[antlr-interest] Who calls CommonTree.setTokenStartIndex ?

Jim Idle jimi at temporal-wave.com
Tue Sep 30 09:09:29 PDT 2008


On Tue, 2008-09-30 at 05:15 -0600, kevin_mitchell at agilent.com wrote:
> I’m using Antlr 3.1 with the Java backend, and generating Antlr-style
> abstract syntax trees.  When I look at these trees I find that
> getTokenStartIndex (and StopIndex) are always set to -1.  I was
> expecting either the parser to emit calls to setTokenStartIndex, or
> some code in addChild to call this method whenever a new child was
> added.  But the parser doesn’t seem to call this method, and adding a
> child doesn’t seem to update the value either.  So where does the code
> to set the start index of a compound tree get called?  Is there some
> post-processing method I should be calling to set this, or some flag
> to tell the parser to generate such calls?


It should be set up, but if you embed imaginary tokens in rewrites, then
these can end up being just -1. There are no bugs that I know of
concerned with this and I use it very heavily in a lot of Java parsers.

Are you doing:

->^(IMAGINARY1 rule1 rule2 ^(IMAGINARY2 rule3))


In this case IMAGINARY2 will not have boundaries set (what should they
be really?) and you need to move the AST production in to the sub rule,
where on rule exit the postProcessing at the end of the rule will set
the ending and the entry to the rule will set the start.

Or perhaps you are referencing the trees in some unorthodox way?

Jim


> 
>  
> 
> Thanks,
> 
>  
> 
> Kevin
> 
> 
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080930/ed2d1504/attachment.html 


More information about the antlr-interest mailing list