[antlr-interest] Factoring token definitions
Thomas Karcher
thkarcher at gmx.de
Mon Feb 18 02:34:17 PST 2008
Salut Olivier,
> DIGIT: '0'..'9';
> INT: DIGIT+;
> The problem with this is that when faced with a single digit the lexer will
> mark it as a DIGIT whereas you'd like to get an INT in all cases. Reversing
> the order of INT and DIGIT might give the desired results in the lexer, if
> I understand that correctly, but that fails even earlier, with ANTLR
> complaining that DIGIT is unreachable when you try to compile the grammar.
The answer might be:
fragment
DIGIT: '0'..'9';
INT: DIGIT+;
Try it ... the "fragment" keyword should do exactly what you want.
Regards,
Thomas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20080218/0397a5d5/attachment.bin
More information about the antlr-interest
mailing list