Which one of the following grammars is free from *left recursion*?
Topic-wise GATE CS PYQs with verified steps
GATE CSE 2016 Set 2 · Q45
Time
Select one answerSingle correct
Solution
Official answer: B) S → Ab Bb c A → Bd B → e
ParsingA context-free grammar has left recursion if there exists a non-terminal such that for some string .
Let us analyze each option:
Option (A):
This contains immediate (direct) left recursion on ().
Option (B):
Let us compute the leading non-terminals reachable from each non-terminal:
or
or
No non-terminal can derive a sentential form starting with itself ($X
ot\Rightarrow^+ X\alpha$). Hence, this grammar is free from left recursion.
Option (C):
Derivation: . Since , there is indirect left recursion on .
Option (D):
Derivation: . Since , there is indirect left recursion on (and similarly on ).
Thus, only the grammar in (B) is free from left recursion.
Try the question first, then check your work.
Examiner trap
Check for both direct left recursion () and indirect left recursion () by expanding the non-terminals.
This Parsing previous year question is Q45 of the GATE CSE 2016 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. 11 of them are 2-mark MCQs like this one, and it is the only one in GATE CSE 2016 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.