GATE Computer ScienceHardGATE CS (PYQ pattern)

For S′ → S; S → a S a | b S b | c, the canonical LR(1) states with identical cores are merged to obtain LALR(1). The LALR state whose only item is S → c · is the merge of how many canonical LR(1) states, and what is its lookahead set?

  1. A. 3 states; {a, b, $}
  2. B. 2 states; {a, b}
  3. C. 3 states; {a, b}
  4. D. 1 state; {a, b, $}

Correct answer: A. 3 states; {a, b, $}

c can be the whole sentence (lookahead $), the middle of a…a (lookahead a) or of b…b (lookahead b). Each context reaches S → c· through a different LR(1) state, so three LR(1) states merge into one LALR state with lookaheads {a, b, $}.

More Compiler Design questions

Exams that ask this topic