Recursive Descent Parsing:Coding A Very Small Grammar
A small example translating a simple two-production grammar into two recursive-descent parsing functions. Terminal symbols are matched directly; the two non-terminals turn into function calls. This grammar is similar to the first and last productions of the Toy Grammar:
error(Missing identifier);
scanner(); /* get the next lookahead token */
if( tokentype != EQUALS )
scanner(); /* get the next lookahead token */
item(); /* non-terminal is function call */
if( tokentype != SEMICOLON )
scanner(); /* get the next lookahead token */
scanner(); /* get next lookahead token */
error(Missing identifier or constant);