[antlr-interest] How to define a FLOAT number
Bernardo Elayda
belayda at gmail.com
Thu Feb 28 23:09:00 PST 2008
Hi,
My solution for recognizing a float is a little different:
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/8b1b2204/attachment.html
More information about the antlr-interest
mailing list