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?

  1. A.

    * has higher precedence than +

  2. B.

    - has higher precedence than *

  3. C.

    + and − have same precedence

  4. 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.

Explore the full course: Mppsc Assistant Professor