The GATE Grind

GATE 2019 CS – Question 29

Compiler Design · Parsing and Syntax Analysis · 1 mark · Numerical answer

Consider the grammar given below:

S → Aa

A → BD

B → b | ε

D → d | ε

Let a, b, d, and \$ be indexed as follows:

abd\$
3210

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.