[antlr-interest] ANTLR 3.0ea3 released

Andy Tripp atripp at jazillian.com
Fri Jun 24 13:47:27 PDT 2005


>
>
>On Jun 23, 2005, at 12:18 PM, Gerald B. Rosenberg wrote:
>
>> ANTLR 2.7.5/2.7.6
>>
>> One thing that I continue to have problems with is the need to walk  
>> up trees.  Cannot seem to find a getParent() method or a working  
>> example of how (best) to add this functionality to an ASTNode  
>> override?  Without an existing getParent, I cannot see a clean way  
>> to provide backlinks in newly created ASTNodes overrides.  Have I  
>> missed something?
>

I wrote my own FancyAST class which extends CommonAST and provides 
getParent()
(and a few other goodies). It's pretty simple, just overriding 
addChild(), setFirstSibling() and
setNextSibling(). You can contact me directly if you want it. Maybe I'll 
try to add it to
the official ANTLR (with Ter's permission) or in the File Sharing area.

>One way to handle this (at least I've tried it years ago) is to call  
>a method to link everything up doubly *after* the tree has been  
>built.  I found that the integrity/validity of double-linked trees is  
>very complicated to keep together. :(
>  
>
Mine's been so maintenance free, I forgot that BaseAST/CommonAST didn't 
have this built-in
until I saw this post :)

>I also found that the need to "look up" is the same as needing to  
>obtain context information, which usually can be provided via the  
>grammar and a few variables.
>  
>
I had lots of cases where I needed to search up an AST where keeping 
context info would have
been messy:
"Is the current node inside a 'for loop'? - search up for ASTs of a 
given type
"Get me all the other references  of this variable" - search up the tree 
for the declaration,
    then back down for references
"Find all other variables that are ever assigned a expression/value 
involving this variable"
...and so on...

>> Also, are the auto-trees in 3.0 doubly linked?
>
I assume it will be something like today, with several levels to choose 
from:
BaseAST for just about everybody,
subclass CommonAST for most people,
maybe subclass FancyAST for those who want getParent(),
your own subclass.

>Ter
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20050624/1dd88598/attachment.html


More information about the antlr-interest mailing list