Next | Higher-Order Parsing | 11 |
This is the method used by Parse::RecDescent too
Idea: each grammar rule becomes a function
The job of the function expression is to parse an expression
If it succeeds, it returns a data structure representing the expression
If not, it returns undef
If you have a rule like this:
expression → "(" expression ")" | term ("+" expression | nothing)
You have functions called expression and term
expression looks to see if the next token is (
If so, it calls itself recursively, and then looks for the )
Otherwise it calls term to look for a term
If term fails, expression does too
Otherwise it looks to see if there's a + sign and another expression
Next | Copyright © 2007 M. J. Dominus |