GATE / CS ARCHIVE

GATE CSE 2015 SET 1 / QUESTION 18

GATE CSE 2015 Set 1 Q18

Compiler Design · Parsing & Syntax Analysis · Full GATE CSE 2015 Set 1 paper

GATE 2015 Set 1, Q18 1 mark · MCQ
Report issue

Parsing & Syntax Analysis

Question 18, GATE 2015: At any valid shift-reduce parsing state, which is true? A viable prefixes appear only at the stack bottom, not inside; B only at its top, not inside; C the stack contains only a set of viable prefixes; D it never contains viable prefixes.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

A handle is the portion reduced in a reverse rightmost derivation. A viable prefix stops at or before the right end of such a handle. The parser stack's grammar symbols form one viable prefix, and each initial segment of those symbols is also viable. Read the paper's “set” wording in this prefix sense, not as a claim that arbitrary internal substrings or LR state numbers are grammar prefixes.

Solution: The grammar-symbol portion of a shift-reduce stack is a viable prefix: a prefix of a right-sentential form that does not pass the handle’s right end. Taking a shorter prefix cannot cross that end, so every prefix is viable too. Thus C.

Original paper, page 8 · Answer key