Given the following expression grammar: E → E * F | F + E | F F → F − F | id…

2025

Given the following expression 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 the same precedence

  4. D.

    + has higher precedence than *

Attempted by 30 students.

Show answer & explanation

Correct answer: B

Correct answer: - has higher precedence than *.

  • Grammar level matters: Operators generated inside the lower nonterminal F bind more tightly than operators generated at E level.

  • Subtraction: The rule F → F − F defines − within F, so a subtraction expression can behave as a single F when used inside an E production.

  • Multiplication and addition: Both * and + are introduced in productions for E, so they do not bind more tightly than the operator inside F.

Therefore, the true statement among the options is that − has higher precedence than *.

Explore the full course: Niacl Ao It Specialist