[antlr-interest] Force nodes for grammar rules

Bryan Ewbank ewbank at gmail.com
Tue Dec 6 09:26:47 PST 2005


On 12/6/05, Maik Merten <maikmerten at gmx.net> wrote:
> We're already using that approach:
>
> pr_BasicStatements :
>       pr_Assignment
>       | pr_LogStatement
>       | pr_LoopConstruct
>       | pr_ConditionalConstruct
>       | pr_SelectCaseConstruct
> {
> ## = #([BasicStatements,"BasicStatements"], ##);
> };
>
>
> The "BasicStatements"-node isn't included in the AST in some cases, though.

Maik,

I'm guessing, as "in some cases" is hard to diagnose from afar.... However...

If you look at the generated code, you should see that with your
original production, the intermediate node is only added when a
pr_SelectCaseConstruct is matched.  If you want to have that action
done for all alternatives, then you need to add an extra set of
parenthesis around the alternatives:

    pr_BasicStatements :
        ( pr_Assignment
        | pr_LogStatement
        | pr_LoopConstruct
        | pr_ConditionalConstruct
        | pr_SelectCaseConstruct
        )
        { ## = #([BasicStatements,"BasicStatements"], ##); }
    ;

Hope this works :-)
- Bryan Ewbank


More information about the antlr-interest mailing list