Compiler - Question and answer - 2

6. What are the requirements for designing a compiler ?
Parsing: The source text is converted to an abstract syntax tree (AST).
Semantic validation: Weeding out syntactically correct statements that make no sense, e.g. unreachable code or duplicate declarations.
Code generation: the AST is transformed into linear low-level code, with jumps, register allocation and the like. Some function calls can be inlined at this stage, some loops unrolled, etc.
Peephole optimization: the low-level code is scanned for simple local inefficiencies which are eliminated.

7. What is abstract machine and what are the components of abstract stack machine ?
An abstract machine is for intermediate code generation/execution. 3 components of abstract stack machine
a) Instruction memory : abstract machine code, intermediate code(instruction)
b) Stack
c) Data memory

8. What is Backpatching ?
Backpatching is the activity of filling up unspecified information of labels using appropriate semantic actions during the process of code generation.
Backpatching Algorithms perform three types of operations
1) Makelist (i) – creates a new list containing only i, an index into the array of quadruples and returns a pointer to the list it has made.
2) Merge (i, j) – concatenates the lists pointed to by i and j, and returns a pointer to the concatenated list.
3) Backpatch (p, i) – inserts i as the target label for each of the statements on the list pointed to by p.

9. What is a handle.
A handle of a string is a substring that matches the right side of a production, and whose reduction to the nonterminal on the left side of the production represents one step along the reverse of a rightmost derivation.

10. What is an assembly language ?
Assembly language often abbreviated asm, is any low-level programming language in which there is a very strong correspondence between the instructions in the language and the architecture's machine code instructions.
1 2 3 4 5 6 7 8