[antlr-interest] Please advice about float
Bryan Ewbank
ewbank at gmail.com
Mon Sep 19 11:06:02 PDT 2005
Yes, and that works too; because I write in C++, I avoid "=>"
predicates because they incur a thrown exception - very expensive in
C++ - and in this case you don't really need it.
For java, I understand exceptions are not expensive, so this would
perhaps work as well.
On 9/19/05, Mark Kattenbelt <mark.kattenbelt at gmail.com> wrote:
> My solution:
>
> REAL_OR_INT
> : ( INT '.' ) => REAL { $setType(REAL); }
> | ('-' INT '.' ) => REAL { $setType(REAL); }
> | INT { $setType(INT); }
> ;
>
> protected INT options { paraphrase = "a constant integer"; }
> : ('0' .. '9')+
> ;
>
> protected REAL options { paraphrase = "a floating point value"; }
> : ('-')? INT '.' INT
> ;
>
> Hope it helps,
>
> Mark Kattenbelt
More information about the antlr-interest
mailing list