Skip to content
Official PYQ · 2026

GATE CS 2026 Set 2 Q31 — Parsing (LL, LR)

Explain with AI

Consider the canonical LR(0)L R(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→ACBA→aA∣ϵC→cC∣ϵB→bB∣b\begin{array}{l} S \rightarrow A C B \\ A \rightarrow a A \mid \epsilon \\ C \rightarrow c C \mid \epsilon \\ B \rightarrow b B \mid b \end{array}
Which one of the following options gives the number of shift-reduce conflicts that will occur in the LR(0)L R(0) ACTION table?

Choose one option
View worked solution

Answer: D

To find the number of shift-reduce (S-R) conflicts in the LR(0)LR(0) parsing table, we construct the canonical collection of LR(0)LR(0) items for the augmented grammar:

  1. S′→SS' \rightarrow S
  2. S→ACBS \rightarrow A C B
  3. A→aA∣ϵA \rightarrow a A \mid \epsilon
  4. C→cC∣ϵC \rightarrow c C \mid \epsilon
  5. B→bB∣bB \rightarrow b B \mid b

An LR(0)LR(0) state has a shift-reduce conflict if it contains at least one shift item (e.g., X→α⋅aβX \rightarrow \alpha \cdot a \beta) and at least one reduce item (e.g., Y→γ⋅Y \rightarrow \gamma \cdot). Let's trace the states containing such conflicts:

  • State I0I_0:
    S′→⋅SS' \rightarrow \cdot S
    S→⋅ACBS \rightarrow \cdot A C B
    A→⋅aAA \rightarrow \cdot a A   (shift on aa)
    A→⋅A \rightarrow \cdot   (reduce A→ϵA \rightarrow \epsilon)
    Conflict 1

  • State I2=goto(I0,A)I_2 = \text{goto}(I_0, A):
    S→A⋅CBS \rightarrow A \cdot C B
    C→⋅cCC \rightarrow \cdot c C   (shift on cc)
    C→⋅C \rightarrow \cdot   (reduce C→ϵC \rightarrow \epsilon)
    Conflict 2

  • State I3=goto(I0,a)I_3 = \text{goto}(I_0, a):
    A→a⋅AA \rightarrow a \cdot A
    A→⋅aAA \rightarrow \cdot a A   (shift on aa)
    A→⋅A \rightarrow \cdot   (reduce A→ϵA \rightarrow \epsilon)
    Conflict 3

  • State I5=goto(I2,c)I_5 = \text{goto}(I_2, c):
    C→c⋅CC \rightarrow c \cdot C
    C→⋅cCC \rightarrow \cdot c C   (shift on cc)
    C→⋅C \rightarrow \cdot   (reduce C→ϵC \rightarrow \epsilon)
    Conflict 4

  • State I8=goto(I4,b)I_8 = \text{goto}(I_4, b) where I4=goto(I2,C)I_4 = \text{goto}(I_2, C):
    B→b⋅BB \rightarrow b \cdot B
    B→b⋅B \rightarrow b \cdot   (reduce B→bB \rightarrow b)
    B→⋅bBB \rightarrow \cdot b B   (shift on bb)
    B→⋅bB \rightarrow \cdot b   (shift on bb)
    Conflict 5

No other states contain both a shift and a reduce item. Thus, there are exactly 55 shift-reduce conflicts in the LR(0)LR(0) parsing table.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Parsing (LL, LR) questions