Syntax-directed Translation · Compiler Design
17 questions · asked in 11 of 27 years (2000–2026)
MCQ 13 · MSQ 2 · NAT 21-mark 10 · 2-mark 7
2000Questions per year2026
Questions 1–5 of 17
Consider the following two syntax-directed definitions and for type declarations.
is the start symbol, and int, float and id are the three terminals. The non-terminal is the same as and the non-terminal is the same as . Here, the subscript is used to differentiate the grammar symbols on the two sides of a production. The function put updates the symbol table with the type information for an identifier.
Let and be the languages specified by grammars and , respectively. Which of the following statements is/are true?
is the start symbol, and int, float and id are the three terminals. The non-terminal is the same as and the non-terminal is the same as . Here, the subscript is used to differentiate the grammar symbols on the two sides of a production. The function put updates the symbol table with the type information for an identifier.
Let and be the languages specified by grammars and , respectively. Which of the following statements is/are true?
One or more options are correct.
Answer: (A), (B), (D)
Language equivalence: generates a type keyword followed by one-or-more identifiers (via the recursive ); generates the same thing via a left-recursive . Both accept exactly "type-keyword followed by identifiers," so . True.
SDD2's attribute style: In SDD2, and the actions are all computed purely from the values of the symbols on the right-hand side of each production (children of the node in the parse tree) — every attribute is synthesized, making SDD2 S-attributed. True.
SDD1's attribute style: In SDD1, is set from (an inherited value flowing top-down from the parent into , then further down into ), so SDD1 does use inherited attributes — but itself is synthesized from as well, so SDD1 is L-attributed but it is not true that it contains "only" inherited attributes (it has both kinds). False as stated.
Symbol table contents: In SDD1, is called for every identifier with the type inherited down from . In SDD2, is similarly called for every identifier with the same type value (synthesized bottom-up instead, but numerically identical since there's only one /type per declaration). Since both add exactly one entry per identifier with the same type value, the symbol tables end up identical. True.
Answer: P and Q are the same language; SDD2 is S-attributed with only synthesized attributes; and both SDDs populate the symbol table with the same entries.
SDD2's attribute style: In SDD2, and the actions are all computed purely from the values of the symbols on the right-hand side of each production (children of the node in the parse tree) — every attribute is synthesized, making SDD2 S-attributed. True.
SDD1's attribute style: In SDD1, is set from (an inherited value flowing top-down from the parent into , then further down into ), so SDD1 does use inherited attributes — but itself is synthesized from as well, so SDD1 is L-attributed but it is not true that it contains "only" inherited attributes (it has both kinds). False as stated.
Symbol table contents: In SDD1, is called for every identifier with the type inherited down from . In SDD2, is similarly called for every identifier with the same type value (synthesized bottom-up instead, but numerically identical since there's only one /type per declaration). Since both add exactly one entry per identifier with the same type value, the symbol tables end up identical. True.
Answer: P and Q are the same language; SDD2 is S-attributed with only synthesized attributes; and both SDDs populate the symbol table with the same entries.
Consider the following three ANSI-C programs, and .
Which one of the following statements is true?
Which one of the following statements is true?
Answer: (A)
P1: There is a global . Inside there is another, local . C allows this. The local one shadows the global one inside the scope of . It compiles without error.
P2: We have and right after it , both in the same block. This redeclares the identifier in one scope. That is a compile-time error.
P3: We have and then . Here too is declared again in the same scope, and this time the types differ. This is also a compile-time error.
Answer: Only P1 will compile without any error.
P2: We have and right after it , both in the same block. This redeclares the identifier in one scope. That is a compile-time error.
P3: We have and then . Here too is declared again in the same scope, and this time the types differ. This is also a compile-time error.
Answer: Only P1 will compile without any error.
Given the following syntax-directed translation rules:
Which ONE is the CORRECT option among the following?
Which ONE is the CORRECT option among the following?
Answer: (C)
S-attributed means every attribute is synthesized, so it is computed only from the children. L-attributed means each inherited attribute of a child depends only on the parent's inherited attributes or on siblings to its left.
Rule 1 (): and are attributes of the children, and they are computed from and , so they are inherited. So the rule is not S-attributed. Also depends on , and is to the right of , so the dependency flows right to left. This breaks the L-attributed rule. Neither S-attributed nor L-attributed.
Rule 2 (): is an inherited attribute of the child , so the rule is not S-attributed. It depends only on , a left sibling, and is synthesized, so it is L-attributed. Not S-attributed, but L-attributed.
Rule 3 (): the only attribute defined is , computed from the children , so it is synthesized. S-attributed, and also L-attributed, since every S-attributed rule is L-attributed.
Answer: (C)
Rule 1 (): and are attributes of the children, and they are computed from and , so they are inherited. So the rule is not S-attributed. Also depends on , and is to the right of , so the dependency flows right to left. This breaks the L-attributed rule. Neither S-attributed nor L-attributed.
Rule 2 (): is an inherited attribute of the child , so the rule is not S-attributed. It depends only on , a left sibling, and is synthesized, so it is L-attributed. Not S-attributed, but L-attributed.
Rule 3 (): the only attribute defined is , computed from the children , so it is synthesized. S-attributed, and also L-attributed, since every S-attributed rule is L-attributed.
Answer: (C)
Consider the following syntax-directed definition (SDD).
Given "MMLK" as the input, which one of the following options is the CORRECT value computed by the SDD (in the attribute S.val)?
Given "MMLK" as the input, which one of the following options is the CORRECT value computed by the SDD (in the attribute S.val)?
Answer: (A)
The input "MMLK" gives the split D = "MM", H = "L", T = , U = "K".
Now find each value:
- Value of :
- Value of :
- Value of is
- Value of :
Add all the values:
Answer: 45
Now find each value:
- Value of :
- Value of :
- Value of is
- Value of :
Add all the values:
Answer: 45
Which of the following statements is/are FALSE?
One or more options are correct.
Answer: (B), (D)
Check each statement:
- (A) An attribute grammar is an SDD whose semantic rules have no side effects. This is TRUE, as it is the definition.
- (B) "L-attributed definitions cannot always be evaluated in depth-first order" is FALSE. An L-attributed definition is built so that a left-to-right depth-first traversal of the parse tree can always evaluate it.
- (C) Synthesized attributes can be evaluated by a bottom-up parser during reductions. This is TRUE.
- (D) "All L-attributed definitions based on LR(1) grammars can be evaluated bottom-up" is FALSE. The marker non-terminal method is sure to work only for L-attributed definitions on LL(1) grammars. Adding markers can turn an LR(1) grammar into one that is not LR.
The false statements are B and D.
Answer: (B), (D)
- (A) An attribute grammar is an SDD whose semantic rules have no side effects. This is TRUE, as it is the definition.
- (B) "L-attributed definitions cannot always be evaluated in depth-first order" is FALSE. An L-attributed definition is built so that a left-to-right depth-first traversal of the parse tree can always evaluate it.
- (C) Synthesized attributes can be evaluated by a bottom-up parser during reductions. This is TRUE.
- (D) "All L-attributed definitions based on LR(1) grammars can be evaluated bottom-up" is FALSE. The marker non-terminal method is sure to work only for L-attributed definitions on LL(1) grammars. Adding markers can turn an LR(1) grammar into one that is not LR.
The false statements are B and D.
Answer: (B), (D)
Keep practising
Topics in Compiler Design
Lexical AnalysisParsing
Syntax-directed TranslationYou are here
Runtime EnvironmentAssemblers, Linkers and LoadersIntermediate Code GenerationMatching