Skip to content
Related Articles
Open in App
Not now

Related Articles

GATE | GATE-CS-2000 | Question 49

Improve Article
Save Article
Like Article
  • Difficulty Level : Hard
  • Last Updated : 12 Sep, 2019
Improve Article
Save Article
Like Article

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 https://www.geeksforgeeks.org/compilers-set-2/

Quiz of this Question

My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!