Jump to ratings and reviews
Rate this book

The Definitive ANTLR 4 Reference

Rate this book
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)

328 pages, Paperback

First published December 2, 2012

Loading interface...
Loading interface...

About the author

Terence Parr

12 books23 followers

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
57 (50%)
4 stars
41 (36%)
3 stars
13 (11%)
2 stars
0 (0%)
1 star
1 (<1%)
Displaying 1 - 7 of 7 reviews
Profile Image for Kang.
4 reviews1 follower
July 5, 2021
Could be better if less compared to ANTLR3. I'm looking for how to do it with ANTLR4, but in the book it could help to elaborate in other/older ways.
Profile Image for Matthew Royal.
234 reviews14 followers
December 19, 2021
What an emotional rollercoaster!

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.
Profile Image for James Thomas.
12 reviews
March 27, 2022
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.
3 reviews
September 19, 2018
In depth look into the ANTLR 4 language, a parser generator with powerfull Adaptive LL (*) (Allstar) dynamic analysis.
7 reviews1 follower
May 23, 2016
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.
Profile Image for Oleksandr.
28 reviews9 followers
January 17, 2017
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.
Displaying 1 - 7 of 7 reviews

Can't find what you're looking for?

Get help and learn more about the design.