[antlr-interest] Matching & transforming two trees at the same time

uprightness_of_character andrei at metalanguage.com
Sun May 25 15:50:07 PDT 2003


Hi folks,


Consider the following problem: transform C++-like "variable 
definitions with initializers" into C-style definitions (no 
initializers) followed by expressions that perfom initialization. IOW, 
the problem is to transform:

int i = 0, j(5), k = 6;

into:

int i, j, k;
...
i = 0, j = 5, k = 6;

The parsing is done, so we're talking about a tree transformation. 

The way I'm doing things now is, I match and transform the tree into 
the assignments, and at the same time I "collect" the bare definitions 
(without assignments) by hand, and hook it into the AST later. 

Now the code is quite ugly, so what I would really like would be to 
match the same tree twice, and perform a different transformation each 
time.

Any idea on how I can do that? Thanks!


Andrei



 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list