in Compiler Design edited by
8,432 views
32 votes
32 votes

Consider the syntax directed definition shown below.$$\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 $t_i'$s are the temporary variable names generated by $newtemp$. For the statement $\text{‘}X : = Y + Z\text{'},$ the $3$-address code sequence generated by this definition is

  1. $X = Y + Z$
  2. $t_1 = Y+Z; X=t_1$
  3. $t_1 =Y; t_2=t_1 +Z; X=t_2$
  4. $t_1 =Y; t_2=Z; t_3=t_1+t_2; X=t_3$
in Compiler Design edited by
8.4k views

4 Answers

36 votes
36 votes
Best answer

Answer (B)

edited by

1 comment

prashant sir t1=y+z
5
5
17 votes
17 votes
x=y+z

three address code

 

operand op1 op2  result   

+           y      z      t1

=          t1              x

t1=y+z

x=t1

so ans is b

1 comment

pooja mam u wrote operand in the place of operand and vice-versa
0
0
6 votes
6 votes
answer - B

1 comment

Please explain your solution
0
0
1 vote
1 vote
This is already a 3 address code. Why do we need to break it down further.

So option a) should also be an acceptable solution.

1 comment

Because that is what asked in the question , to follow the Translations.
0
0
Answer:

Related questions