[antlr-interest] Force nodes for grammar rules
Monty Zukowski
monty at codetransform.com
Tue Dec 6 10:53:26 PST 2005
Maik Merten wrote:
> Bryan Ewbank wrote:
>
>>There's no automatic way to do it. You would have to make sure that
>>every production has an action of the form
>> { ## = #( #PRODUCTION_ID,"production_name"], ## ); }
>>Of course, the leaf nodes, such as identifier, etc, might need
>>different processing...
>
>
> Thank you for your proposal. 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.
Yeah, you have it building on just the last alt. Put your whole match
inside of parens
( pr_Assignment | .... ) {##=#([BasicStatements,"BasicStatements"], ##);}
Another more automatic way of doing this would be to modify the code
generator -- in debug mode is calls enterRule() and exitRule() I think.
Messing with that might get you where you want to go but will be a
little more dangerous than doing it manually.
Monty
More information about the antlr-interest
mailing list