[antlr-interest] Matching & transforming two trees at the sam
e time
mzukowski at yci.com
mzukowski at yci.com
Tue May 27 08:16:55 PDT 2003
I like to write a tree grammar without actions to use as an antlr
"superclass." Then I subclass and specialize the rules I need to do my
transformations. In the gcc translation framework there is an example of
subclassing:
class GnuCEmitter extends GnuCTreeParser;
www.codetransform.com/gcc.html
Then in your main code you just run the tree through the tree parsers in the
right order.
Monty
-----Original Message-----
From: uprightness_of_character [mailto:andrei at metalanguage.com]
Sent: Sunday, May 25, 2003 3:50 PM
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] Matching & transforming two trees at the same time
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/
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list