Reputation: 7043
Grammar:
E -> TE’
E’ -> +TE’ | ε
T -> FΤ’
Τ’ -> *FΤ’ | ε
F -> (E)| id
Functions:
1. FIRST(F) = FIRST(T) = FIRST(E) = {(, id}
2. FIRST(E’) = {+, ε}
3. FIRST(T’) = {*, ε}
4. FOLLOW(E) = FOLLOW(E’) = {), $}
5. FOLLOW(T) = FOLLOW(T’) = {+, ), $}
6. FOLLOW(F) = {*, +, ), $}
Here is the grammar and the functions from my lectures...Can someone explain me how FOLLOW works??? I understood how FIRST work but FOLLOW is very difficult to understand...
Upvotes: 1
Views: 1943
Reputation: 25
here FOLLOW(F) is find by this way:
T-->FT' means FOLLOW(T) IS subset of FOLLOW(F)
T'-->*FT' means FIRST(T') contain epsilon then except epsilon and add other values to set.
Upvotes: 1
Reputation: 2712
Have a look at Wikipedia's FIRST_and_FOLLOW_sets .
You look for any references of E
.
Here (E)
and union all following terminals and the FIRST-set of the following nonterminals.
Here only the following terminal )
.
F
is referenced by FT
, *FT'
. So FOLLOW(F)
is the union of FIRST(T) = {(, id}*
and FIRST(T') = {*, ε}
.
Finally, FOLLOW(F) = {(, id, *, ε}
.
Upvotes: 3