GATE / CS ARCHIVE

GATE CSE 2000 / QUESTION 2.21

Precedence encoded in grammar levels

Compiler Design · Parsing & Syntax Analysis · Full GATE CSE 2000 paper

GATE 2000, Q2.21 2 marks · MCQ
Report issue

Parsing & Syntax Analysis

Question 2.21, GATE 2000: Given E→E*F|F+E|F and F→F−F|id, which operator-precedence claim is true: * above +; − above *; + and − equal; + above *?
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

Step 1: The only grammar productions introducing minus are inside F. Any operand F used by multiplication or addition is therefore formed before the surrounding E-level operation.

Step 2: For example id*id−id must have the minus within the right F, giving id*(id−id), rather than treating minus as an outer E-level operation. Thus minus binds more tightly than multiplication, B.

The E rules do not give a clean unambiguous ordering between + and *; some mixed expressions have multiple parses. F→F−F is itself associative-ambiguous. These ambiguities do not invalidate the separation placing minus at the tighter grammar level.

Original paper, page 6