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?
- A.
* has higher precedence than +
- B.
− has higher precedence than *
- C.
+ and − have the same precedence
- 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 *.