• retagged by
12,208 views
32 32 votes

Consider the following grammar:

  • $P\rightarrow xQRS$
  • $Q\rightarrow yz\mid z$
  • $R\rightarrow w\mid \varepsilon$
  • $S\rightarrow y$

What is FOLLOW($Q$)?

  1. $\left \{ R \right \}$
  2. $\left \{ w \right \}$
  3. $\left \{ w,y \right \}$
  4. $\left \{ w,\$ \right \}$

8 Answers

Best answer
32 32 votes

Follow of $Q$ is first of $R$ so we get $\{w\}$

but since $R$ can be Null so we have to check first of $S$ which is $\{y\}$

so FOLLOW $Q=\{w,y\}$

Correct option (C)

• edited by
13 13 votes

correct option is c.

7 7 votes
\[
\begin{array}{|c|c|c|}
\hline
\textbf{Non-terminal} & \textbf{FIRST} & \textbf{FOLLOW} \\
\hline
P & \{x\} & \{\$\} \\
\hline
Q & \{y, z\} & \{w, y\} \\
\hline
R & \{w, \varepsilon\} & \{y\} \\
\hline
S & \{y\} & \{\$\} \\
\hline

\end{array}
\]
$\text{Follow(Q) ={w,y}}$

Correct Answer : $C$
• edited by
0 0 votes

In the production: P → xQRS,
FOLLOW (Q) = FIRST (R)
FIRST (R) = {w, ϵ} >br> Since FIRST (R) = {ϵ}, so FOLLOW (Q) → {w} ∪ FIRST(S)
FIRST(S) = {y}
So, FOLLOW (Q) = {w, y}

0 0 votes
Answer: C

$$\text{Follow(Q) = First(RS) = First(R) = } \{w,\epsilon\}$$ 

$$\text{But, since R directly generates Null } (\epsilon), \text{ substituting } \epsilon \text{ back in the production of P gives: } $$ 

$$\text{Follow(Q) = First(RS) = First(R)} \cup \text{First(S) - } \{\epsilon\} =\{w,y\}$$ 

$$\text{Note: Back substitution of epsilon vanishes the non-terminal generating NULL and omits epsilon.}$$ 

$$\text{Note: Epsilon NEVER comes in the FOLLOW of a non-terminal and \$ NEVER comes in the FIRST of the same.}$$ 

 

Answer:
Position:
Show:

Related questions

85 85 votes
14 answers 14 answers
34.8k
34.8k views
Arjun asked Feb 14, 2017
34,840 views
Consider the following grammar:stmt $\rightarrow$ if expr then expr else expr; stmt | $Ò$expr $\rightarrow$ term relop term | termterm $\rightarrow$ id | numberid $\right...
21 21 votes
4 4 answers
6.8k
6.8k views
Arjun asked Feb 27, 2025
6,799 views
Which of the following statement(s) is/are TRUE while computing $\operatorname{First}$ and $\operatorname{Follow}$ during top down parsing by a compiler?For a production ...
1 1 vote
0 0 answers
2.5k
2.5k views
aditi19 asked May 12, 2019
2,529 views
why do first sets can have epsilon symbol but follow sets don’t?P.S: I’ve a silly doubt :P