[antlr-interest] help related to interpreted grammar for calculator

Jim Idle jimi at temporal-wave.com
Mon Aug 18 15:01:33 PDT 2008


On Mon, 2008-08-18 at 17:50 -0400, mark twain wrote:
> Hi Jim,
>  
> I am still getting the same errors :-( even with your last suggested
> modifications....


Oh, your parameter specification is incorrect too:

assignment [int v = 0; ]

It is [] not {}

Jim

PS: Please use the group rather than emailing me direct.


> ***********************************************************************
> ANTLR Parser Generator  Version 3.1b2 (July 17, 2008)  1989-2008
> error(100): bbcalcInterpreter.g:16:13: syntax error: antlr:
> bbcalcInterpreter.g:16:13: unexpected token:  int v = 0; 
> error(100): bbcalcInterpreter.g:17:22: syntax error: antlr:
> bbcalcInterpreter.g:17:22: unexpected token: IDENTIFIER
> error(100): bbcalcInterpreter.g:17:34: syntax error: antlr:
> bbcalcInterpreter.g:17:34: unexpected token: =
> error(100): bbcalcInterpreter.g:17:39: syntax error: antlr:
> bbcalcInterpreter.g:17:39: unexpected token: )
> warning(138): bbcalcInterpreter.g:0:0: grammar bbcalcInterpreter: no
> start rule (no rule can obviously be followed by EOF)
> ************************************************************************
> Please suggest me if I am still missing something!!!
>  
> Cheers:)
> On 8/18/08, Jim Idle <jimi at temporal-wave.com> wrote: 
> 
>         On Mon, 2008-08-18 at 17:05 -0400, mark twain wrote: 
>         
>         > 
>         > Sorry!! for the mistake.. 
>         > I have attached all 3 grammar files once again... Please
>         > look into the Interpreter grammar file and let me know my
>         > mistake....
>         
>         
>         You are not using references properly. You need to use $xxxx
>         and then the return element reference. PLease cosinder
>         spending time reading through the C examples and the Wiki
>         stuff. If you can afford to then buyig the book woudl be a
>         good resource:
>         
>         tree grammar bbcalcInterpreter;
>         
>         
>         options
>         {
>              tokenVocab= bbcalc;
>              ASTLabelType = pANTLR3_BASE_TREE;
>              language = C;
>         }
>         
>         @header {
>         #include <stdio.h>
>         }
>         
>         assignment  { int v = 0; }
>                    : ^(EQUAL IDENTIFIER v=expr)
>                    { printf("My value:%d\n", $v.val); }
>                 ;
>         
>         
>         expr returns [int val =0]
>                 : z = operand   { $val = $z.val; }
>                   |  ^(PLUS x=expr y=expr) { $val = $x.val + $y.val; }
>                   |  ^(MINUS x=expr y=expr) { $val = $x.val -
>         $y.val; }
>                   |  ^(MULT x=expr y=expr) { $val = $x.val * $y.val; }
>                   |  ^(DIV x=expr y=expr) { $val = $x.val / $y.val; }
>                 ;
>         
>         operand returns [int val =0]
>         : n = NUMBER { $val = atoi($n.text->chars); }
>                 ;
>         
>         
>         
>         
>         List:
>         http://www.antlr.org/mailman/listinfo/antlr-interest
>         Unsubscribe:
>         http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>         
>         
> 
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080818/c7e1c599/attachment.html 


More information about the antlr-interest mailing list