[antlr-interest] missing attribute access on rule scope when testing token in action section

Terence Parr parrt at cs.usfca.edu
Sun Oct 21 17:34:08 PDT 2007


hi. $el should work.  Are you sure el isn't a rule somewhere?  Is it  
literally as in the book?  I tried every example; maybe i messed this  
up in 3.0.1?

Ter
On Oct 21, 2007, at 9:31 PM, Dave Carey wrote:

> I think I answered my own question here and it seems it is a typo  
> in the book.
> If the if clause you don't prefix el with a '$'   so it is
>
>   if( el!=null)
>
>
> On 21/10/2007, Dave Carey <dacarey at gmail.com> wrote: I have a  
> question regarding "action section" and testing for the presence of  
> optional tokens inside them
> According to the v3 Definitive Antlr Guide ( section 6.3) you can  
> do something like this:-
>
> stat: 'if' expr 'then' stat(el='else' stat)?
> {
>    if($el!=null)
>        System.out.println ("found an else");}
> |...
> ;
>
> In fact when I try this same example ( Anrlr 3.0.1)   I always get
>
> error(117): Test.g3:116:4: missing attribute access on rule scope: el
>
> You can workaround by access the token contents supplying an  
> attribute e.g. $el.text:  but this doesn't feel right and the guide  
> suggests that it should work as prescribed.
>
> Can anybody clarify?
>
> Cheers
> Dave
>
>



More information about the antlr-interest mailing list