[antlr-interest] How much use is ANTLR for manipulating ASTs?

Andy Tripp atripp at jazillian.com
Fri Jun 17 17:49:57 PDT 2005


>
>
>I'm using ANTLR to process an AST (currently, just semantic checking for 
>a simple C-like language, with scanning and tree construction in 
>lex/yacc). Writing this code has got me thinking about what exactly 
>ANTLR is buying me.
>
>My grammar basically calls various methods at the nodes of the tree, 
>storing results in the node, and passing information up the tree. However:
>
>1) The tree structure itself is known to be correct because I wrote it 
>myself from the front-end code. If the tree structure is known to be 
>correct, is there any point in using ANTLR? I could just as easily (more 
>easily, in fact) traverse the tree manually, and the required checking 
>code is too complex to put in the grammar file.
>
>2) I don't actually need to know what the tree structure is to do 
>semantic checking. Having to specify the structure in ANTLR syntax then 
>just becomes another potential failure point.
>
>At some point I also need to do some simple transformations on the tree. 
>Ok, I could do this with ANTLR, but it'll also be pretty simple just to 
>do manual in-situ transformations of the tree, rather than generating an 
>entire new tree.
>
>Any thoughts?
>
>Paul
>

See Terence's "Translators should use Tree Grammars" article:
http://www.antlr.org/article/1100569809276/use.tree.grammars.tml
for all the reasons why using ANTLR to walk your AST is the best thing 
since sliced bread.

See my lttle thing titled "The Problem with Tree Walkers":
http://jazillian.com/antlr/trees.html for my reasons for prefering to 
just walk ASTs by hand,
rather than using ANTLR treewalkers.

See a long thread titled "Translators should use tree walkers" back in 
November...
http://www.antlr.org/pipermail/antlr-interest/2004-November/thread.html
where I take a brutal beating for refusing to see why ANTLR treewalkers 
are better
than walking an AST "by hand".

After all that, you know my opinion: if you've already got an AST, just 
write a little code
to walk it. Embedding your actions in an ANTLR treewalker won't buy you 
anything, IMO.

Andy


More information about the antlr-interest mailing list