Line 19: | Line 19: | ||
The FOLLOW set is computed for non-terminals and indicates the set of terminal symbols that are possible after a given non-terminal. The special symbol $ is used to represent the end of phrase (end of input). | The FOLLOW set is computed for non-terminals and indicates the set of terminal symbols that are possible after a given non-terminal. The special symbol $ is used to represent the end of phrase (end of input). | ||
− | # If | + | # If X is the grammar's initial symbol then {$} ⊆ FOLLOW(X) |
− | # If A -> | + | # If A -> αXβ is a production, then FIRST(β)\{ε} ⊆ FOLLOW(X) |
− | # If A -> | + | # If A -> αX or A -> αXβ (β <amsmath>\overset{*}{\Rightarrow}</amsmath> ε), then FOLLOW(A) ⊆ FOLLOW(X) |
The algorithm should be repeated until the FOLLOW set remains unchanged. | The algorithm should be repeated until the FOLLOW set remains unchanged. |
The FIRST set for a given string or symbol can be computed as follows:
As an example, consider production X -> Y1...Yn
The FIRST set can also be computed for a string Y1...Yn much in the same way as in case 3 above.
The FOLLOW set is computed for non-terminals and indicates the set of terminal symbols that are possible after a given non-terminal. The special symbol $ is used to represent the end of phrase (end of input).
The algorithm should be repeated until the FOLLOW set remains unchanged.