GATE 2019 CS – Question 29
Consider the grammar given below:
S → Aa
A → BD
B → b | ε
D → d | ε
Let a, b, d, and \$ be indexed as follows:
| a | b | d | \$ |
|---|---|---|---|
| 3 | 2 | 1 | 0 |
Compute the FOLLOW set of the non-terminal B and write the index values for the symbols in the FOLLOW set in the descending order. (For example, if the FOLLOW set is {a, b, d, \$}, then the answer should be 3210.)
Answer: ________.
Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: 31
Explanation
$\text{FOLLOW}(B)=\text{FIRST}(D)\cup\text{FOLLOW}(A)$, because $D$ can derive $\varepsilon$. $\text{FIRST}(D)=\{d\}$ and $\text{FOLLOW}(A)=\{a\}$. So $\text{FOLLOW}(B)=\{a,d\}$, with indices 3 and 1, giving 31.