next next up down toc toc mail

10.12.  Recursive-Descent Parsing

Recursive-descent parsing is one of the simplest parsing techniques that is used in practice. Recursive-descent parsers are also called top-down parsers, since they construct the parse tree top down (rather than bottom up).

The basic idea of recursive-descent parsing is to associate each non-terminal with a procedure. The goal of each such procedure is to read a sequence of input characters that can be generated by the corresponding non-terminal, and return a pointer to the root of the parse tree for the non-terminal. The structure of the procedure is dictated by the productions for the corresponding non-terminal.

The procedure attempts to "match" the right hand side of some production for a non-terminal.

One example: --- We want to write a program for the following CFG:

<Sum>:           <Sum> + <Product>
             |   <Sum> - <Product>
             |   <Product>
<Product>:       <Product> * <N>
             |   <Product> / <N>
             |   <N>
<N>:             ( <Sum> )
             |   number
back next up down toc toc mail

Created by unroff & hp-tools. © by Hans-Peter Bischof. All Rights Reserved (1998).

Last modified: 27/July/98 (12:14)