• edited by
13,159 views
45 45 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$

5 Answers

20 20 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 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 flag:
✌ Low quality (Siddharth_Perkar “Wrong explanation”)
Answer:
Position:
Show:

Related questions

61 61 votes
5 answers 5 answers
14.8k
14.8k views
Kathleen asked Sep 17, 2014
14,817 views
A program consists of two modules executed sequentially. Let $f_1(t)$ and $f_2(t)$ respectively denote the probability density functions of time taken to execute the two ...
100 100 votes
12 answers 12 answers
56.1k
56.1k views
Kathleen asked Sep 16, 2014
56,072 views
In a bottom-up evaluation of a syntax directed definition, inherited attributes canalways be evaluatedbe evaluated only if the definition is L-attributedbe evaluated only...
54 54 votes
5 answers 5 answers
22.3k
22.3k views
go_editor asked Apr 24, 2016
22,349 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...
51 51 votes
5 answers 5 answers
19.9k
19.9k views
Kathleen asked Sep 17, 2014
19,904 views
Consider the translation scheme shown below.$S \rightarrow T\;R$$R \rightarrow + T \{\text{print}(‘+’);\} R\mid \varepsilon$$T \rightarrow$ num $\{\text{print}$(num.val)...