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 16–17 of 17
Consider the syntax directed definition shown below
Here, gen is a function that generates the output code, and newtemp is a function that returns the name of a new temporary variable on every call. Assume that ti's are the temporary variable names generated by newtemp. For the statement 'X:= Y + Z', the 3-address code sequence generated by this definition is
Here, gen is a function that generates the output code, and newtemp is a function that returns the name of a new temporary variable on every call. Assume that ti's are the temporary variable names generated by newtemp. For the statement 'X:= Y + Z', the 3-address code sequence generated by this definition is
Answer: (B)
For the parse tree is below.
- only sets to the name of the identifier. It calls no gen, so it makes no code and no temporary. So and .
- gets a new temporary , generates , and sets .
- generates .
The code is then . Options C and D copy Y and Z into temporaries, which no rule does. Option A has no temporary, but the rule for always makes one.
Answer: (B)
- only sets to the name of the identifier. It calls no gen, so it makes no code and no temporary. So and .
- gets a new temporary , generates , and sets .
- generates .
The code is then . Options C and D copy Y and Z into temporaries, which no rule does. Option A has no temporary, but the rule for always makes one.
Answer: (B)
Consider the translation scheme shown below
S TR
R + T {print ('+');}R |
T num {print (num.val);}
Here num is a token that represents an integer and num. val represents the corresponding integer value. For an input string '9 + 5+ 2', this translation scheme will print
S TR
R + T {print ('+');}R |
T num {print (num.val);}
Here num is a token that represents an integer and num. val represents the corresponding integer value. For an input string '9 + 5+ 2', this translation scheme will print
Answer: (B)
The actions run in a left to right, depth first walk of the parse tree. A print action sits after the symbols before it, so it runs once they are done.
For :
1. : prints 9.
2. : after reading +, T prints 5. Only then does the action print +.
3. The new R reads the second +, T prints 2, and then the action prints +.
4. prints nothing.
The output is , that is 95+2+.
Answer: (B)
For :
1. : prints 9.
2. : after reading +, T prints 5. Only then does the action print +.
3. The new R reads the second +, T prints 2, and then the action prints +.
4. prints nothing.
The output is , that is 95+2+.
Answer: (B)
Keep practising
Topics in Compiler Design
Lexical AnalysisParsing
Syntax-directed TranslationYou are here
Runtime EnvironmentAssemblers, Linkers and LoadersIntermediate Code GenerationMatching