GATE Computer ScienceVery hardGATE CS (PYQ pattern)

For S → a A | b B; A → c A d | ε; B → c B d d | ε (augmented with S′ → S), count the reduce entries (state, terminal) in the ACTION tables, $ column included, accept excluded. What are the counts for the SLR(1), LALR(1) and canonical LR(1) tables, in that order?

  1. A. 14, 14 and 12
  2. B. 14, 10 and 12
  3. C. 10, 10 and 12
  4. D. 14, 10 and 10

Correct answer: B. 14, 10 and 12

FOLLOW(A) = FOLLOW(B) = {d, $}. SLR: six complete-item states for A/B (two ε-states and one c…d state per non-terminal) get 2 entries each = 12, plus S → a A· and S → b B· on $ = 14. LALR: the ε-state right after a (or b) has lookahead $ only and the one after a c (or b c) has d only, saving 4: 10. LR(1) splits A → c A d· and B → c B d d· into a $-copy and a d-copy, and also has a separate ε-state for deeper nesting (lookahead d): 12.

More Compiler Design questions

Exams that ask this topic