On Thu, 2008-10-30 at 21:49 -0700, Sven Prevrhal wrote:
> Essentially, I want a return of type double for e.g.


Consult:

http://www.antlr.org/wiki/display/ANTLR3/Lexer+grammar+for+floating
+point%2C+dot%2C+range%2C+time+specs

To see how to lex floating point numbers and so on, then steal an
expression parser from one of the examples grammars such as Java or C
(whichever sample is closest to your language). The book will also help
you here of course.

Jim

> 
> 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
> 

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address

Reply via email to