a1204773
a1204773

Reputation: 7043

How Follow function works? (compiler)

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

Answers (2)

SAGGU
SAGGU

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

Vertex
Vertex

Reputation: 2712

Have a look at Wikipedia's FIRST_and_FOLLOW_sets .

FOLLOW(E):

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 ).

FOLLOW(F):

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

Related Questions