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

Syntax Directed Translation Questions and Answers

Answer: C

Correct answer: the type of an expression is synthesised from those of its operands

The type of a sum follows from the types of its two operands, which follow from theirs, all the way down to the identifiers and constants. That is a purely synthesised computation, so type checking fits an S-attributed definition and can be done during a bottom up parse.

Please log in or register to report this question.

Answer: D

The rule detects the mismatch and inserts an explicit conversion so that later phases see consistent types. Whether a coercion is permitted at all is a decision of the language definition. Some languages forbid every implicit conversion and require an explicit cast.

Please log in or register to report this question.

Answer: A

The place attribute names where the value lives, usually a compiler generated temporary. The code itself is either another attribute or is emitted directly as a side effect. Which choice is made affects whether fragments can be reordered afterwards.

Please log in or register to report this question.

Answer: B

A counter guarantees a distinct name for each intermediate result. Reducing the number of temporaries is left to later optimisation rather than to the translation itself. Keeping the translation simple makes it far easier to verify as correct.

Please log in or register to report this question.

35.

The expression a + b * c is translated into three address code with one operation per instruction. How many temporaries are introduced?

Answer: C

The multiplication produces one temporary and the addition a second, giving two in all. Each binary operator in the tree contributes exactly one temporary under this scheme. Counting operators is therefore enough to predict the number of temporaries.

Please log in or register to report this question.

36.

An expression tree contains 5 binary operators. Translating it with one operation per three address instruction produces how many instructions?

Answer: D

Each operator becomes one instruction, so five are emitted. The number of temporaries introduced is also five, one holding the result of each operation. Later optimisation may eliminate several of them by reusing registers.

Please log in or register to report this question.

Answer: A

Passing the destinations down the tree lets each subexpression emit a jump directly to the right place. This avoids computing a value that would immediately be tested and discarded. The saving is substantial in code full of compound conditions.

Please log in or register to report this question.

Answer: B

Correct answer: the destination of a jump is not known when the jump is emitted

Translating a conditional or a loop in one pass means emitting the jump before the code it jumps over has been generated, so the destination cannot yet be known. The jump is emitted with the field blank, its position is recorded on a list, and the list is patched when the label is finally reached.

Please log in or register to report this question.

Answer: C

Merging two such lists is how the true exits of a subexpression are combined. When the destination becomes known every instruction on the list is patched in one sweep. The lists are merged as subexpressions combine, which keeps the cost linear.

Please log in or register to report this question.

40.

Match each translation task with the attribute flow it mainly uses.
List I
A. computing the value of an expression
B. passing a declared type to a list of names
C. passing jump targets into a boolean expression
D. computing the width of a record type
List II
1. inherited
2. synthesised
3. synthesised
4. inherited

Answer: D

Values built from parts flow upward while context supplied from outside flows downward. Recognising which applies is what determines whether the definition can be S-attributed. A single downward flow anywhere forces the L-attributed treatment.

Please log in or register to report this question.

Loading…

Other Subjects

Tags: Syntax Directed Translation Questions and Answers || Syntax Directed Translation MCQ Questions and Answers || Syntax Directed Translation GK Questions and Answers || Syntax Directed Translation GK MCQ Questions || Syntax Directed Translation Multiple Choice Questions and Answers || Syntax Directed Translation GK || GK on Syntax Directed Translation || Compiler Design Questions and Answers || Compiler Design MCQ Questions and Answers || Compiler Design GK Questions and Answers || GK on Compiler Design