[antlr-interest] Intentional?: Can't label (tokens*)
Johannes Luber
JALuber at gmx.de
Wed Dec 5 04:45:56 PST 2007
-------- Original-Nachricht --------
> Datum: Wed, 5 Dec 2007 23:09:37 +1100
> Von: "Steve Bennett" <stevagewp at gmail.com>
> An: "Brendon McLean" <antlr at twistedprotein.com>
> CC: antlr-interest at antlr.org
> Betreff: Re: [antlr-interest] Intentional?: Can\'t label (tokens*)
> On 12/5/07, Brendon McLean <antlr at twistedprotein.com> wrote:
> > 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)
>
> Looks like what I did wrong in my previous post. How should one write
> this?
>
> postincdec : varref (op='++' | op='--') -> ^(POSTFIX_EXPR $op)
>
> (I assume you meant ^ before the other parentheses).
postincdec : varref op=('++' | '--') -> ^(POSTFIX_EXPR $op)
is correct, but an ANTLR bug prevents this usage. Just create an op-subrule as workaround.
>
> Incidentally, I find it odd that it's illegal to parenthesise the AST
> structure:
>
> ... -> (foo);
>
> seems to be illegal. It's not particularly useful, but you expect it
> to be ignored.
It complains because usually people forget the '^' in front of the parentheses.
Johannes
--
Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten
Browser-Versionen downloaden: http://www.gmx.net/de/go/browser
More information about the antlr-interest
mailing list