[antlr-interest] Parsing floats and unary minus

Bart Kiers bkiers at gmail.com
Sat Apr 24 04:38:39 PDT 2010


On Sat, Apr 24, 2010 at 1:05 PM, Rick Mann <rmann at latencyzero.com> wrote:

>
> On Apr 24, 2010, at 01:34:08, Bart Kiers wrote:
>
> > On Sat, Apr 24, 2010 at 4:25 AM, Rick Mann <rmann at latencyzero.com>
> wrote:
> > float returns [float val]
> >        :       { $val = Float.parseFloat($FLOAT.text); }
> >        ;
> >
> > Note that you never use your 'float' rule.
>
> Yeah, I go back and forth, trying to make it work.
>

Okay, but you showed a grammar where you did not use your float-rule, but
mentioned you had problems with that rule. Could you post the grammar you're
actually having problems with?


>
> > INT :   '0'..'9'+
> >    ;
> >
> > FLOAT
> >    :   ('0'..'9')+ '.' ('0'..'9')* EXPONENT?
> >    |   '.' ('0'..'9')+ EXPONENT?
> >    |   ('0'..'9')+ EXPONENT
> >    ;
> >
> > Try placing FLOAT before INT in your grammar.
>
> That's straight from the ANTLRWorks grammar creation wizard. Is it
> incorrect?
>
> --
> Rick
>


If you haven't changed anything about the order, then itmust be correct.

Bart.


More information about the antlr-interest mailing list