GATE 2017 CS – Question 27
Consider the following grammar:
$P \rightarrow xQRS$
$Q \rightarrow yz \mid z$
$R \rightarrow w \mid \epsilon$
$S \rightarrow y$
What is FOLLOW($Q$)?
Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: (C) $\{w, y\}$
Explanation
In $P \rightarrow xQRS$, $Q$ is followed by $R$ and then $S$. FIRST($R$) is $\{w\}$, and since $R$ can be empty, FIRST($S$) $= \{y\}$ also follows $Q$. So FOLLOW($Q$) $= \{w, y\}$.