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\))?
- A.
\(\left \{ R \right \}\) - B.
\(\left \{ w \right \}\) - C.
\(\left \{ w,y \right \}\) - 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.