[antlr-interest] A postmortem of my use of antler

siemsen at ucar.edu siemsen at ucar.edu
Wed Mar 12 12:06:28 PDT 2008


On Mar 11, 2008, at 4:06 PM, Andy Tripp wrote:

> siemsen at ucar.edu wrote:
>>
>> Wow, I think this question is backwards.  I learned ANTLR from the  
>> book as I wrote
>> a nontrivial translator.
> Do you have a pointer to more info? We may just have different  
> definitions for "non-trivial".

I'm beginning to realize that just because my grammar is ~900 lines,  
it's still a trivial translator - as Loring wrote, "A source to B  
source for languages in which language B can straightforwardly  
express the paradigms of language A".  I've now spent some time  
reading more about ASTs, and I think I now understand why they are  
needed.  I could get by without one in my current project, but  
perhaps it will improve things to have more phases, each of which  
encapsulates different processing.

>> I took a compiler class at the university many years ago.  We used  
>> yacc/lex and the
>> famous Aho/Ullman dragon book.  I agree with a previous post,  
>> lexing/parsing is
>> *hard* to do well.  Now I'm done with the theory, and I just want  
>> to get the job done.
>> IMHO, ANTLR is the next generation of yacc/lex, and is a great  
>> leap forward.  Many
>> thanks to Terence for encapsulating the concepts in code so well.   
>> Again, I'm done with
>> the theory, so if Terence were to proclaimed "ASTs are good, you  
>> should always use
>> them" I wouldn't argue, I'd just do it.
> I think one should take arguments on their merits and use your own  
> experience.
> Terence is probably the best in the world at what he does. But the  
> best car designer or mechanic
> in the world is not necessarily the best driver. Most rocket  
> scientists would
> not be the best astronauts.
>
> In fact, I'd argue that being really, really smart actually *hurts*  
> one's ability to empathize
> with the average users.

I'm an average ANTLR user, and I don't want to become an expert.  I  
want to be told what I *should* do, not everything I *can* do.   
Having a choice to use an AST is only helpful if I understand the  
choice. It seems to be a somewhat subtle.  Loring wrote "an AST is  
helpful and aids maintainability".  I'm curious enough to try it and  
see.

ANTLR has a significant learning curve, and I'm lazy, so I hoped to  
dodge the AST piece of it.  I got away with it because my translator  
doesn't need one.  In the larger picture, it seems ASTs are a good  
thing.  I want a translator strategy that I can come back and use in  
a year or two, when I've forgotten some of what I've learned about  
ANTLR.  At that future time, I'll likely use my existing grammar as a  
model and start hacking.  I won't want to re-learn the big concepts  
well enough to choose whether to use an AST or not.  Also, I'm tired  
of reading the book and this mailing list with a mental filter that  
tries to dodge the AST parts.  So I'll add an AST to my current  
(first ever) ANTLR translator whether it needs it or not, and ASTs  
will become a standard part of my future translators.  Perhaps ASTs  
are meant to be a part of all ANTLR translators, and I just didn't  
follow the book as intended.

A little voice in my head is saying "Huh?  Another source file to  
maintain?  And it has to be kept in sync with the parser grammar?".   
Enough!  I'll try it!

Thanks very much for all who contributed to this thread.  I learned  
something.

-- Pete



More information about the antlr-interest mailing list