Implementing Parsers
The ANTLR tool generates recursive-descent parsers from grammar rules such as assign that we just saw. Recursive-descent parsers are really just a collection of recursive methods, one per rule. The descent term refers to the fact that parsing begins at the root of a parse tree and proceeds toward the leaves (tokens). The rule we invoke first, the start symbol, becomes the root of the parse tree. That would mean calling method stat for the parse tree in the previous section. A more general term for this kind of parsing is top-down parsing; recursive-descent parsers are just one kind of top-down parser implementation.
To get an idea of what recursive-descent parsers look like, here’s the (slightly cleaned up) method that ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access