Deriving Grammars from Language Samples
Writing a grammar is a lot like writing software except that we work with rules instead of functions or procedures. (Remember that ANTLR generates a function for each rule in your grammar.) But, before focusing on the rule innards, itâs worth discussing the overall anatomy of a grammar and how to form an initial grammar skeleton. Thatâs what weâll do in this section because itâs an important first step in any language project. If youâre itching to build and execute your first parser, you can revisit Chapter 4, âA Quick Tourâ or jump to the first example in the next chapter: âParsing Comma-Separated Valuesâ. Feel free to pop back and forth to the examples in the next chapter as we learn ...
Get The Definitive ANTLR 4 Reference, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.