[antlr-interest] Need help with rule-parameters (ANTLR bug?)

Christian chwchw at gmx.de
Tue Jan 17 00:15:14 PST 2012


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
>



More information about the antlr-interest mailing list