See "Rewrite rule element cardinality" in the Definitive Antlr Reference (pg. 
184), it seems you want something like:

vars            : VARDECL type (VARIABLE ID literal?)+
        -> ^(VARDECL type ^(VARIABLE ID literal))+;

-J

Date: Wed, 6 Jan 2010 14:58:54 -0500
From: Laurie Harper <[email protected]>
Subject: [antlr-interest] tree rewrite: breaking apart subtrees
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes

I'm trying to construct a parser/translator that will transform an 
extended version of a C-like language 'X' into standard 'X'. I can't 
figure out quite what I need in my tree grammar to get the result I 
want... For example, I have an input AST that looks something like this:

(VARDECL integer
     (VARIABLE ivar1 (LITERAL 1))
     (VARIABLE ivar2 (LITERAL 2))
     (VARIABLE ivar3))
(VARDECL integer
     (VARIABLE ivar4))

I need to rewrite it to look like this:

(VARDECL integer
     (VARIABLE ivar1 (LITERAL 1)))
(VARDECL integer
     (VARIABLE ivar2 (LITERAL 2)))
(VARDECL integer
     (VARIABLE ivar3))
(VARDECL integer
     (VARIABLE ivar))

My tree grammar contains a rule like this:

vars            : ^(VARDECL type (^(VARIABLE ID literal?))+)
        -> ^(VARDECL type)+ ^(VARIABLE ID literal)+;

but that's not giving a result that's even close to right :-) I've 
tried all sorts of variations as I try to puzzle out the tree rewrite 
syntax, to no avail. Can anyone offer any insight?

Thanks,

L.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
-- 
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.


Reply via email to