GATE CSE
First time here? Checkout the FAQ!
x
+2 votes
191 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)   | 191 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 (66.3k 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.7k points)  

Related questions

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


Top Users May 2017
  1. akash.dinkar12

    3548 Points

  2. pawan kumarln

    2126 Points

  3. Bikram

    1922 Points

  4. sh!va

    1682 Points

  5. Arjun

    1622 Points

  6. Devshree Dubey

    1272 Points

  7. Debashish Deka

    1270 Points

  8. Angkit

    1056 Points

  9. LeenSharma

    1028 Points

  10. Arnab Bhadra

    812 Points

Monthly Topper: Rs. 500 gift card
Top Users 2017 May 22 - 28
  1. Bikram

    1008 Points

  2. pawan kumarln

    752 Points

  3. Arnab Bhadra

    726 Points

  4. akash.dinkar12

    428 Points

  5. Arjun

    350 Points


22,896 questions
29,206 answers
65,329 comments
27,708 users