[antlr-interest] postmortem

Loring Craymer lgcraymer at yahoo.com
Thu Mar 13 20:31:43 PDT 2008


Andy--

As others have pointed out, take a look at
http://www.antlr.org/wiki/pages/viewpage.action?pageId=1760
and also:
http://www.antlr.org/article/parse.trees/index.tml

Visitors ("just have some ("by hand") code that walks the AST") have their place.  Not all language translation passes need heavy-duty language processing machinery.  Some do, though, and most benefit.  Pretty printing is one of those that benefits:  take a look at jalopy (http://jalopy.sourceforge.net/) to see what ANTLR can do with Java.

--Loring

----- Original Message ----
From: Andy Tripp <antlr at jazillian.com>
To: Loring Craymer <lgcraymer at yahoo.com>
Cc: Thomas Brandon <tbrandonau at gmail.com>; antlr-interest <antlr-interest at antlr.org>
Sent: Thursday, March 13, 2008 1:29:30 PM
Subject: Re: [antlr-interest] postmortem

Loring Craymer wrote:

> 
> For practical translation, though, parse trees are not particularly 
> helpful--they capture preconceptions about the input language and 
> contribute little to the analysis phase(s) of a translator.  Failure to 
> design a tree structure that helps in performing analysis seems 
> invariably to lead to "action-packed" grammars that become less and less 
> maintainable as they are asked to do more and more.  Eventually, you get 
> to the point where the grammar itself is virtually unmaintainable 
> because it is hidden by a vast amount of target language code.

Yea, I'm sure that would become a huge mess very quickly.

But suppose you design things so that the parser just parses (producing an AST) and does not
try to do any translation. And similarly, suppose you don't try to define
a treewalker to do translation, because that's going to have this
"huge amounts of code buried within a grammar" problem anyway.

Instead, you just have some ("by hand") code that walks the AST.
Wouldn't that code be straightforward, simply ignoring any nodes that it
doesn't need to process? For example, look at my thing that just
walks a Java AST "by hand" and pretty prints it:
http://www.jazillian.com/articles/JavaEmitter.java
Seems like this wouldn't be much more complicated to deal with a parse tree
than it is now dealing with an AST.






      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 



More information about the antlr-interest mailing list