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

Sven Prevrhal sprevrha at gmail.com
Thu Oct 30 21:49:35 PDT 2008


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   :               '/';

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081030/4cf5358e/attachment.html 


More information about the antlr-interest mailing list