[antlr-interest] Floats and Integers

Tom Zagotta tzagotta1 at sienasystems.com
Tue Sep 23 08:13:42 PDT 2003

Hello everyone,
I have a grammar that needs to accept both floating-point numbers and
integers. A simplified form of the grammar (whitespace skipping not shown)
is like this:

class TestParser extends Parser;
class TestLexer extends Lexer;
INT: ('0'..'9')+;

The problem I have is with input like this:

ABC 3 5

In this case, I need the "3" to match the FLOAT token for the abc rule. It
seems that the only way to do this is to change the rule to the following:


But the problem with that is that there are a really large number of such
rules in my grammar.
Is there a better/alternative way to handle this? Ideally I'd like to define
a token that can match both int and float, but I still need a separate token
for int. It seems this is not possible.
Thanks in advance,
- Tom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20030923/c0a174df/attachment.html

More information about the antlr-interest mailing list