[antlr-interest] How to create many AST trees from one rule

Jim Idle jimi at temporal-wave.com
Fri Oct 30 06:54:59 PDT 2009


Fold it up into the top rule like this:

 

decl : t=type

        i+=ID

        (

          COMMA i+=ID

          

                

        )*  SEMI

        

          ->  ^(DECL $i $t)+

     ;

 

However, do you have some particular reason to make the tree look like that? It is just as easy to deal with: ^(DECL type ^(VARS A B C)) in a walker.

 

Jim

 

 

From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Jared Klumpp
Sent: Thursday, October 29, 2009 12:44 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] How to create many AST trees from one rule

 

I'm trying to create a new DECL for each identifier - if this were C, int a, b; would become (DECL A (TYPE INT)) (DECL B (TYPE INT)).

My rules (untested):
decl: type IDENTS SEMI
-> ^(DECL idents ^(TYPE $type));

idents: IDENT (COMMA IDENT)*
-> IDENT+;

My problem is this creates (DECL A B (TYPE INT)), how can I split this into multiple trees when idents collects the identifiers into one tree?

Thanks,
Jared 



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20091030/fe24be1f/attachment.html 


More information about the antlr-interest mailing list