[antlr-interest] Problem parsing float numbers

Jim Idle jimi at temporal-wave.com
Wed Nov 25 16:18:29 PST 2009


Well, these rules are all ambiguous. I am sure you are getting errors about that? You can do two things:

 

Steal number parsing from a grammar that already supports the types you want.

 

See the FAQ:

 

http://www.antlr.org/wiki/display/ANTLR3/Lexer+grammar+for+floating+point%2C+dot%2C+range%2C+time+specs

 

Though this does more than you are asking here, you can just take the pieces you need.

 

Jim

 

 

From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Marcel Schaible
Sent: Wednesday, November 25, 2009 2:44 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Problem parsing float numbers

 

Hello everybody,

 

I have a problem with parsing floating point numbers:

 

My grammar contains the following part for recognizing floats:

 

fragment DIGIT : '0'..'9' ;

fragment INT   : DIGIT + ;

NUM     : INT ( '.' INT)? ;

EXP     : ( 'E' | 'e' ) ( '-' | '+')? NUM  ;

ENUM    : NUM ( EXP )? ;

 

When I feed into the parser 1.0 I got the following error message:

 

line 1:0 required (...)+ loop did not match anything at input '1.0'

 

I did not see the problem. Any ideas and comments are welcome!

 

Thanks in advance for your help.

 

Marcel



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20091125/00805a89/attachment.html 


More information about the antlr-interest mailing list