GATE / CS ARCHIVE

GATE CSE 2014 SET 2 / QUESTION 17

GATE CSE 2014 Set 2 Q17

Compiler Design · Parsing & Syntax Analysis · Full GATE CSE 2014 Set 2 paper

GATE 2014 Set 2, Q17 1 mark · MCQ
Report issue

Parsing & Syntax Analysis

Question 17, GATE 2014: Grammar: S→T*P; T→U or T*U; P→Q+P or Q; Q→Id; U→Id. Which associativity statement is true? A + left, * right; B + right, * left; C both right; D both left.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

1. Set up the reasoning. Inspect the recursive side of each operator production. T recurs on the left of *, while P recurs on the right of +.

2. Derive the result. The rule T→T*U is left-recursive and groups multiplication to the left. P→Q+P is right-recursive and groups addition to the right. Thus + is right associative and * left associative, B.

3. Check the interpretation. Expanding T twice gives (Id*Id)*Id, whereas expanding P twice gives Id+(Id+Id). Associativity concerns grouping of repeated operators, not which operator has greater precedence.

Original paper, page 33 · Answer key