Skip to content
Related Articles

Related Articles

GATE | GATE-CS-2000 | Question 49
  • Difficulty Level : Hard
  • Last Updated : 12 Sep, 2019
GeeksforGeeks - Summer Carnival Banner

Given the following expression grammar:

E -> E * F | F + E | F
F -> F - F | id 

which of the following is true?
(A) * has higher precedence than +
(B) – has higher precedence than *
(C) + and — have same precedence
(D) + has higher precedence than *


Answer: (B)

Explanation: Let say i/p is 3*4-5 when we draw parse tree according to grammar

      E
   /  |  \
  E   *   F
  |     / | \
  F    F  -  F
  |    |     |
id(3) id(4) id(5)

As we can see first ‘- ‘ will be evaluated then ‘ * ‘ is evaluated so ‘ – ‘ has higher precedence then *.

So correct choice is B

See question 1 of http://www.geeksforgeeks.org/compilers-set-2/

Quiz of this Question

sudo-gate-course

My Personal Notes arrow_drop_up
Recommended Articles
Page :