GATE Computer ScienceModerateGATE CS (PYQ pattern)
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 how many times does the SLR(1) parser reduce by S → ε?
- A. 4 and 4
- B. 4 and 3
- C. 5 and 5
- D. 3 and 4
Correct answer: A. 4 and 4
The grammar is unambiguous, so both parsers build the same parse tree; each uses S → ε once per ε-leaf. The tree is S → ( S1 ) S2 with S1 → ( ε ) ε and S2 → ( ε ) ε: four ε-leaves, hence 4 and 4 — the LL parser in leftmost order, the LR parser in reverse rightmost order.
More Compiler Design questions
- 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…
- Consider strings containing both ab and bb as substrings in either order (overlaps allowed). How many states does the minimal complete DFA…
- G1: L → L , x | x and G2: L → x , L | x generate the same language. A shift-reduce (LR) parser parses "x , x , x , x , x" (five x's) with…
- Productions of the grammar are numbered: (1) E → E + T; (2) E → T; (3) T → T F; (4) T → F; (5) F → ( E ); (6) F → id. An LR parser parses…