GATE Computer ScienceHardGATE CS (PYQ pattern)
A table-driven LL(1) parser for S → a S A | ε; A → b S | c parses "a a b a c c". Each expansion of a non-terminal and each match of a terminal is one move. How many moves does it make until both stack and input hold only $, and how many of the expansions use S → ε?
- A. 14 moves, 3 of them S → ε
- B. 12 moves, 2 of them S → ε
- C. 14 moves, 2 of them S → ε
- D. 16 moves, 4 of them S → ε
Correct answer: C. 14 moves, 2 of them S → ε
FOLLOW(S) = {b, c, $}. Trace: S→aSA, a, S→aSA, a, S→ε (lookahead b), A→bS, b, S→aSA, a, S→ε (lookahead c), A→c, c, A→c, c. That is 8 expansions + 6 matches = 14 moves, with S → ε used twice.
More Compiler Design questions
- 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…
- 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…