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

Syntax Directed Translation Questions and Answers

Answer: A

The total is built from the parts, so the flow is upward. Field offsets, by contrast, require a running total passed along the list and are naturally inherited. A record type therefore needs both directions of flow in the same definition.

Please log in or register to report this question.

Answer: B

Correct answer: an inherited attribute carrying the running total so far

Each field is placed at the current total and advances it, so the offset must be passed along the list from left to right. That is an inherited attribute, and it makes the record layout definition L-attributed - one of the standard illustrations of why inherited attributes are needed at all.

Please log in or register to report this question.

Answer: C

The L condition forbids exactly this dependency. Such a definition may still be evaluable, but it needs multiple passes or an explicit topological sort of the dependency graph. Both are avoided in practice by restructuring the grammar instead.

Please log in or register to report this question.

Answer: D

Correct answer: the definition is neither S-attributed nor L-attributed

Both restricted classes can be evaluated in a single traversal. A definition outside them may have dependencies that no single left-to-right pass satisfies, so the tree must be traversed more than once, with a dependency analysis deciding what can be computed on each pass.

Please log in or register to report this question.

Answer: A

Information cannot flow into a subtree that has already been parsed. Reaching down the value stack to a known offset is the usual trick, though it is fragile if the grammar changes. A marker nonterminal achieves the same effect far more robustly.

Please log in or register to report this question.

Answer: B

Correct answer: a fragile technique that breaks if the grammar is changed

Reading below the current production’s entries on the value stack works only if the surrounding productions always place the same thing there, which is an assumption the grammar may violate the moment it is edited. Marker nonterminals achieve the same effect explicitly and survive change.

Please log in or register to report this question.

Answer: C

Each rule builds a node from the nodes returned by its children, so the tree assembles itself bottom up. This is one of the most common S-attributed translations in any compiler. Each node holds pointers to the nodes its children returned.

Please log in or register to report this question.

Answer: D

Optimisation and analysis often need repeated traversals. An explicit tree makes those possible, at the cost of the memory needed to hold the whole program's structure. Optimising compilers accept that cost without hesitation.

Please log in or register to report this question.

Answer: A

Correct answer: it cannot revisit earlier parts of the program after moving on

A one pass compiler emits code as it parses and never returns, so any decision requiring information from later in the program cannot be made properly - a forward reference, or an optimisation depending on how a variable is used further on. Backpatching handles the simplest of these; the rest require a second pass.

Please log in or register to report this question.

Answer: B

Reduction is the only moment at which the parser knows the production was used. This is why every action other than one at the very end of a right side needs a marker nonterminal. The marker is inserted silently by the generator in most tools.

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