[antlr-interest] [C Target] Bug in AST walking , implementing control flow

Jim Idle jimi at temporal-wave.com
Tue Oct 27 08:18:40 PDT 2009



From: Mohamed Yousef [mailto:harrrrpo at gmail.com] 
Sent: Tuesday, October 27, 2009 7:19 AM
To: Jim Idle
Subject: Re: [antlr-interest] [C Target] Bug in AST walking , implementing control flow



2009/10/27 Jim Idle <jimi at temporal-wave.com>

It probably is a bug I am afraid. 3.2.1 will be a 'catch up' release to ensure that everything works in C. You can make calls to LT() directly and so on though.

so i could for now - till 3.2.1 - use something like


    :   ^('if' c=expr s=. e=.)




You would not have the s=. and e=., just code to consume what you need.

//do whatever with return values or custom nodes in e&s
will this work even if s had children (e will be next 'stat' not just a certain child of s ) ?

For index and related properties you should use the method calls rather than the fields directly, but if you know you will never override the structure types then you only have to worry if I change the names of the fields. This is not likely, but I don't guarantee not to do it.

what method do you mean ? , i couldn't find any methods in pANTLR3_BASE_TREE that returns the index of the tree root


You probably need:




Nodes are valid between tree walks and rewrites so long as you do not free the node streams until you are completely done. You can dup a node outside the factory and then it will persist, but you need to free the memory.

the syntax i use for carrying out 3 consecutive walks is something like  

// filtered initial walk , on certain portions of tree
treePsr1    = yatgWalkerNew(nodes);

// walk 2 based on indices from 1
treePsr2    = yatgWalkerNew(nodes);

// walk 3 by the same walker of 2 , utilizing indices from it walk 2 & 1
treePsr2    = yatgWalkerNew(nodes);

so ,  indices across these walks should be valid ?



Yes, but I suggest that you don't use the nodes etc, create your own 'class'/structure and populate it from the information in the node. You will probably need to reset the node stream etc too.



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20091027/593458c3/attachment.html 

More information about the antlr-interest mailing list