[antlr-interest] Intentional?: Can't label (tokens*)

Brendon McLean antlr at twistedprotein.com
Wed Dec 5 03:45:34 PST 2007


I was wondering whether the labelling of parenthesised tokens should  
be allowed?

Currently, you can construct a grammar like this:

postincdec	:	varref op=('++' | '--')	-> (^POSTFIX_EXPR $op)

The grammar will compile to Java, but the program is invalid as the  
token ref 'op' is never assigned a value.  In this particular case,  
labelling this token expression makes sense (to a human), but I can  
see why labelling parenthesised token expressions will not always  
make sense (more than one token for example).

It would be nice if this could fail fast or if the grammar could be  
tweaked to make labelling parenthesised token expression illegal.

Regards,
Brendon.


More information about the antlr-interest mailing list