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: [email protected] 
[mailto:[email protected]] On Behalf Of Jared Klumpp
Sent: Thursday, October 29, 2009 12:44 PM
To: [email protected]
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 




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

Reply via email to