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

Related questions

0 votes
0 answers
1
asked in Compiler Design by thor Boss (8.8k points)   | 242 views
+2 votes
1 answer
2
asked in Compiler Design by Rakesh K Active (1.7k points)   | 66 views
+3 votes
1 answer
3


Top Users Sep 2017
  1. Habibkhan

    6970 Points

  2. Warrior

    2490 Points

  3. Arjun

    2368 Points

  4. rishu_darkshadow

    2136 Points

  5. A_i_$_h

    2004 Points

  6. nikunj

    1980 Points

  7. makhdoom ghaya

    1760 Points

  8. manu00x

    1750 Points

  9. Bikram

    1744 Points

  10. SiddharthMahapatra

    1718 Points


26,060 questions
33,668 answers
79,747 comments
31,079 users