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?

  1. A. S ( S ( S )
  2. B. S ( S
  3. C. S ( S )
  4. 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

Exams that ask this topic