Contents    Page-10    Prev    Next    Page+10    Index   

Recursive Descent

Recursive Descent is a method of writing a top-down parsing program in which a grammar rule is written as a function.

Given a grammar rule:


   S -> NP VP
we simply make the left-hand-side nonterminal be the name of the function, and write a series of function calls for the right-hand side.

   (defn s []
     (and (np)
          (vp)) )

There could be an infinite loop if there is left recursion, i.e. a rule of the form:


   A -> A ...