[antlr-interest] How to force a TreeWalker to match exactly?

Andy Tripp antlr at jazillian.com
Thu Mar 23 06:47:05 PST 2006


> 
>This can be very annoying! If there is an inconsistency between the Parser and the TreeWalker grammar, there is very little chance to detect it. Instead, unknown nodes are sometimes silently ignored. Is there a way to turn off this feature? How do you ensure that the TreeWalker grammars really correspond to the AST generated by the parser?
>  
>
I discuss this in several places in my article about why I don't like 
TreeWalkers.
http://www.jazillian.com/articles/treewalkers.html
For example, I say:
------------
..do we want our AST-transformation phase to be tied tightly (to "look 
like", really) the AST structure of the parser? In my opinion, the 
answer is "no". By not having the AST-transformer tightly bound to the 
AST structure, it's easier to maintain, enhance, and modify to work with 
other languages and AST structures.
*
*

Glancing at the "by-hand" code gives little clue as to the input AST 
structure, and I think that's a good thing, because
 that way, it is less dependent on the input AST structure. For example, 
all the node types that are binary operators are lumped together because 
they are all processed in the same way, and we don't care where they may 
appear in the AST.

----------
So I think your life might be easier if you don't even attempt to 
explicitly validate AST structure in your treewalker.




More information about the antlr-interest mailing list