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

Mohamed Yousef harrrrpo at gmail.com
Tue Oct 27 08:12:52 PDT 2009


This was firstly sent to jim only by accident ,, sorry

>  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

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

pANTLR3_BASE_TREE  s=(pANTLR3_BASE_TREE)LT(1);
pANTLR3_BASE_TREE  e=(pANTLR3_BASE_TREE)LT(1);
//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

> 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);
treePsr1->program(treePsr1);

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

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

so ,  indices across these walks should be valid ?


Thanks,
Mohamed Yousef
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20091027/a90d3fe7/attachment.html 


More information about the antlr-interest mailing list