Consider the grammar defined by the following production rules, with two operators * and + S → T * P T → U T * U P → Q + P Q Q → Id U → Id Which one of the following is TRUE?
Topic-wise GATE CS PYQs with verified steps
GATE CSE 2014 Set 2 · Q17
Time
Select one answerSingle correct
Solution
Official answer: B) + is right associative, while * is left associative
ParsingTo determine the associativity of operators from context-free grammar productions:
**For operator T \rightarrow T * U \mid UTT \rightarrow T * U$), the production is left-recursive. Therefore, the operator is left-associative.
For operator $+: The production rule is . Since the non-terminal appears on the rightmost position on the right-hand side (), the production is right-recursive. Therefore, the operator is right-associative.
Hence, is right associative, while is left associative, which corresponds to option (B).
Try the question first, then check your work.
Examiner trap
Check whether the recursive step for each operator is left-recursive or right-recursive.
This Parsing previous year question is Q17 of the GATE CSE 2014 Set 2 paper. Find more GATE CSE PYQs on Parsing in Compiler Design, or browse all GATE CSE PYQs.
Free diagnostic
Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Parsing PYQs now with no account.
An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.
Parsing has 23 GATE CSE PYQs across 16 papers from 2012 to 2026. 5 of them are 1-mark MCQs like this one, and it is the only one in GATE CSE 2014 Set 2.
How GATE tests ParsingIndependent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.