[antlr-interest] Possible bug in (not) setting TokenStartIndex and TokenStopIndex during AST rewrites
Jim Idle
jimi at temporal-wave.com
Thu Aug 7 14:47:58 PDT 2008
On Thu, 2008-08-07 at 11:15 -0700, Terence Parr wrote:
> Interesting. I think I only set the start and stop information at the
> root for rule because that is the only information I have tracked.
YEs. I usually throw the subsequent '.' xxx etc into a subrule, which
causes the subrule to set the boundaries. However, I don't usually code
this type of construct in a serial fashion like this - it makes it no
easier to handle, even if it is easier to see. So, is there a reason you
cannot do:
pe: IDENTIFIER (DOT^ IDENTIFIER)*
;
This gives a natural progress down a tree adn lets you accumulate symbol
table references as you descend it. The tokens then all keep their
locations too.
Jim
> Ter
> On Aug 6, 2008, at 11:34 AM, Sam Harwell wrote:
>
> > If you take the following rule:
> >
> > postfix_expression
> > : ( IDENTIFIER
> > -> ^(IDENTIFIER)
> > )
> > ( '.' IDENTIFIER
> > -> ^(AST_DIRECT_MEMBER $postfix_expression
> > IDENTIFIER)
> > )*
> > ;
> >
> >
> > And run it on the following input:
> >
> > a.b.c
> >
> > You get the following AST:
> >
> > AST_DIRECT_MEMBER /* has Token Start/Stop Info set */
> > - AST_DIRECT_MEMBER /* DOES NOT have Token Start/Stop Info set! */
> > -- a /* has Token Start/Stop Info set */
> > -- b /* has Token Start/Stop Info set */
> > - c /* has Token Start/Stop Info set */
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080807/49f4caeb/attachment-0001.html
More information about the antlr-interest
mailing list