Multiple choice

Consider the syntax directed definition shown below, S $\rightarrow$ id : = E {gen (id.place = E.place;);} E $\rightarrow$ E1 + E2 {t = newtemp( ); gen(t = E1.place + E2.place;); E.place = t;} E $\rightarrow$ 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

  1. X = Y + Z

  2. t1 = Y + Z; X = t1

  3. t1 = Y; t2 = t1 + Z; X = t2

  4. t1 = Y; t2 = Z; t3 = t1 + t2; X = t3

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

In 3-address code we use temporary variables to reduce complex instructions so here $$ t_1 = Y \\ t_2 = Z \\ t_3 = t_1 + t_2 \\ x = t_3 \\ $$