[antlr-interest] Need help with rule-parameters (ANTLR bug?)
Sean Walton
ab8kf at aim.com
Tue Jan 17 06:58:44 PST 2012
No go. I took out "{ $tree }" and still get the same problem.
The problem is at line #4 (not #7) in the grammar; I've tried all permutations of these parameters, but the problem persists. I believe that the process of creating synthetic predicate is causing the problem, because I can actually find with "n" is being defined elsewhere.
When I manually patch (commenting out "void =null" and defining the type appropriately of "n"), it compiles and works (caveat: I still don't get the tree).
Also, I struggle to believe that a botch job on my end would create "void =null;" when clearly Java does not allow void types.
Sean Walton
ab8kf at aim.com
-----Original Message-----
From: Christian <chwchw at gmx.de>
To: antlr-interest <antlr-interest at antlr.org>
Sent: Tue, Jan 17, 2012 1:15 am
Subject: Re: [antlr-interest] Need help with rule-parameters (ANTLR bug?)
Hi Sean,
wrongly generated code often results from a wrong grammar---what ever
the latter means. The error source is unfortunately not always clear.
I would first try to change your action code in the last rewrite rule: {
$tree }.
I think you want to add this as second entry, but you add it as direct
(Java/C# etc.) code. Remove the braces. However, I do not know whether
you can insert an arbitrary object within a rewrite rule. Usually, you
give the result of a parser rule (I do not know what general return
value it has).
Regards,
Christian
Am 16.01.2012 23:12, schrieb Sean Walton:
> When I put in this:
>
> 1 cccl_declaration[Object tree]
> 2 : cccl_name cccl_def_options '\n'
> 3 -> ^(CCCL_DECLARATION cccl_name cccl_def_options)
> 4 | n=cccl_name cccl_def_options '\n' cccl_declaration[n.getTree()]
> 5 -> ^(CCCL_DECLARATION cccl_name cccl_def_options)
> 6 | cccl_name cccl_command_params* ':' '\n' cccl_execution_block
> 7 -> ^(CCCL_IMPLEMENTATION { $tree } cccl_name cccl_command_params*
cccl_execution_block)
> 8 ;
>
> I get this:
>
> 1 public final void synpred3_cccl_fragment() throws RecognitionException {
> 2--> void =null;
> 3
> 4
> 5 // /home/swalton/Projects/Arthur/Tools/Testing/CCCL/cccl.g:153:4: (n=
cccl_name cccl_def_options '\\n' cccl_declaration[n.getTree()] )
> 6 // /home/swalton/Projects/Arthur/Tools/Testing/CCCL/cccl.g:153:4: n=
cccl_name cccl_def_options '\\n' cccl_declaration[n.getTree()]
> 7 {
> 8 pushFollow(FOLLOW_cccl_name_in_synpred3_cccl402);
> 9--> n=cccl_name();
> 10
> 11 state._fsp--;
> 12 if (state.failed) return ;
> 13
> 14 pushFollow(FOLLOW_cccl_def_options_in_synpred3_cccl404);
> 15 cccl_def_options();
> 16
> 17 state._fsp--;
> 18 if (state.failed) return ;
> 19
> 20 match(input,113,FOLLOW_113_in_synpred3_cccl406); if (state.failed)
return ;
> 21
> 22 pushFollow(FOLLOW_cccl_declaration_in_synpred3_cccl408);
> 23 cccl_declaration(n.getTree());
> 24
> 26 state._fsp--;
> 27 if (state.failed) return ;
> 28
> 29 }
>
> }
>
> Note the arrows. "void =null" is clearly wrong, and in "n=cccl_name()" the "n"
is not defined (it is defined outside this synthetic predicate).
>
> What I want to do:
> I need to collect "cccl_name" from "cccl_declaration" and place them in the
CCCL_IMPLEMENTATION (line #7) rewrite.
>
>
>
> Sean Walton
> ab8kf at aim.com
>
>
> 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
More information about the antlr-interest
mailing list