Open In App

GATE | GATE-CS-2017 (Set 1) | Question 23

Consider the following grammar

p --> xQRS
Q --> yz|z
R --> w|∈
S -> y

Which is FOLLOW(Q)?



(A) {R}
(B) {w}
(C) {w, y}
(D) {w, ∉}

Answer: (C)
Explanation:

Alternate Solution



To compute FOLLOW(A) for all non terminals A, apply the following rules until nothing can be added to any FOLLOW set:

Therefore, follow(Q) = First(RS) = ( w ) ∪ First(S) = { w } ∪ { y } = { w,y }.

Note that here, first(S) is not ∈.

This explanation has been contributed by Mithlesh Upadhyay.

Quiz of this Question

Article Tags :