I am trying to calculate the First and Follow of the following grammar

B-> epsilon
C-> Cc
C-> Epsilon

I have calculated the firsts and it is all good

Follow(A) = {a,b,c,$}

What is confusing me is the follow of B, I get Follow(B) = Follow(A) But on the other hand, I have a solution for the grammar that states that the follow(B) = {b,c,$}

So which one is the right one?

  • $\begingroup$ Why do you think that $Follow(A)$ should be the same as $Follow(B)$? $\endgroup$ – Rick Decker Jul 13 '19 at 19:38
  • $\begingroup$ According to a rule that says * For any production rule A → αB, Follow(B) = Follow(A) $\endgroup$ – Athl1n3 Jul 15 '19 at 5:53

It is evident that $B$ can be followed by $a$ — in other words, that $a\in \text{FOLLOW}(B)$ — as shown by the partial derivation

$$\begin{align}S&\to A B C&(S\to ABC)\\ &\to AaBC &(A\to Aa)\\&\to aBaBC&(A\to aB) \\ \end{align}$$

So the answer provided does not correspond to this grammar.


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.