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

Related questions

0 votes
0 answers
1
asked in Compiler Design by thor Boss (8.6k points)   | 89 views
0 votes
1 answer
2
asked in Compiler Design by Rakesh K Active (1.6k points)   | 45 views
+2 votes
1 answer
3
Top Users Feb 2017
  1. Arjun

    4902 Points

  2. Bikram

    4102 Points

  3. Habibkhan

    3748 Points

  4. Aboveallplayer

    2986 Points

  5. sriv_shubham

    2288 Points

  6. Smriti012

    2222 Points

  7. Arnabi

    1946 Points

  8. Debashish Deka

    1920 Points

  9. mcjoshi

    1614 Points

  10. sh!va

    1462 Points

Monthly Topper: Rs. 500 gift card

20,793 questions
25,951 answers
59,558 comments
21,976 users