[antlr-interest] lexer: matching float vs int

Thomas Brandon tbrandonau at gmail.com
Tue Sep 9 09:38:46 PDT 2008


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.
>
> 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.


More information about the antlr-interest mailing list