GATE CSE
First time here? Checkout the FAQ!
x
+2 votes
180 views
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
asked in Compiler Design by Active (1.6k points)   | 180 views

2 Answers

+7 votes
Best answer
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.
answered by Veteran (65.1k points)  
selected by
dats what m confused....but the grammar is ambiguous na...u r seeing according to this instance of parse tree only?
what if S->S-S/S+S was given?

both - and + are on same level...but again since it is ambiguous how can we decide about precedence?
Ya it is an ambiguous grammar but it is not of concern since in this case - and + will be in same level of the derivation tree although the derivation tree is not unique.
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.
answered by Loyal (4.5k points)  

Related questions

0 votes
0 answers
1
asked in Compiler Design by thor Boss (8.6k points)   | 106 views
0 votes
1 answer
2
asked in Compiler Design by Rakesh K Active (1.6k points)   | 46 views
+2 votes
1 answer
3


Top Users Mar 2017
  1. rude

    4758 Points

  2. sh!va

    3014 Points

  3. Rahul Jain25

    2830 Points

  4. Kapil

    2636 Points

  5. Debashish Deka

    2442 Points

  6. 2018

    1514 Points

  7. Vignesh Sekar

    1416 Points

  8. Akriti sood

    1298 Points

  9. Bikram

    1286 Points

  10. Sanjay Sharma

    1076 Points

Monthly Topper: Rs. 500 gift card

21,471 questions
26,802 answers
61,041 comments
23,037 users