[antlr-interest] Use of index attribute in tree gramar

Gavin Lambert antlr at mirality.co.nz
Mon Apr 28 01:38:09 PDT 2008


At 10:12 28/04/2008, Bernardo Elayda wrote:
>                 { $statement::plus.add( $p.token.index); }
[...]
>When the above code is compiled with javac , javac complains that 
>index can't be found.  Technically, that's true since 'index' is 
>protected in the CommonToken class. The workaround to this 
>problem is to use $p.token.getTokenIndex().  Is that a 
>feature?  To be consistant with other places I've used token 
>attributes, I expected $p.token.index to work.

It's a known quirk, at least.  Basically the attribute replacement 
only works to one level at the moment.  It's not smart enough to 
notice that $p.token returns a token and thus it should try the 
token attribute replacements -- it just assumes you're trying to 
invoke some arbitrary target-language code (as in 
$foo.text.subString(...)).



More information about the antlr-interest mailing list