[antlr-interest] Floats and Integers

Anthony W Youngman Anthony.Youngman at ECA-International.com
Fri Sep 26 03:47:00 PDT 2003


In my grammar, I've got this:
 
NUMBER_LITERAL : ( INT (DECIMAL (INT)?)? | DECIMAL INT ) ;

Presumably you need something like
 
NUMBER : ( INT | FLOAT ) ;
 
maybe protected. Dunno what you're trying to do, but that should work.
 
Cheers,
Wol

-----Original Message-----
From: Tom Zagotta [mailto:tzagotta1 at sienasystems.com] 
Sent: 23 September 2003 16:14
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] Floats and Integers


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;
abc:"ABC" FLOAT INT;
 
class TestLexer extends Lexer;
INT: ('0'..'9')+;
FLOAT: INT '.' INT;

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:

abc: "ABC" (FLOAT|INT) INT;

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
 

Your use of Yahoo! Groups is subject to the Yahoo!
<http://docs.yahoo.com/info/terms/> Terms of Service. 





***********************************************************************************

This transmission is intended for the named recipient only. It may contain private and confidential information. If this has come to you in error you must not act on anything disclosed in it, nor must you copy it, modify it, disseminate it in any way, or show it to anyone. Please e-mail the sender to inform us of the transmission error or telephone ECA International immediately and delete the e-mail from your information system.

Telephone numbers for ECA International offices are: Sydney +61 (0)2 9911 7799, Hong Kong + 852 2121 2388, London +44 (0)20 7351 5000 and New York +1 212 582 2333.

***********************************************************************************

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20030926/5a8a3aa8/attachment.html


More information about the antlr-interest mailing list