Skip to content
Related Articles

Related Articles

Improve Article

GATE | GATE-CS-2003 | Question 59

  • Last Updated : 28 Jun, 2021

Consider the syntax directed definition shown below.

S → id : = E  {gen (id.place = E.place;);}
E → E1 + E2   {t = newtemp ( ); gen (t = El.place + E2.place;); E.place = t}
E → id     {E.place = id.place;} 

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
(A) X = Y + Z
(B) t1 = Y + Z; X = t1
(C) t1 =Y; t2 = t1 + Z; X = t2
(D) t1 = Y; t2 = Z; t3 = t1 + t2; X = t3


Answer: (B)

Explanation: It must be B. The production E –> E + E is used only one time and hence only one temporary variable is generated.

Quiz of this Question

Attention reader! Don’t stop learning now.  Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.

Learn all GATE CS concepts with Free Live Classes on our youtube channel.

My Personal Notes arrow_drop_up
Recommended Articles
Page :