Next: A Parser for Expressions
Up: No Title
Previous: Top-Down Parsing
To derive a parser from a context-free grammar written in EBNF style:
- Introduce one function void A() for each non-terminal A
- The task of A() is to recognize sub-sentences derived from
A, or issue an error if no A was found.
- Translate all regular expressions on the right-hand-side of
productions as before, but
- every occurrence of a non-terminal B maps to B()
- Recursion in the grammar translates naturally to recursion
in the parser.
- This technique of writing parsers is called parsing by
recursive descent or predictive parsing .