[antlr-interest] How to define a FLOAT number

maulattu maulattu at yahoo.it
Thu Feb 28 08:36:29 PST 2008


Hello!
I need to define a rule in order to recognize a float number. For example, this rule must recognize as float the following numbers:
1.0
22
i.e., the 2nd number is a float without the dot and the decimal part.
I don't need to recognize float number as "mantix+EXPexponent" or the like, just a simple float number as it can be written in a C/C++ program.
I wrote this simple grammar:
-------------------------------
grammar float_recognizer;
offset
    :
        FLOAT
    ;
DIGIT
    :    '0'..'9'
    ;
INT 
    :    DIGIT+
    ;
FLOAT
    :    INT ('.' INT)?
    ;
-------------------------------

This grammar recognizes "1.0" and "0.0", but it fails when it receives as input "1" or a number without the dot and the decimal part.
How can it be possible since the dot and the decimal part are defined as optional (I used the "?" in the FLOAT rule)?

A lot of thanks in advance guys!

Mau


       
---------------------------------

---------------------------------
L'email della prossima generazione? Puoi averla con la nuova Yahoo! Mail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080228/522df06b/attachment.html 


More information about the antlr-interest mailing list