John Roberts
John Roberts

Reputation: 5986

Grammar Follow Set Explanation

I'm looking at the following simple grammar and its accompanying table:

S-> aSbT | epsilon
T-> bFaF | epsilon
F-> epsilon

nonterminal first set   follow set  
S           a           b                                      
T           b           b
F           ∅          a b  

Could someone please explain why b, but not a, is in the follow set of T?

Upvotes: 0

Views: 1472

Answers (1)

niculare
niculare

Reputation: 3687

Take a look here for a good explanation of how first and follow sets are computed.

The third rule for Follow sets applies when you compute Follow(T) (because T is appears only in the first production and nothing follows after it). Then you will put everything from Follow(S) in Follow(T).

Follow(S) = {b}, then Follow(T) = {b}.

I think in Follow(S) should also be $ (or epsilon) if S is the starting symbol of your grammar.

Upvotes: 3

Related Questions