GATE / CS ARCHIVE

GATE CSE 2017 SET 1 / QUESTION 17

GATE CSE 2017 Set 1 Q17

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

GATE 2017 Set 1, Q17 1 mark · MCQ
Report issue

Parsing & Syntax Analysis

Question 17, GATE 2017: Grammar: P→xQRS; Q→yz | z; R→w | ε; S→y. Find FOLLOW(Q). A {R}; B {w}; C {w,y}; D {w,$}.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Step through it (13 steps)

1. FOLLOW(Q) contains terminal symbols that can occur immediately after a derivation of Q, not the next nonterminal’s name. Its only occurrence is in P→xQRS.

2. R can produce w, placing w immediately after Q. It can also disappear through ε, exposing S, which produces y.

3. S is not nullable, so Q never reaches the end of this production and no end marker is inherited. FOLLOW(Q)={w,y}, C.

Original paper, page 10 · Answer key