Given a Context-Free Grammar as follows:
Which ONE of the following statements is TRUE?
GATE CSE 2025Compiler Design › Grammars & ParsingVerified
GATE CSE 2025 PYQ: Given a Context-Free Grammar G \text{G} G as follows: S → A a ∣ b A c ∣ d c ∣ b d a A → d \begin{array}{l}…
- Ais neither nor
- Bis , not
- CisCorrect answer
- Dis , also
Answer
(C) G \text{G} G is LALR ( 1 ) , not SLR ( 1 ) \operatorname{LALR}(1), \operatorname{not} \operatorname{SLR}(1) LALR ( 1 ) , not SLR ( 1 )
Approach
Build the LR(0) automaton and compute FOLLOW(A). The only possible conflict arises from the item A -> d. in the state reached after shifting d from the initial state, because SLR(1) uses FOLLOW(A) = {a, c}. Then compare with the more precise LR(1)/LALR(1) lookaheads to see whether that conflict survives.
The SLR(1) table contains a shift-reduce conflict at the state reached after shifting d from the start state: on symbol c it must both shift for S -> d . c and reduce A -> d because c ∈ FOLLOW(A). Canonical LR(1) uses the exact lookahead a in that state, and LALR(1) does not merge this state with any other state having the same core, so the conflict disappears. Thus G is LALR(1), not SLR(1).
Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.