[antlr-interest] lexer: matching float vs int
Edwards, Waverly
Waverly.Edwards at genesys.com
Tue Sep 9 10:51:53 PDT 2008
That was a pretty neat example.
Thank Jim,
W.
________________________________
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Jim Idle
Sent: Tuesday, September 09, 2008 1:04 PM
To: Thomas Brandon
Cc: antlr-interest at antlr.org
Subject: Re: [antlr-interest] lexer: matching float vs int
On Wed, 2008-09-10 at 02:38 +1000, Thomas Brandon wrote:
On Tue, Sep 9, 2008 at 2:01 PM, Olya Krachina
<okrachin at purdue.edu> wrote:
> Hello,
> I am new to antlr and i seem to be stuck on this.
> i need to have 2 datatypes defined: int and float, currently i
have them defined
> like this in my .g file:
>
> INT: ('0'..'9')+;
> FLOAT: ('0'..'9')*('.')('0'..'9')+ ;
>
> So, this does not work, when it comes across an int i think it
tries to match
> the longest string, i.e. float but finds space instead of '.'
(since its an int)
> and bails out.
See:
http://www.antlr.org/wiki/display/ANTLR3/Lexer+grammar+for+floating+poin
t%2C+dot%2C+range%2C+time+specs
>
> ps: i know this is more a regexp question, but if someone
could help out, I
> would greatly appreciate it.
>
> thanks
Those two rules work fine for me. I think either other rules are
interfering or you are providing invalid input to the grammar.
Try
making a minimal grammar that reproduces the problem and post
that
along with the exact input that fails.
Tom.
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-addr
ess
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080909/62a8b06e/attachment.html
More information about the antlr-interest
mailing list