search
Log In
23 votes
4.6k views

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 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. $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
4.6k views

3 Answers

28 votes
 
Best answer

Answer (B)

using given semantic rules.


edited by
4
prashant sir t1=y+z
16 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
0
pooja mam u wrote operand in the place of operand and vice-versa
6 votes
answer - B
0
Please explain your solution
Answer:

Related questions

30 votes
6 answers
1
5.2k views
The following program fragment is written in a programming language that allows global variables and does not allow nested declarations of functions. global int i=100, j=5; void P(x) { int i=10; print(x+10); i=200; j=20; print (x); } main() {P(i+j);} If the ... scoping and call by name parameter passing mechanism, the values printed by the above program are $115, 220$ $25, 220$ $25, 15$ $115, 105$
asked Apr 24, 2016 in Compiler Design jothee 5.2k views
33 votes
3 answers
2
6.4k views
Consider the translation scheme shown below. S $\rightarrow$ T R R $\rightarrow$ + T {print(‘+’);} R$\mid \varepsilon$ 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 $9 + 5 + 2$ $9 \ 5 + 2 +$ $9 \ 5 \ 2 + +$ $+ + 9 \ 5 \ 2$
asked Sep 17, 2014 in Compiler Design Kathleen 6.4k views
31 votes
3 answers
3
11k views
Consider the grammar shown below. $S \rightarrow C \ C$ $C \rightarrow c \ C \mid d$ This grammar is LL(1) SLR(1) but not LL(1) LALR(1) but not SLR(1) LR(I) but not LALR(1)
asked Sep 17, 2014 in Compiler Design Kathleen 11k views
27 votes
3 answers
4
6.3k views
Consider the grammar shown below $S \rightarrow i E t S S' \mid a$ $S' \rightarrow e S \mid \epsilon$ $E \rightarrow b$ In the predictive parse table, $M,$ of this grammar, the entries $M[S' , e]$ and $M[S' , \$]$ respectively are $\{S' \rightarrow e S\ ... $\{S' \rightarrow \epsilon\}$ $\{S' \rightarrow e S, S' \rightarrow \varepsilon$} and $\{S' \rightarrow \epsilon\}$
asked Sep 17, 2014 in Compiler Design Kathleen 6.3k views
...