[antlr-interest] What is the difference between grammars?!
Randall R Schulz
rschulz at sonic.net
Tue Jan 15 15:03:52 PST 2008
On Tuesday 15 January 2008 14:56, Ostrov, Alexei (GMIT-TASS) wrote:
> One:
> DIGIT : '0'..'9';
> DOUBLE : (DIGIT)+ ('.' (DIGIT)+)? ('e' ('-'|'+')?( DIGIT)+ )? ;
> num : DOUBLE | COLUMN;
>
>
> Another one:
> DOUBLE : ('0'..'9')+ ('.' ('0'..'9')+)? ('e' ('-'|'+')?('0'..'9')+ )? ;
> num : DOUBLE | COLUMN;
>
>
> The first one does not accept 4 as num, the second one does.
>
> That is if I check the parse trees either in AntlrWorks or via
> generated code (CSharp). Using Antlr build antlr-2008-01-10.16
>
> What am I missing!? Did I stumble into a bug?
You're using the DIGIT lexeme in the first grammar as a fragment, but
you did not declare it as such. Just put that keyword ("fragment") in
front of DIGIT and it should do what you want and expect.
> Alexei Ostrov
Randall Schulz
More information about the antlr-interest
mailing list