[antlr-interest] Difference between * and +
Johannes Luber
jaluber at gmx.de
Fri Oct 17 06:45:46 PDT 2008
Axelle Ziegler schrieb:
> Hi,
> I'm feeling I'm missing something pretty fundamental here, if someone
> can enlight me. I've been switching from antlr 3.0.1 to antlr 3.1 and
> got some weird errors with my variable names rule. In the end, I've
> narrowed it down to this small example, using antlrWorks :
>
> grammar Test;
>
> atoms :
> VARNAME;
>
> private MIN :('a'..'z');
> private MAJ :('A'..'Z');
> private CHAR :('_')|('.')|(':')|('!')|('?')|('\'');
>
> VARNAME : MIN(MAJ|MIN|CHAR|'0'..'9')*;
There are two errors. The first is that "private" isn't currently used
(though it is allowed syntactically). I think you want "fragment" here.
The other problem is that in lexer rules '*' should not be used. Or more
specifically: You may not create empty tokens. Doing so increases in the
best case merely the code size and doesn't work in the worst case.
Johannes
>
> Under 3.0, this (atoms rule) match "dfqsdfq" as one would expect.
> Under 3.1 however, it seems that only 'd' (the first letter) is matched.
> How ever the same grammar with VARNAME : (MAJ|MIN|CHAR|'0'..'9')+;
> seems to work properly in both cases. (but matches variables starting
> with uppercases obviously)
> Is the error coming from AntlrWorks ? Am I missing something ?
>
> Thanks for your help.
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
More information about the antlr-interest
mailing list