For FIRST
FIRST(a) = Set of those terminals with which the strings derivable from a start
If a = XYZ, then FIRST(a) is computed as follows:
FIRST(a) = FIRST(XYZ) = { X } if X is terminal.
Otherwise,
FIRST(a) = FIRST(XYZ) = FIRST(X) if X does not derive to an empty string; that is, if
FIRST(X) does not contain ε.
If FIRST(X) contains ε, then
FIRST(a) = FIRST(XYZ) = FIRST(X) - { ε } U FIRST(YZ)
FIRST(YZ) is computed in an identical manner:
FIRST(YZ) = { Y } if Y is terminal.
Otherwise,
FIRST(YZ) = FIRST(Y) if Y does not derive to an empty string (i.e., if FIRST(Y) does not contain ε). If FIRST(Y)
contains ε , then
FIRST(YZ) = FIRST(Y) - { ε } U FIRST(Z)
For FOLLOW
FOLLOW(A) = Set of terminals that immediately follow A in any string occurring on the right side of productions of the
grammar
For example, if A->aBβ is a production, then FOLLOW(B) can be computed using A->aBb, as shown below:
FOLLOW(B) = FIRST(β) if FIRST(β) does not contain ε
FOLLOW(B) = FIRST(β) - { ε } U FOLLOW(A) if FIRST(β) contains ε
----------------------------------------------------------------------------------------------------------
First(E)=First(T)
First(E)=First(T)
First(T)=First(F)
First(T)=First(F)
First(F)={a,b}
First(E)=First(T)=First(F)={a,b}
Follow(E)={+,$}
Follow(T)=First(F)⋃Follow(E)={a,b,+,$}
Follow(F)={∗}⋃Follow(T)={∗,a,b,+,$}