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

Syntax Directed Translation Questions and Answers

Answer: A

Correct answer: a set of semantic rules relating the attributes of its symbols

A syntax directed definition pairs each production with rules saying how the attributes of the symbols in it are related - the value of the left side from those of the right, or the reverse. It says what is to be computed without saying when, which is what distinguishes it from a translation scheme.

Please log in or register to report this question.

Answer: B

Correct answer: a value associated with an occurrence of that symbol in a tree

An attribute belongs to a node rather than to the symbol in the abstract, so the same nonterminal appearing twice in a tree carries two independent sets of values. Attributes hold whatever the translation needs - a type, a value, a piece of generated code, an address.

Please log in or register to report this question.

Answer: C

Correct answer: the attributes of that node's children and of the node itself

A synthesised attribute flows upward, computed from below. That direction is what makes S-attributed definitions so convenient for bottom up parsing: by the time a production is reduced, every child has already been reduced and its attributes are available on the stack.

Please log in or register to report this question.

Answer: D

Information flows downward or sideways across the tree. Inherited attributes express context, such as the type declared at the head of a declaration being passed to each name in the list. Without inherited attributes that construct cannot be handled in one pass.

Please log in or register to report this question.

5.

Match each attribute usage with the direction of information flow.
List I
A. the value of an arithmetic expression
B. the type declared for a list of names
C. the width of a generated code fragment
D. the nesting level of the enclosing block
List II
1. upward, synthesised
2. upward, synthesised
3. downward, inherited
4. downward, inherited

Answer: A

Correct answer: A-2, B-4, C-1, D-3

The direction follows from where the information comes from. An expression’s value and a code fragment’s width are both built up from the parts below, so they are synthesised. A declared type must be passed down to the list of names it applies to, and a nesting level comes from the enclosing block, so both are inherited.

Please log in or register to report this question.

Answer: B

Correct answer: every attribute in it is synthesised

S-attributed definitions use no inherited attributes at all, so information flows only upward. That makes them exactly what a bottom up parser can evaluate during the parse, with the attribute values held on a stack parallel to the parsing stack and no extra machinery at all.

Please log in or register to report this question.

Answer: C

Every attribute is synthesised, so the children are complete when the parent is reduced. Yacc-style value stacks implement exactly this evaluation with no extra machinery. Nothing beyond the parallel stack is needed to realise the whole definition.

Please log in or register to report this question.

Answer: D

Correct answer: the left side's inherited attributes and symbols to its left

The restriction is to information already available when the symbol is reached in a left-to-right traversal - what came down from the parent, and what has been computed from the siblings already passed. That is precisely what makes a single depth-first left-to-right pass sufficient.

Please log in or register to report this question.

9.

Consider the following statements about attribute classes.
1. Every S-attributed definition is also L-attributed.
2. Every L-attributed definition is also S-attributed.
3. L-attributed definitions can be evaluated in one depth first pass.

Answer: A

Correct answer: 1 and 3 only

Statements 1 and 3 are correct: an S-attributed definition has no inherited attributes at all, so it satisfies the L-attributed condition vacuously, and L-attributed definitions evaluate in one depth-first pass. Statement 2 reverses the containment - an L-attributed definition may use inherited attributes, which an S-attributed one by definition does not.

Please log in or register to report this question.

10.

Assertion (A): Every S-attributed definition is also L-attributed.
Reason (R): The L condition constrains only inherited attributes, of which an S-attributed definition has none.

Answer: B

Both are true and the reason gives the mechanism, and the containment is strict. An L-attributed definition passing a declared type down a list of identifiers uses an inherited attribute and so lies outside the S-attributed class.

Please log in or register to report this question.

Loading…
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