Professional Documents
Culture Documents
First and Follow sets are needed so that parser can properly apply the needed
production rule at the correct place.
FIRST Function
First(α) is a set of terminal symbol that begins in string derived from α
Example: Aabc/def/ghi/cBA
Then First(A)={a,d,g,c}
First(X)={ ε}
First(Y1)={a,c, ε }
Calculating First(X)
If ε ∉ First(Y1) then First(X)= First(Y1)
Follow(B)=Follow(A)
Note:
={b}∪{c}∪{d}
={bcd}
FIRST(B)={b, ε }
ABC
bCD/CD
A-DaAb
DBb
B-c
Follow(A)={b,$}
Follow(D)={a}
Follow(B)={b}
A-Da
DB
Bc
Follow(A)={$}
Follow(D)={a}
Follow(B)=Follow(D)={a}
A-DaAb
Cd
Follow(A)={$,b}
Follow(D)={a}
Follow(B)={b}
Follow(C)=First(B)={c}