329 views
2 2 votes

Consider the following grammar $G$ with non-terminals $\{S, A, B, C\}$ and terminals $\{a, b, c, d, g\}$ :

$$
\begin{aligned}
& S \rightarrow A B \\
& A \rightarrow a A \mid \epsilon \\
& B \rightarrow b B \mid C \\
& C \rightarrow c C \mid d \mid \epsilon
\end{aligned}
$$


What is the FOLLOW set of the non-terminal $A$ ?

  1. $\{a, b, c, d\}$
     
  2. $\{b, c, d, \$\}$
     
  3. $\{b, c, d\}$
     
  4. $\{B, b, c, d, \$\}$

2 Answers

0 0 votes
$\{b, c, d, \$\}$

Since $S \rightarrow A B$, $\operatorname{FOLLOW}(\mathrm{A})$ contains $\operatorname{FIRST}(\mathrm{B})$. Because $B$ is nullable ( $\mathrm{B} \rightarrow \mathrm{C} \rightarrow \epsilon$ ), $\operatorname{FOLLOW}(\mathrm{A})$ also inherits $\operatorname{FOLLOW}(\mathrm{S})$, which is $\{\$\}$.
Answer:
Position:
Show:

Related questions

3 3 votes
2 2 answers
325
325 views
GO Classes asked Jan 16
325 views
Consider the following context-free grammar:$$\begin{aligned}& E \rightarrow T R \\& R \rightarrow+T R \mid \epsilon \\& T \rightarrow F Y \\& Y \rightarrow * F Y \mid \e...
4 4 votes
3 3 answers
362
362 views
GO Classes asked Jan 16
362 views
Consider a language that allows identifiers to start with a digit if they contain at least one letter. How would this impact the design of the Lexical Analyzer?IT WOULD S...
1 1 vote
3 3 answers
352
352 views
GO Classes asked Jan 16
352 views
$\text { Consider the following C code segment: }$inline int square(int s) { return s * s; } void process(int n, int a[]) { int x = 10; int y = x; // Copy of x for (int i...
2 2 votes
2 2 answers
281
281 views
GO Classes asked Jan 16
281 views
Consider the following C code segment: int a = 10, b = 20; for (int i = 0; i < n; i++) { int constant_val = a * b + 5; for (int j = 0; j < n; j++) { i...