Recursive Descent Parsing:Coding A Very Small Grammar
Another small example of translating a grammar into recursive-descent parsing functions. Terminal symbols are matched directly; non-terminals turn into function calls:
<> => ID = ( <> | CONST ) ;
error(Missing identifier);
scanner(); /* get the next lookahead token */
if( tokentype != EQUALS )
scanner(); /* get the next lookahead token */
scanner(); /* get next lookahead token */
expr(); /* non-terminal is a function */
if( tokentype != SEMICOLON )
scanner(); /* get the next lookahead token */
error(Missing constant);
scanner(); /* get next lookahead token */