Syntax-directed Translation: GATE CS Previous Year Questions

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

Q16GATE 20031 markMCQ−0.33 if wrong
Consider the syntax directed definition shown below

S→id:=E{gen(id.place=E.place;);}E→E1+E2{t=newtemp();gen(t=E1.place+E2.place;);E.place=t;}E→id{E.place=id.place;}\begin{array}{ll} S \rightarrow \mathbf{ id :=} E&\qquad \{gen(\mathbf{ id}.place = E.place;);\}\\ E \rightarrow E_1 + E_2 &\qquad \{t = newtemp();\\ &\qquad gen(t = E_1.place + E_2.place;);\\ &\qquad E.place = t;\}\\ E \rightarrow id&\qquad \{E.place = \mathbf{id}.place;\} \end{array}

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

Q17GATE 20031 markMCQ−0.33 if wrong
Consider the translation scheme shown below
S →\rightarrow TR
R →\rightarrow+ T {print ('+');}R | ϵ\epsilon
T →\rightarrow 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

Keep practising

Topics in Compiler Design

All CS topics ›