Machine-translated by Google. Questions are authored in English.
Top

Intermediate Code Generation Questions and Answers

11.

Assertion (A): Quadruples are preferred to triples when the intermediate code will be optimised.
Reason (R): A triple names its result by its own position, so moving an instruction invalidates every reference to it.

Answer: C

Correct answer: Both A and R are true, and R is the correct explanation of A

Both are true and the reason gives the mechanism. Optimisation moves and removes instructions constantly, and in a triple representation an instruction’s identity is its position, so every such change invalidates the references to it. A quadruple names its result explicitly and is unaffected.

Please log in or register to report this question.

Answer: D

Reordering then means permuting the pointer list while the triples themselves stay put. This restores the reorderability of quadruples while still sharing identical subexpressions. The extra indirection costs one memory reference per access.

Please log in or register to report this question.

13.

Match each representation with its distinguishing property.
List I
A. quadruple
B. triple
C. indirect triple
D. static single assignment
List II
1. a pointer list over a triple array
2. explicit result field
3. each name assigned exactly once
4. result named by instruction position

Answer: A

Each form trades space against ease of manipulation. Choosing among them is essentially a decision about how much optimisation the compiler intends to perform on the representation. A compiler that optimises little can afford the more compact forms.

Please log in or register to report this question.

Answer: B

Renaming each assignment to a fresh version makes the definition reaching any use immediately apparent. Many data flow analyses become far simpler and faster on this form. Modern optimising compilers use it as their main internal representation.

Please log in or register to report this question.

Answer: C

Correct answer: where control flow paths carrying different versions of a name meet

Static single assignment gives every assignment a distinct name, which works within straight-line code but fails at a join, where the value could have come from either path. The phi function is placed at that join to select between the incoming versions, which restores the single-assignment property.

Please log in or register to report this question.

Answer: D

The tree is closer to the source and easier to transform structurally. Three address code is closer to the machine and easier to schedule and allocate registers for. Most compilers keep both forms and lower from one to the other.

Please log in or register to report this question.

Answer: A

Common subexpressions are identified by construction, since a node is reused rather than duplicated. This makes the graph a natural vehicle for local common subexpression elimination. The sharing happens as a side effect of building the structure at all.

Please log in or register to report this question.

18.

The expression a + b + a + b is represented as a directed acyclic graph with sharing. How many distinct interior nodes does it have?

Answer: B

In a directed acyclic graph, identical subexpressions are built once and shared. Here \( a+b \) occurs twice but becomes a single node, and the outer addition that combines the two references is a second: \[ \text{interior nodes} = 1 \ (a+b) + 1 \ (\text{outer} +) = 2 \] A plain syntax tree, which cannot share, would carry three interior nodes for the same expression.

Please log in or register to report this question.

Answer: C

A node with no parent computes a value nobody consumes, and a shared node is a repeated computation. Both observations feed directly into local optimisation of the block. The graph is therefore built as much for analysis as for representation.

Please log in or register to report this question.

20.

Arrange the steps of translating an assignment statement into three address code.
1. generate the instruction combining the operand temporaries
2. parse the right hand side into a tree or during the parse
3. generate the copy assigning the result to the left hand side
4. generate code for each subexpression into a temporary

Answer: D

Correct answer: 2 - 4 - 1 - 3

The order follows the structure of the expression. The right hand side is parsed, each subexpression is evaluated into a temporary, those temporaries are combined by the operator, and the result is finally copied to the left hand side. Generating the copy first would have nothing to copy.

Please log in or register to report this question.

Loading…
Tags: Intermediate Code Generation Questions and Answers || Intermediate Code Generation MCQ Questions and Answers || Intermediate Code Generation GK Questions and Answers || Intermediate Code Generation GK MCQ Questions || Intermediate Code Generation Multiple Choice Questions and Answers || Intermediate Code Generation GK || GK on Intermediate Code Generation || Compiler Design Questions and Answers || Compiler Design MCQ Questions and Answers || Compiler Design GK Questions and Answers || GK on Compiler Design