Consider the following grammar: p → xQRS Q → yz | z R → w | ε S → y What is…

2017

Consider the following grammar:

p → xQRS

Q → yz | z

R → w | ε

S → y

What is FOLLOW(\(Q\))?

  1. A.

    \(\left \{ R \right \}\)

  2. B.

    \(\left \{ w \right \}\)

  3. C.

    \(\left \{ w,y \right \}\)

  4. D.

    {w,$}

Attempted by 251 students.

Show answer & explanation

Correct answer: C

Key idea: compute FIRST of the symbols that follow Q in the production p -> x Q R S and use that to find FOLLOW(Q).

  • FIRST(R) = {w, ε} because R -> w | ε.

  • FIRST(R S) = FIRST(R) without ε plus (if R is nullable) FIRST(S). So FIRST(R S) = {w} ∪ {y} = {w, y}.

  • Therefore FOLLOW(Q) = {w, y}. The end-of-input marker is not included because S -> y is not nullable.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir