GATE Computer ScienceVery hardGATE CS (PYQ pattern)
An LR parser for S → S ( S ) | ε parses "( ( ) ) ( )". Each shift and each reduce (including reductions by S → ε) counts as one move. What are the grammar symbols on the stack, bottom to top, right after move 7?
- A. S ( S ( S )
- B. S ( S
- C. S ( S )
- D. S ( (
Correct answer: B. S ( S
Move 1 reduces S → ε (the S that every S ( S ) starts with). Then: 2 shift ( → S (, 3 reduce ε → S ( S, 4 shift ( → S ( S (, 5 reduce ε → S ( S ( S, 6 shift ) → S ( S ( S ), 7 reduce S → S ( S ) → S ( S.
More Compiler Design questions
- Minimal SSA form (φ-functions at the iterated dominance frontier of each variable's defining blocks, no pruning) is built for 1: x = 1; 2…
- SSA form is built for 1: i = 0; 2: L1: if i >= n goto L4; 3: if i > k goto L2; 4: x = i 2; 5: goto L3; 6: L2: x = i + 1; 7: y = x; 8: L3…
- Minimal SSA form without liveness pruning (φ-functions at the iterated dominance frontier of every block that assigns the variable) is…
- In 1: a = 1; 2: b = 2; 3: if p > 0 goto L1; 4: a = a + 1; 5: goto L2; 6: L1: b = b + 1; 7: L2: c = a + b; 8: if c > q goto L3; 9: a = c…
- The statement r = ((x y) + (y x)) ((x y) − z) + (z − x y) is turned into a DAG (+ and commutative, − not), and code is generated with one…
- For the grammar S → a A | A b; A → c | ε, what is FOLLOW(A)?