Given a Context-Free Grammar G as follows: S → Aa bAc dc bda A → d Which ONE of the following statements is TRUE?
Topic-wise GATE CS PYQs with verified steps
GATE CSE 2025 Set 2 · Q40
Time
Select one answerSingle correct
Solution
Official answer: C) G is LALR(1), not SLR(1)
ParsingLet us analyze the grammar by constructing the LR(0) and LR(1) items:
Augmented Grammar:
SLR(1) Analysis:
: From , . From , . Hence, .
In the initial canonical collection state :
On input symbol from , we transition to state :
In state , on terminal :
There is a shift action due to .
There is a reduce action due to since .
This causes a Shift-Reduce (SR) conflict on symbol . Therefore, the grammar is not SLR(1).
CLR(1) and LALR(1) Analysis:
In the LR(1) collection, the lookaheads are computed explicitly:
In , the item has lookahead because it is generated from [S \rightarrow \cdot Aa, \]$.
The item [S \rightarrow \cdot dc, \][S \rightarrow d \cdot c, \$]c$.
Thus, in the state for :
Shift on for [S \rightarrow d \cdot c, \]$.
Reduce by on lookahead for .
Since the lookaheads for shift and reduce are disjoint (), there is no conflict.
Similarly, after transitioning on , the state containing has lookahead and [S \rightarrow bd \cdot a, \]a$, which are also conflict-free.
No merge conflicts arise when converting to LALR(1).
Hence, is LALR(1), not SLR(1), which matches option (C).
Try the question first, then check your work.
Examiner trap
Check for shift-reduce conflicts in state using for SLR(1) versus the precise lookaheads for LR(1)/LALR(1).
This Parsing previous year question is Q40 of the GATE CSE 2025 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 GATE CSE 2025 Set 2 has 2.
How GATE tests ParsingIndependent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.