GATE / CS ARCHIVE

GATE CSE 1995 / QUESTION 2.10

Reduction-time translation

Compiler Design · Semantic Analysis & Type Checking · Full GATE CSE 1995 paper

GATE 1995, Q2.10 2 marks · MCQ
Report issue

Semantic Analysis & Type Checking

Question 2.10, GATE 1995: Grammar S→xxW {print1}, S→y {print2}, W→Sz {print3}. What is printed by a shift-reduce parse of xxxxyzz?
Tap to enlarge
Your answer
Answer & solution

Answer: A: 23131 (no official key was published)

Step through it (14 steps)

The innermost y reduces to S first, printing 2. That S followed by z reduces to W, printing 3. The preceding xx and this W reduce to S, printing 1. The remaining outer z then permits W→Sz, printing another 3, and the remaining outer xxW reduces to S, printing the last 1. Thus the output is 23131. Actions occur after reductions, giving inside-out order rather than the order of productions in a top-down derivation.

Original paper, page 4