Chapter 4: Syntax Analysis

Constructing parse table

. Table can be constructed if for every non terminal, every lookahead symbol can be handled by at most one production

. First( a ) for a string of terminals and non terminals a is

- Set of symbols that might begin the fully expanded (made of only tokens) version of a

. Follow(X) for a non terminal X is

- set of symbols that might follow the derivation of X in the input stream

The construction of the parse table is aided by two functions associated with a grammar G. These functions, FIRST and FOLLOW , allow us to fill in the entries of a predictive parsing table for G, whenever possible. If α is any string of grammar symbols, FIRST ( α ) is the set of terminals that begin the strings derived from α . If α * ε , then ε is also in FIRST( α ).

If X is a non-terminal, FOLLOW ( X ) is the set of terminals a that can appear immediately to the right of X in some sentential form, that is, the set of terminals a such that there exists a derivation of the form S * α A a ß for some α and ß . Note that there may, at some time, during the derivation, have been symbols between A and a , but if so, they derived ε and disappeared. Also, if A can be the rightmost symbol in some sentential form, then $ is in FOLLOW(A).