edited by
10,912 views
31 votes
31 votes

Consider the grammar with the following translation rules and $E$ as the start symbol$$\begin{array}{lll}
E \rightarrow   E_ 1\# \: T & \qquad\left\{E.value = E_1.value * T.value\right\}\\
\qquad\mid T & \qquad \{E.value = T.value\}\\
T \rightarrow  T_1 \& \: F &\qquad \{T.value = T_1.value + F.value\}\\
\qquad\mid F&\qquad \{T.value = F.value\}\\
F \rightarrow \text{num}&\qquad \{F.value=num.value\}
\end{array}$$Compute E.value for the root of the parse tree for the expression:$2$ # $3$ & $5$ # $6$ & $4$

  1. $200$
  2. $180$
  3. $160$
  4. $40$
edited by

2 Answers

Best answer
53 votes
53 votes

Here # is multiplication and & is addition by semantics rules given in the question.
By observation of productions,

  1. here &(+) is higher precedence than #(*), because & is far from starting symbol
  2. both &,# are left associative

So, we can solve the expression as $((2*(3+5))*(6+4)) =160$

Answer is (C).

edited by
Answer:

Related questions

21 votes
21 votes
2 answers
2
29 votes
29 votes
2 answers
4
Kathleen asked Sep 18, 2014
6,360 views
Consider a program $P$ that consists of two source modules $M_1$ and $M_2$ contained in two different files. If $M_1$ contains a reference to a function defined in $M_2$ ...