Machine-translated by Google. Questions are authored in English.
Top

Discussion

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

\(S \rightarrow ACB\)
\(A \rightarrow aA \mid \epsilon\)
\(C \rightarrow cC \mid \epsilon\)
\(B \rightarrow bB \mid b\)

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

  • A.2
  • B.3
  • C.4
  • D.5

Answer: D

The LR(0) ACTION table has 5 shift-reduce conflicts.

LR(0) reduces on every terminal whenever a state contains a complete item, so a state with both a complete item and an item that shifts a terminal has a conflict. Building the canonical LR(0) collection:

  1. I0 holds S′ → .S, S → .ACB, A → .aA and the complete item A → . (from A → ε): shift on a against reduce A → ε.
  2. After a: A → a.A, A → .aA, A → . : the same conflict on a.
  3. After A from I0: S → A.CB, C → .cC, C → . : shift on c against reduce C → ε.
  4. After c: C → c.C, C → .cC, C → . : the same conflict on c.
  5. After b from S → AC.B: B → b.B, B → b., B → .bB, B → .b : shift on b against reduce B → b.

The remaining states (S → AC.B, the states with a single complete item such as A → aA., C → cC., B → bB., S → ACB., and the accept state) have no conflict. That makes 5, not 2, 3 or 4.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.