FIRST FOLLOW (Top-Down) Parsing
Last updated
Last updated
For FIRST and FOLLOW, we keep applying rules until nothing else can be added to the FIRST and FOLLOW sets.
The set of terminals that BEGIN strings derived from . If is or generates , then is also in .
If X is a terminal, the FIRST(X) = {X}
If X
If X
If a production has multiple Symbols like X
Add every
If
Continue for each subsequent , if
to FIRST(X).
If all symbols can derive , then add
The set of terminals that can immediately follow A in sentential form (i.e. ).
If S is the start symbol, add $ to FOLLOW(S)
Search for A in a production body and apply rules to that production:
Add FOLLOW(A) to FOLLOW(B) if:
If