GATE Computer ScienceHardGATE CS (PYQ pattern)
For S → a A | A b; A → c | ε (augmented), how many non-blank ACTION entries does the initial state I0 have in the SLR(1) table, and in the LALR(1) table?
- A. 4 in SLR(1), 3 in LALR(1)
- B. 3 in SLR(1), 3 in LALR(1)
- C. 4 in SLR(1), 4 in LALR(1)
- D. 2 in SLR(1), 2 in LALR(1)
Correct answer: A. 4 in SLR(1), 3 in LALR(1)
I0 holds S → ·a A, S → ·A b, A → ·c, A → ·. Shifts on a and c. SLR reduces A → ε on all of FOLLOW(A) = {b, $} ($ comes from S → a A), giving 4 entries. In I0 the A can only be the one in S → A b, so its LR(1) lookahead is just b: LALR(1) has 3 entries and an error on $.
More Compiler Design questions
- For S → a S | a S b S | c (augmented), how many states does the canonical LR(1) automaton have, and how many ACTION cells of the canonical…
- For G: S → A | B; A → a A b | ε; B → a B b b | ε, which of these statements are true? I. Exactly two cells of the LL(1) table, M[S, a] and…
- The grammar S → i S | i S e S | a is ambiguous. How many distinct parse trees does the string "i i i a e a e a" have?
- int A(int m, int n) { if (m == 0) return n + 1; if (n == 0) return A(m - 1, 1); return A(m - 1, A(m, n - 1)); } Each activation record…
- For S → id | id [ E ] | id ( E ); E → id (augmented with S′ → S), how many states do the LR(0) and the canonical LR(1) automata have?
- The grammar S → A B; A → a A | a; B → a B | a is ambiguous. How many distinct parse trees does the string "a a a a a a" have?