# Computing FIRST and FOLLOW

Given the following grammar with terminals $$VT=\{[,],a,b,c,+,-\}:$$

$$S \rightarrow [SX]|a$$

$$X \rightarrow +SY|Yb|\epsilon$$

$$Y \rightarrow -SXc|\epsilon$$

This should be the FIRST function:

$$first(S) = \{[,a\}$$

$$first(X) = \{\epsilon,+,-,b\}$$

$$first(Y) = \{\epsilon,-\}$$

What would the FOLLOW function be?

• There is an algorithm for computing the FOLLOW function. All you have to do is run it, manually or on a computer. It is even likely that people have already programmed this, and you can use their code. – Yuval Filmus May 16 '20 at 10:43

$$follow(S) = \{\,+,-,b,],c\}$$
$$follow(X) = \{],c\}$$
$$follow(Y) = \{b,],c\}$$