Question

Consider the canonical LR(0)LR(0) parsing of the grammar below using terminals {a,b,c}\{a, b, c\} and non-terminals {A,B,C,S}\{A, B, C, S\} with SS as the start symbol.

S→ACBS \rightarrow ACB
A→aA∣ϵA \rightarrow aA \mid \epsilon
C→cC∣ϵC \rightarrow cC \mid \epsilon
B→bB∣bB \rightarrow bB \mid b

Which one of the following options gives the number of shift-reduce conflicts that will occur in the LR(0)LR(0) ACTION table?

Choose one option
Official answer and solution
Official answer
D
From
Official GATE 2026 answer key

Solution

Construct the canonical LR(0) states containing reduce items (A→⋅A \rightarrow \cdot, A→aA⋅A \rightarrow aA\cdot, C→⋅C \rightarrow \cdot, C→cC⋅C \rightarrow cC\cdot, B→b⋅B \rightarrow b\cdot, B→bB⋅B \rightarrow bB\cdot, S→ACB⋅S \rightarrow ACB\cdot) and count the shift-reduce conflicts in the LR(0) ACTION table.

In an LR(0)LR(0) parser, a state with a reduce item X→α⋅X \rightarrow \alpha \cdot places a reduce action in every terminal column of the ACTION table (or we count each conflicting (state, terminal) entry or state-level shift-reduce conflict):

  1. Initial state I0I_0: Closure of [S′→⋅S][S' \rightarrow \cdot S] contains [S→⋅ACB][S \rightarrow \cdot ACB], [A→⋅aA][A \rightarrow \cdot aA], and the reduce item [A→⋅][A \rightarrow \cdot] (from ϵ\epsilon-production), with shift on aa (Ia=GOTO(I0,a)I_a = \text{GOTO}(I_0, a) contains identical closure items [A→a⋅A][A \rightarrow a \cdot A], [A→⋅aA][A \rightarrow \cdot aA], [A→⋅][A \rightarrow \cdot]).
  2. State IA=GOTO(I0,A)I_A = \text{GOTO}(I_0, A): Contains [S→A⋅CB][S \rightarrow A \cdot CB], [C→⋅cC][C \rightarrow \cdot cC], and the reduce item [C→⋅][C \rightarrow \cdot], with shift on cc.
  3. State Ic=GOTO(IA,c)I_c = \text{GOTO}(I_A, c): Contains [C→c⋅C][C \rightarrow c \cdot C], [C→⋅cC][C \rightarrow \cdot cC], and the reduce item [C→⋅][C \rightarrow \cdot], with shift on cc.
  4. State Ib=GOTO(IAC,b)I_b = \text{GOTO}(I_{AC}, b): Contains [B→b⋅B][B \rightarrow b \cdot B], [B→b⋅][B \rightarrow b \cdot], [B→⋅bB][B \rightarrow \cdot bB], [B→⋅b][B \rightarrow \cdot b], which has reduce item [B→b⋅][B \rightarrow b \cdot] and shift on bb.

These 5 states (I0I_0, IaI_a, IAI_A, IcI_c, and IbI_b) each contain both a shift item on a terminal (a,a,c,c,ba, a, c, c, b respectively) and a completed reduce item (A→⋅A \rightarrow \cdot in I0,IaI_0, I_a; C→⋅C \rightarrow \cdot in IA,IcI_A, I_c; B→b⋅B \rightarrow b \cdot in IbI_b), producing exactly 5 shift-reduce conflicts in the LR(0)LR(0) ACTION table.

Final answer

Option (D)

Common trap

Forgetting that GOTO(I0,a)\text{GOTO}(I_0, a), GOTO(IA,c)\text{GOTO}(I_A, c), or GOTO(IAC,b)\text{GOTO}(I_{AC}, b) are distinct canonical LR(0)LR(0) states that also contain the ϵ\epsilon-reduce / B→b⋅B \rightarrow b\cdot items.

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2026 Computer Science and Information Technology - Session 2 (CS2)
Question
41 of 65
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.