GATE Computer ScienceVery hardGATE CS (PYQ pattern)
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 M[S, $], are multiply defined. II. G is ambiguous. III. Some LR(1) grammar generates L(G).
- A. I and II only
- B. I only
- C. I and III only
- D. I, II and III
Correct answer: A. I and II only
FIRST(A) = FIRST(B) = {a, ε} and both are nullable, so S → A and S → B both go to M[S, a] and M[S, $]; the A- and B-rows have no clash (a versus FOLLOW = {b, $}). The empty string has two parse trees (S → A → ε and S → B → ε), so G is ambiguous. L(G) = {aⁿbⁿ} ∪ {aⁿb²ⁿ} is the standard inherently non-deterministic CFL: no DPDA accepts it, so no LR(1) grammar generates it.
More Compiler Design questions
- 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?
- For the declaration grammar D → T L; T → int | float; L → L , id | id (augmented with D′ → D), how many states does the LR(0) automaton…
- Build the SLR(1) table of S → A a | b A c | d c | b d a; A → d (augmented). Which option describes all of its conflicts?