Its very easy to find FIRST in compiler design. Im finding difficult to find follow , suppose if we have one variable(say B) then we need to search the variable in the whole question .If there was a terminal or a variable after B (say Ba,BA) we can find it easily. but if we have epsilon (say Bε).How to find the follow for such values(Bε) and if there was ε in the same variable then we need to go to the next variable.then how to continue the problem. help me to find the solution for the following question.


For production of the form $A \rightarrow \alpha B \beta,\ FOLLOW(B) = FIRST(\beta)-\{\epsilon\}$.

If $\epsilon$ belong to $FIRST(\beta)$ or in case the production is of the for $A \rightarrow \alpha B$, whatever is in $FOLLOW(A)$ must be in $FOLLOW(B)$


Find $FIRST\ \&\ FOLLOW$ of all the symbols in the grammar $G = \{\{S,B,C\},\{a,b\},P,S\}$, where $S$ is the start symbol and $P$ is the set of productions given below.

\begin{align*} S \rightarrow BC\\ B \rightarrow aB\ |\ \epsilon\\ C \rightarrow bC\ |\ \epsilon\\ \end{align*}

Drop a comment in case you need a more detailed explanation. However, I encourage you to solve the exercise problem first.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.