GATE | GATE-CS-2000 | Question 49
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
Attention reader! Don’t stop learning now. Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.
Learn all GATE CS concepts with Free Live Classes on our youtube channel.



