GATE Computer ScienceHardGATE CS (PYQ pattern)
The grammar S → X Y Z; X → a X | ε; Y → b Y | X; Z → c | ε is not LL(1). How many distinct parse trees does the string "a a a c" have?
- A. 3
- B. 4
- C. 1
- D. 8
Correct answer: B. 4
Y derives b*a*, so with no b in the string X derives a^i and Y (through Y → X) derives a^(3−i), Z → c. i can be 0, 1, 2 or 3, giving 4 trees; the ambiguity is why M[X, a] holds both X → a X and X → ε.
More Compiler Design questions
- Construct the SLR(1) parsing table of S → a S b S | b S a S | ε (augmented). In how many states of the SLR(1) automaton does the ACTION…
- G1: S → A B; A → a A | c; B → a B | c. G2: S → A B A; A → a A | c; B → b B | c. For each, how many more states does the canonical LR(1)…
- The grammar S → ( S ) S | ε is both LL(1) and SLR(1). On the input "( ( ) ) ( )", how many times does the LL(1) parser expand S → ε, and…
- Integer code: a = 4; b = a 2; c = b + n; d = c 0; e = d + b; f = e - 8; g = n + f; h = g 1; r = h. Only r is live at the end. The…
- For S → A | x b; A → a A b | B; B → x (augmented), how many states does the canonical LR(1) automaton have, and in how many states of the…
- A yacc-generated parser for E → E op E | num uses the precedence declarations %left ''; %right '-'; %left '+' (in this order, so + binds…