Thanks Chris, I can follow. However I don't know how to disambiguate this.
Thanks and Cheers! Sven -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Chris Rebert Sent: Thursday, October 30, 2008 10:06 PM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] 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 <[EMAIL PROTECTED]> 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:8080/mailman/listinfo/antlr-interest > Unsubscribe: > http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address > > > List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en -~----------~----~----~----~------~----~------~--~---
