GATE Computer ScienceHardGATE CS (PYQ pattern)

For S′ → S; S → A | x b; A → a A b | B; B → x, what is the LALR(1) lookahead set of the item B → x · in the state reached from the start state on x, and in the state reached on a then x?

  1. A. {$} and {b}
  2. B. {b, $} and {b, $}
  3. C. {$} and {b, $}
  4. D. {b} and {$}

Correct answer: A. {$} and {b}

From the start, x is either the beginning of S → x b or a B that is the whole A = S, so B → x· has lookahead $ (and the item S → x·b shifts b — which is why SLR, using FOLLOW(B) = {b, $}, has a conflict here). After a, the B is inside a A b, so it is followed only by b. The two states have different cores, so nothing is merged.

More Compiler Design questions

Exams that ask this topic