Took me awhile, but I finally finished reading: The Definitive Antlr Reference: Building Domain-Specific Languages (Pragmatic Programmers)
It is hard to separate reviewing ANTLR from reviewing this book, which is written by the author of ANTLR, Terence Parr. ANTLR is a fantastic tool, which really opened my eyes to the capabilities of creating DSLs to solve what otherwise would be very difficult problems. I looked up many resources on ANTLR, and by far this book is the best resource available. If you are going to try to learn to use ANTLR buy this book.
Good:
- First few chapters start out very simple and easy to understand.
- Very good examples of how to use ANTLR with real code and real programming languages.
- Excellent coverage of each feature of the tool, and why it was built that way.
- Builds on concepts of language parsing while introducing ANTLR features.
Bad:
- Gets a bit complicated near the end of the book. Some of the examples and concepts get pretty deep into complex language parsing, although there is a warning about it.
- Missing information on best practices for using ANTLR. (Would have liked to see a chapter dedicated to that subject.)
What I learned:
I had no idea that creating a DSL could be so easy. Language parsing really is not that hard. It is intimidating to think about creating a DSL, but with the right tools, it is not really very difficult at all.
I learned how to use ANTLR and got most of my questions answered about how to accomplish pretty much anything I would need to do in ANTLR.
There was a topic about using string templates that made me realize how useful it is to not hard code the code generation into the tree parsing when creating a language. By separating out the code generation into templates, it is possible to target several different languages easily.
I got a much better understanding about general language parsing and design, as well as a good understanding of Abstract Syntax Trees (ASTs), why you would use them, and how to use them effectively. I got a good understanding of why you would need a multi-pass parser for parsing a language.
This book will change the way I look at many problems. I feel pretty confident in implementing DSLs to solve the right kind of problems after reading this book.
I have implemented hand written language parsers in the past, but after reading this book, will never do that again and would highly recommend reading this book and checking out DSLs in general. It is easier than you think.