retagged by
2,782 views
19 votes
19 votes

Consider the parse tree

Assume that $*$ has higher precedence than $+$, $-$ and operators associate right to left (i.e $(a + b + c= (a + (b + c)))$. Consider

  1. $2 + a - b$
  2. $2 + a - b * a + b$
  3. $(2 + ((a - b) * (a + b)))$
  4. $2 + (a - b) * (a + b)$

The parse tree corresponds to

  1. Expression (i)
  2. Expression (ii)
  3. Expression (iv) only
  4. Expression (ii), (iii), and (iv)
  5. Expression (iii) and (iv) only
retagged by

2 Answers

Best answer
15 votes
15 votes

e is correct

Because as the precedence is right to left, expression evaluated in (ii) is $2+(a-((b*a)+b)),$ which is not a correct evaluation as the given parse tree.

edited by
6 votes
6 votes
Although given answer is correct one can approach in another way if one wants more visualization to this problem

Write the "postfix" expression of given parse tree keeping in mind precedences order & associativity as per question we will get      { 2ab-ab+*+ }

Now write the postfix expressions of options 3 & 4 you will see same and for option 2 you will get different

 

(E) correct answer
Answer:

Related questions

2.6k
views
2 answers
16 votes
makhdoom ghaya asked Nov 2, 2015
2,631 views
Which of the following correctly describes $\text{LR}(k)$ parsing?The input string is alternately scanned left to right and right to left with $k$ reversals.Input ... with $k$ symbol to the right as look-ahead to give left-most derivation.
10.5k
views
4 answers
36 votes
Sandeep Singh asked Feb 12, 2016
10,522 views
The attribute of three arithmetic operators in some programming language are given below. ... value of the expression $2-5+1-7*3$ in this language is ________.
339
views
1 answers
0 votes
1.4k
views
1 answers
3 votes
kirtikanwar asked Jan 4, 2017
1,378 views
Consider the following operator grammarE->AaBcDA->bA|eB->bB|eD->eD|gWhich of the following precedence relation is incorrect from the above grammar? Assume x< y is used to represent x is ... appears next.a) a< b b) c< g c) a< e d) c< b