[antlr-interest] ints and fractions - how to avoid "Decision can match input such as "INT SLASH INT" using multiple alternatives" warnings

Sven Prevrhal sven.prevrhal at ucsf.edu
Mon Nov 3 12:48:55 PST 2008


Thanks Chris,
I can follow. However I don't know how to disambiguate this. 

 
Thanks and Cheers!
Sven


-----Original Message-----
From: cvrebert at gmail.com [mailto:cvrebert at gmail.com] On Behalf Of Chris
Rebert
Sent: Thursday, October 30, 2008 10:06 PM
To: sven.prevrhal at ucsf.edu
Cc: antlr-interest at antlr.org
Subject: Re: [antlr-interest] ints and fractions - how to avoid "Decision
can match input such as "INT SLASH INT" using multiple alternatives"
warnings

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