1
$\begingroup$

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

S->ABC
A->Aa
A->aB
B->Bb
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?

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

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.

$\endgroup$

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.