Programmers run into parsing problems all the time. Whether it's a data format like JSON, a network protocol like SMTP, a server configuration file for Apache, a PostScript/PDF file, or a simple spreadsheet macro language--ANTLR v4 and this book will demystify the process. ANTLR v4 has been rewritten from scratch to make it easier than ever to build parsers and the language applications built on top. This completely rewritten new edition of the bestselling Definitive ANTLR Reference shows you how to take advantage of these new features.
Build your own languages with ANTLR v4, using ANTLR's new advanced parsing technology. In this book, you'll learn how ANTLR automatically builds a data structure representing the input (parse tree) and generates code that can walk the tree (visitor). You can use that combination to implement data readers, language interpreters, and translators.
You'll start by learning how to identify grammar patterns in language reference manuals and then slowly start building increasingly complex grammars. Next, you'll build applications based upon those grammars by walking the automatically generated parse trees. Then you'll tackle some nasty language problems by parsing files containing more than one language (such as XML, Java, and Javadoc). You'll also see how to take absolute control over parsing by embedding Java actions into the grammar.
You'll learn directly from well-known parsing expert Terence Parr, the ANTLR creator and project lead. You'll master ANTLR grammar construction and learn how to build language tools using the built-in parse tree visitor mechanism. The book teaches using real-world examples and shows you how to use ANTLR to build such things as a data file reader, a JSON to XML translator, an R parser, and a Java class->interface extractor. This book is your ticket to becoming a parsing guru!
What You Need:
ANTLR 4.0 and above. Java development tools. Ant build system optional (needed for building ANTLR from source)
I went from being a true believer in a language-agnostic event-based parsing in order to keep the code out of the grammar to maximize reuse... to a true believer in the impossibility of keeping code out of the grammar, since it inevitably needs to ask for higher level context from some other module or have embedded predicates in order to parse some things correctly and efficiently... within a few week span.
It feels like a fairly good solution to the leaky abstraction of separate lexer, parser, and app components, but there are a ton of unexplained ramifications to this stuff, and to rewriting Left-recursive phrases. It leaves me with a pseudo-religious dread, as if I discovered an ancient stone room behind a wall while remodeling a basement.
Most of the book explores trivial examples not actually compliant with any language spec. I wish we could have taken a deep dive into a few real language specs to quantify the difference between an easy start and a complete job. Additional use cases would be handy; most of the run-of-the-mill cases would be handled by some grepping.
Also missing was a discussion on the time and space complexity of different options and language constructs. How much longer will my parser take to run using option A vs option B?
Overall, I feel like I know very little about the depth of the projects I want to create with ANTLR 4. Just enough to be dangerous.
Good book, especially for a technical reference manual. Terence did a good job keeping things interesting without being needlessly dry--and he still managed to always be informative. Useful for anyone who wants to use ANTLR or even people with a decent amount of experience with it, such as myself.
Helped me out a lot during my dissertation. Only thing that agitates me a little bit is sometimes he refers to material in another reference book he's wrote in insufficient detail.
But overall very clear. Unlike some other reference books I've had to use there wasn't any point where I was having to spend a very long time wrapping my head around the content, or concepts that were poorly explained that I would only realise later on I really didn't actually understand, etc.
ANTLR is a very powerful parsing tool. This book is a complete guide for Language applications developers. Book contains understandable explanations and common language development problems troubleshooting. Strongly recommend.