306 views
3 3 votes

Consider the following context-free grammar:

  • $E \rightarrow T E^{\prime}$
     
  • $E^{\prime} \rightarrow+T E^{\prime} \mid \epsilon$
     
  • $T \rightarrow F T^{\prime}$
     
  • $T^{\prime} \rightarrow * F T^{\prime} \mid \epsilon$
     
  • $F \rightarrow(E) \mid i$


What is $\operatorname{FOLLOW}\left(T^{\prime}\right)$ ?

  1. $\{*\}$
     
  2. $\{+, \$,)\}$
     
  3. $\{+,)\}$
     
  4. $\{+, \$,), \epsilon\}$

2 Answers

3 3 votes

Locate $\mathbf{T}^{\prime}: T^{\prime}$ appears at the end of the productions $T \rightarrow F \mathbf{T}^{\prime}$ and $T^{\prime} \rightarrow * F \mathbf{T}^{\prime}$.

  • Because $T^{\prime}$ is the last symbol in $T \rightarrow F T^{\prime}$, everything that follows $T$ must also follow $T^{\prime}$.
     
  • Therefore, $\operatorname{FOLLOW}\left(T^{\prime}\right)=\operatorname{FOLLOW}(T)$.
     

Find $\operatorname{FOLLOW}\mathrm{(T)}$: We look for $T$ in the grammar ( $E \rightarrow \mathbf{T} E^{\prime}$ ).

  • $T$ is followed by $E^{\prime}$.
     
  • So, $\operatorname{FOLLOW}(T)$ includes $\operatorname{FIRST}\left(E^{\prime}\right)$ (excluding $\epsilon$ ).
     
  • $\operatorname{FIRST}\left(E^{\prime}\right)=\{+, \epsilon\}$. So, we add $+$ .
     

Handle Epsilon again: Since $E^{\prime}$ can be $\epsilon, \operatorname{FOLLOW}(T)$ also includes $\operatorname{FOLLOW}(E)$.


$E$ is the start symbol (conventionally), so it includes the end-of-input marker $\textbf{\$}$.

$E$ also appears inside parentheses in $F \rightarrow(E)$. So it is followed by ).

$\operatorname{FOLLOW}(E)=\{ ), \$\}$.

$\left.\operatorname{FOLLOW}\left(T^{\prime}\right)=\{+,), \$\right\}$

Answer:
Position:
Show:

Related questions

2 2 votes
2 2 answers
344
344 views
GO Classes asked Dec 9, 2025
344 views
Consider the following context-free grammar:$A \rightarrow b B C$ $B \rightarrow d \mid \epsilon$ $C \rightarrow a \mid f$ What is $\operatorname{FOLLOW}(B)$ ? $\{C\}$ $\...
3 3 votes
2 2 answers
345
345 views
GO Classes asked Dec 9, 2025
345 views
Consider the following multi-line C code snippet: int *ptr_arr[MAX_VAL], x = 0; /* Token counting starts from the next line */ do { ptr_arr[x] = &x; } while ((x++ < M...
2 2 votes
2 2 answers
339
339 views
GO Classes asked Dec 9, 2025
339 views
The number of tokens in the following C statement isif(ptr->count++ >= 10 && !flag) $11$ $12$ $13$ $14$
4 4 votes
3 3 answers
312
312 views
GO Classes asked Dec 9, 2025
312 views
A C program contains a call to a function named $\verb|calculate_area|$ in $\verb|main()|$, but the function definition itself is entirely missing from all source files...