Contents    Page-10    Prev    Next    Page+10    Index   

Recursive Descent Parser

A parser for some context-free languages can be written using the technique of recursive descent. The basic idea is to write a procedure to parse each kind of statement or expression in the grammar. When such procedures are written in a recursive language, they can call each other as needed.


if expression then statement else statement

Recursive descent works well for a well-structured language such as Pascal. In Pascal, each statement other than assignment statements begins with a unique reserved word; thus, it is easy for a ``big switch'' program to determine which statement parser to call.

It may be necessary to restructure a grammar to avoid left recursion, which can cause a recursive descent parser to go into a loop.

Operator precedence can be used for arithmetic expressions.