1,497 views
2 votes
2 votes
Consider the following parse tree:

                           string
                          /    |    \     
                 string    +     string
                /    |    \              |
       string     -    string      2
           |                 |
           9                5

Which of the following statement is true?

(A) Both + and - are having equal precendence

(B) + is having higher precedence

(C) - is having higher precedence

(D) None of these

2 Answers

Best answer
8 votes
8 votes
See the task is easier here than if the grammar were given and then asked that which operator has more precedence.But here we can answer about the precedence by simply examining the dervation tree.The behaviour is similar to recursion tree if you recall

According to the tree , we know that calling is done in top down manner but execution is done in bottom up manner.So the '-' being lower in the tree will be executed first then the '+' which is at higher level.

So '-' has higher precedence than '+'.

Hence C) is correct option.
selected by
0 votes
0 votes
Option C will be right option for it.

The operator having low level have higher precedence compare to operator having low level.

That's option C will be right option for.

Related questions

1 votes
1 votes
2 answers
1
Hirak asked Jun 14, 2019
1,289 views
In operator precedence parsing we have the rule that production cannot have two adjacent non-terminals or an epsilon production, so this production, S ab is allowed but ...
0 votes
0 votes
3 answers
2
0 votes
0 votes
1 answer
3
saumya mishra asked Jun 11, 2018
207 views
How to make a parse tree for the expression$a+b*c/b*c*f?$
0 votes
0 votes
1 answer
4
saumya mishra asked Jun 5, 2018
767 views
Consider the following grammar$S \rightarrow SS/Sa/aS/a$Construct Parse Tree for $w=aaaa$ as many as possible? How many parse trees are possible?