[antlr-interest] How to define a FLOAT number

Bernardo Elayda belayda at gmail.com
Thu Feb 28 23:10:27 PST 2008


Whoops!  I forgot one more thing.  Correction is below:



On Thu, Feb 28, 2008 at 11:09 PM, Bernardo Elayda <belayda at gmail.com> wrote:

> Hi,
>
> My solution for recognizing a float is a little different:
>

@lexer::member {
int n=0;
}

>
> REAL
>      :(
>      (NATURAL+ PERIOD)=>NATURAL+ PERIOD {++n;} NATURAL* {n==1}?
>      |
>      (PERIOD NATURAL+)=>PERIOD {++n;} NATURAL+ {n==1}?
>       )
>      {
>             System.out.println("n is: " + n);
>      }
>      ;
>
> fragment PERIOD : '.' ;
> fragment NATURAL: '0'..'9' ;
>
> I found that it was necessary to use syntax predicate and a validating
> semantic check.  Without the validating semantic check, a value of 1.2.3would be recognized as a float.
>
> regards,
> Bernie Elayda
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080228/8ca86f96/attachment.html 


More information about the antlr-interest mailing list