Java News Brief (JNB): ANTLR 3.0
This month's OCI Java News Brief (JNB) article is out. In this article, Mark Volkmann continues his effort in getting you to be proficient with ANTLR 3.0. (Actually, you need ANTLR 3.1b1 to compile the grammars in the article.)
Mark Volkmann:ANTLR 3.0
by
R. Mark Volkmann, Partner/Software Engineer
Object Computing, Inc. (OCI)Table of Contents
- Part I - Overview
- Part II - Jumping In
- Part III - Lexers
- Part IV - Parsers
- Part V - Tree Parsers
- Part VI - ANTLRWorks
- Part VII - Putting It All Together
- Part VIII - Wrap Up
As always with JNB articles, this one is intended for you to follow along. So download ANTLR 3.1b1, fire up your bash and vim, and learn some language recognition tricks.
On a related note, Martin Fowler recently blogged about a phenomenon he calls Parser Fear:
Martin Fowler: I talk quite a bit with people about DomainSpecificLanguages these days and a common reaction I get to external DSLs is that it's hard to write a parser.
He went on to say that creating an external DSL with ANTLR is just as fast as using XML files, where supposedly you get the parser for free.
I quite don't agree with Martin
Coincidentally, I wrote about Martin's article "ParserFear." IMHO, creating an external DSL is just the beginning. There are other factors that need to be considered too.
For more details, please read Fear of parsers? Not really....
Best regards,
-Alex
I quite don't agree with Martin
Alex, you raise some very relevant questions.
I have a feeling that the phrase DSL (domain specific languages) has been "talked up" in the last couple of years as a result of the Ruby hype. From my perspective, it would seem that the Ruby folks made the phrase popular, and the ANTLR folks rode the waves.
Of course DSL, as we are discussing them now, is nothing new. They used to be called little languages or minilanguages, although the current DSL definition seems to include data formats as well.
I agree that DSLs should be used with caution. We should ask all the questions that you are asking in your piece before committing on creating a DSL.
In addition to XML, other alternatives to a brand new DSL also include using a ready made small language intended for embedding, and to use a well designed API in the hosting language.
However, the world is big. There will always be situations where a small little language will do a lot of good. And in those situations, an external DSL will be appropriate.
I think Martin Fowler's point is not that ANTLR based DSLs are better than XML based DSLs. If anything, his claim can be summarized as "an ANTLR based DSL is roughly equivalent to an XML schema based DSL." He's lamenting the fear of ANTLR based DSL that he senses existed, not out of knowledge of ANTLR, but out of ignorance.
Like other things that we know and love such as object-orientation and test driven development, ANLTR based DSL is another tool on our tool belt. When the moment is right™, it may prove magical.