• edited by
17,106 views
42 42 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$

2 Answers

Best answer
65 65 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:
Position:
Show:

Related questions

34 34 votes
3 answers 3 answers
13.3k
13.3k views
Kathleen asked Sep 18, 2014
13,264 views
Consider the following grammar G:$S \rightarrow bS \mid aA \mid b$$A \rightarrow bA \mid aB$$B \rightarrow bB \mid aS \mid a$Let $N_a(w)$ and $N_b(w)$ denote the number o...
32 32 votes
3 answers 3 answers
16.6k
16.6k views
Kathleen asked Sep 18, 2014
16,583 views
Which of the following grammar rules violate the requirements of an operator grammar? $P, Q, R$ are nonterminals, and $r, s, t$ are terminals.$P \rightarrow Q R$$P \right...
40 40 votes
4 answers 4 answers
14.0k
14.0k views
Kathleen asked Oct 8, 2014
13,999 views
A shift reduce parser carries out the actions specified within braces immediately after reducing with the corresponding rule of grammar$S \rightarrow xxW \;\text{{print“1...
63 63 votes
5 answers 5 answers
21.4k
21.4k views
Vikrant Singh asked Nov 12, 2014
21,362 views
Consider the grammar rule $E \rightarrow E1 – E2$ for arith­metic expressions. The code generated is targeted to a CPU having a single user register. The sub­traction ope...