GATE Computer ScienceVery hardGATE CS (PYQ pattern)
For G: S → A b | a A c | B c | a B b; A → a; B → a, which statements are true? I. G is LL(2). II. G is SLR(1). III. G is LALR(1). IV. The LALR(1) and canonical LR(1) automata have the same number of states.
- A. II, III and IV only
- B. I, III and IV only
- C. III and IV only
- D. III only
Correct answer: C. III and IV only
I: a a c (from a A c) and a a b (a B b) share the 2-prefix a a: not LL(2) (it is LL(3)). II: FOLLOW(A) = FOLLOW(B) = {b, c}, so both states {A → a·, B → a·} have reduce-reduce clashes. III/IV: the state after a alone reduces A on b, B on c; after a a it reduces A on c, B on b. Those two states have different cores (the first also holds S → a·A c, S → a·B b), so no core is split and LALR = LR(1), conflict-free.
More Compiler Design questions
- For E → id | E [ E ] | ( E ) (augmented), how many states does the LR(0) automaton have, and which is the strongest of LR(0) / SLR(1) /…
- S → A B; A → a | ε; B → A b | c generates exactly five strings, and its LL(1) table has one multiply-defined cell. If that cell is…
- Consider an SDD where for A → B C the rules are: B.i = A.i + 1, C.i = B.s, A.s = C.s. Which statement is correct?
- Consider these claims about LR parsers. I. Merging LR(1) states with the same core can create a shift-reduce conflict that the canonical…
- Code: k = 3; m = k k; k = k + 1; p = k m; q = p - 36; s = q + z; r = s 1. Only r is live at the end and z is an input. After constant…
- A predictive translator uses E → T R; R → + { print('+') } T R | − { print('−') } T R | ε; T → num { print(num.val) }. (The print action…