Given the following expressions of a grammar E → E * F / F + E / F F → F − F /…
2012
Given the following expressions of a 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 *
Attempted by 112 students.
Show answer & explanation
Correct answer: B
In compiler grammar, left-recursion implies higher precedence than right-recursion. Here, E → E * F is left-recursive for multiplication, while E → F + E is right-recursive for addition. Thus, * binds tighter than +.
A video solution is available for this question — log in and enroll to watch it.