[antlr-interest] Root note of tree doesn't have the index attribute?

Bernardo Elayda belayda at gmail.com
Sun Mar 23 18:12:58 PDT 2008


To answer my own question:

>myrule : ^(a='=' b=NODE c=NODE) -> mytemplate(mya={$a.index},
>myb={$b.text},myc={$c.text}) ;
>
>When I compile the above rule and compile the resulting java
>file, I get an error that says it cannot find the method
>getTokenIndex for 'a'.  That doesn't make sense to me.  Isn't the
>root node labeled as 'a' above just a token?

I need to do this instead:

myrule : ^(a='=' b=NODE c=NODE) ->
mytemplate(mya={$a.token.getTokenIndex()},myb={$b.text},myc={$c.text}) ;
I also tried : $a.token.index, but that didn't work.

-be




On Sun, Mar 23, 2008 at 5:12 PM, Gavin Lambert <antlr at mirality.co.nz> wrote:

> At 12:45 24/03/2008, Bernardo Elayda wrote:
> >myrule : ^(a='=' b=NODE c=NODE) -> mytemplate(mya={$a.index},
> >myb={$b.text},myc={$c.text}) ;
> >
> >When I compile the above rule and compile the resulting java
> >file, I get an error that says it cannot find the method
> >getTokenIndex for 'a'.  That doesn't make sense to me.  Isn't the
> >root node labeled as 'a' above just a token?  If I change the
> >above template to use $a.text, that works.
>
> Each element within a tree parser is a tree node, which *contains*
> a token (and a collection of child nodes), but it's not a token
> itself.
>
> There should be a way to get to the token itself, but I haven't
> really used tree grammars before myself so I can't tell you what
> it would be offhand.  If nobody else pipes up then your best bet
> would be to have a look at the generated code, particularly at the
> definition of the class it uses for the node.
>
> (Although I do seem to recall also hearing that literal strings
> didn't work in tree grammars.  But that was a long long time ago
> so maybe that's been sorted out.)
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080323/af35e3d6/attachment.html 


More information about the antlr-interest mailing list