[antlr-interest] ints and fractions - how to avoid "Decision can match input such as "INT SLASH INT" using multiple alternatives" warnings
Chris Rebert
cvrebert+antlr at gmail.com
Thu Oct 30 22:05:36 PDT 2008
In plain English, that error message means: input such as e.g. "1/2"
is ambiguous since it could be interpreted as either a float literal
using the fraction syntax or as a division expression with 2 integer
operands.
You'll have to disambiguate your grammar so ANTLR can know which
interpretation you intend.
Cheers,
Chris
--
Follow the path of the Iguana...
http://rebertia.com
On Thu, Oct 30, 2008 at 9:49 PM, Sven Prevrhal <sprevrha at gmail.com> wrote:
> Essentially, I want a return of type double for e.g.
>
> 3
>
> 1.523
>
> 1 2/3
>
>
>
> Below's my grammar with C# actions, and I get
>
> "Decision can match input such as "INT SLASH INT" using multiple
> alternatives" in Antlrworks.
>
>
>
> Thanks for your help!!
>
> Sven
>
>
>
> //
>
> //Trouble Grammar
>
> //
>
> number returns [double n]
>
> :
>
> (INT {$n = (double)int.Parse($INT.text);}) (f = fraction {$n
> += f;})? |
>
> f = fraction {$n = f;} |
>
> AFLOAT {$n = double.Parse($AFLOAT.text);};
>
>
>
> fraction returns [double f] :
>
> i1=INT SLASH i2=INT {$f = (double)int.Parse($i1.text) /
> (double)int.Parse($i2.text);};
>
>
>
> AFLOAT : INT DOT INT?;
>
>
>
> INT : '0'..'9'+;
>
>
>
> SLASH : '/';
>
>
>
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
>
>
More information about the antlr-interest
mailing list