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

mark twain himmy070 at gmail.com
Mon Aug 18 15:10:38 PDT 2008


Jim,
Sorry to bug you again but still I am getting the following error
messages......
*****************************************************************************************
ANTLR Parser Generator  Version 3.1b2 (July 17, 2008)  1989-2008
error(148): bbcalcInterpreter.g:16:13: rule parameters may not have init
values: v
error(122): bbcalcInterpreter.g:17:33: label v conflicts with rule
assignment's return value or parameter with same name
error(146): bbcalcInterpreter.g:18:12: invalid StringTemplate % shorthand
syntax: '%d'
***********************************************************************************************

Cheers:)

On 8/18/08, Jim Idle <jimi at temporal-wave.com> wrote:
>
> 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
>
>
>
>
>
> 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/2254ea26/attachment.html 


More information about the antlr-interest mailing list