For FIRST and FOLLOW, we keep applying rules until nothing else can be added to the FIRST and FOLLOW sets.
FIRST(α)
The set of terminals that BEGIN strings derived from α. If α is ϵ or generates ϵ, then ϵ is also in FIRST(α).f(x)=x∗e2piiξx
If X is a terminal, the FIRST(X) = {X}
If X →aα,add a to FIRST(X)
If X →ϵ,add ϵ to FIRST(X)
If a production has multiple Symbols like X →Y1,Y2,...,Yk
Add every non−ϵ in FIRST(Yi) to FIRST(X)
If Y1⇒∗ϵ,add ϵ FIRST(Y2) to FIRST(X)
Continue for each subsequent Yi, if Yi⇒∗ϵ add FIRST(Yi+1) to FIRST(X)
to FIRST(X).
If all symbols Y1,Y2,...,Yk can derive ϵ, then add ϵ
FOLLOW(α)
The set of terminals that can immediately follow A in sentential form (i.e. ).
If S is the start symbol, add $ to FOLLOW(S)
If A→αBβ,add FIRST(β)−ϵ to FOLLOW(B)
Search for A in a production body and apply rules to that production:
Add FOLLOW(A) to FOLLOW(B) if:
A→αB
A→αBβ and β⇒∗ϵ
Last updated