GATE Computer ScienceVery hardGATE CS (PYQ pattern)
For G: S → a A b | A a; A → a | ε (which generates a, aa, ab and aab), which statements are true? I. G is LL(2). II. G is LL(3). III. G is LR(1). IV. G is unambiguous.
- A. I, II and IV only
- B. II and IV only
- C. II, III and IV only
- D. IV only
Correct answer: B. II and IV only
Each of the four strings has exactly one tree (IV). With lookahead a at the start, S → a A b (aab, ab) and S → A a (a, aa) share the 2-prefix a a (aab versus aa), so not LL(2); three symbols (a a b versus a a $) decide: LL(3). An LR parser seeing a first must already decide whether to reduce A → ε (the string a) or shift a (A = a, or S → a A b), and one symbol of lookahead cannot tell a$ from aa$: LR(1) conflicts, so G is not LR(1) though it is LL(3) (and hence LR(3)).
More Compiler Design questions
- Let G2: S → A A; A → a A | b and G3: S → A A A; A → a A | b. For each, how many more states does the canonical LR(1) automaton have than…
- A SLR(1) parser for the augmented grammar S → x A | y B; A → z S | ε; B → z S | w parses "x z y w". What is the maximum number of grammar…
- The control-flow graph of 1: if p > 0 goto L2; 2: L1: x = x + 1; 3: if x > n goto L3; 4: L2: y = y + x; 5: if y < m goto L1; 6: L3: return…
- For S → a S b | a b | ε (augmented), how many multiply-defined ACTION cells do the SLR(1), LALR(1) and canonical LR(1) tables have, in…
- Expressions are compared textually (x + y and y + x are different) and an assignment to an operand kills an expression. For 1: a = x + y…
- For S → A a | b A c | B c | b B a; A → d; B → d (augmented), how many states do the LR(0) and canonical LR(1) automata have, and what does…