GATE Computer ScienceHardGATE CS (PYQ pattern)
An SLR(1) shift-reduce parser for E → E + T | T; T → T * F | F; F → ( E ) | id parses "( id + id ) * id". Each shift and each reduce counts as one move. What are the grammar symbols on the parser stack (bottom to top) right after move number 8? (Initial state excluded.)
- A. ( E + id
- B. ( E + F
- C. ( E + T
- D. ( E
Correct answer: B. ( E + F
Simulating the SLR table move by move, the stack after move 8 holds: ( E + F.
More Compiler Design questions
- An LR parser for S → S ( S ) | ε parses "( ( ) ) ( )". Each shift and each reduce (including reductions by S → ε) counts as one move. What…
- 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…