edited by
11,391 views
34 votes
34 votes

Consider the following translation scheme. 

  • $ S\rightarrow ER$
  • $ R\rightarrow *E\left \{ \text{print}(\text{‘}*\text{’}); \right \} R\mid \varepsilon $
  • $ E\rightarrow F+E\left \{ \text{print}(\text{‘}+\text{’}); \right \}\mid F $
  • $ F\rightarrow (S)\mid id \left \{ \text{print}(id.value); \right \} $

Here $id$ is a token that represents an integer and $id.value$ represents the corresponding integer value. For an input $\text{‘}2 * 3 + 4\text{’},$  this translation scheme prints 

  1. $2 * 3 + 4$
  2. $2 * +3 \ 4$
  3. $2 \ 3 * 4 +$
  4. $2 \ 3 \ 4+*$
edited by

4 Answers

Best answer
45 votes
45 votes

Correct Option: D

Make a tree and perform post order evaluation.

edited by
0 votes
0 votes
This grammer is actually left recursive removed grammer of S-->E*E|E  E-->F+E|F and so on. So + have highest precedence than * . So although the grammer give two parse tree for the given i/p string.. The correct ans should be which allow + have higher precedence than * .. i.e Option D.
0 votes
0 votes
clearly here {} is present in between the variables in r.h.s hence we will go for top down parsing as it is L-attributed. Now refer the best answer for the figure.
–2 votes
–2 votes

My Guesstimation: ..Usuallhy in this typ of question we perform top down left to right... but here  { } is given in between...so this is S-attributed grammer(use bottom up parsing)

Answer:

Related questions

7.6k
views
4 answers
25 votes
go_editor asked Nov 7, 2016
7,603 views
The grammar$S\rightarrow AC\mid CB$C\rightarrow aCb\mid \epsilon$A\rightarrow aA\mid a$B\rightarrow Bb\mid b$generates the language $ ... max (l,m) + 2$l + m + 2$l + m + 3$\max (l,m) + 3$
12.5k
views
4 answers
45 votes
Rucha Shelke asked Sep 26, 2014
12,482 views
Which one of the following grammars generates the language $ L=\left \{ a^{i}b^{j}\mid i\neq j \right \}$?$S\rightarrow AC\mid CB$C\rightarrow aCb\mid ... \mid CB$C\rightarrow aCb\mid \varepsilon$A\rightarrow aA\mid a$B\rightarrow Bb\mid b$
29.2k
views
4 answers
64 votes
Rucha Shelke asked Sep 18, 2014
29,182 views
Consider the following statements about the context free grammar ... statements about $G$?I onlyI and III onlyII and III onlyI, II and III
8.6k
views
4 answers
26 votes
Rucha Shelke asked Sep 26, 2014
8,571 views
Consider the following grammar:$S\rightarrow FR$ R\rightarrow * S\mid \varepsilon $ F\rightarrow id $In the predictive parser table $M$ ... $ \left \{ R\rightarrow \varepsilon \right \} $