[antlr-interest] Difference between * and +

Jim Idle jimi at temporal-wave.com
Fri Oct 17 07:43:10 PDT 2008


On Fri, 2008-10-17 at 15:45 +0200, Johannes Luber wrote:

> 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.


Yes - the lack of fragment is matching the MIN as a token in its own
right.


> 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.


However, he has not done that here as the VARNAME rule starts with one
MIN followed by any number of the following tokens, so it does not
create an empty token (lack of spaces in the rule spec makes it harder
to see that I think).


Jim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081017/9c710df5/attachment.html 


More information about the antlr-interest mailing list