[antlr-interest] Transforming trees: modify input tree
Adrian Tineo
tineo at ac.uma.es
Wed Apr 21 04:46:39 PDT 2004
Hello there
I am using the GNU C grammar available at antlr.org. Thanks to this grammar I
can easily create a tree for a C program. I need to modify that tree and
print it back to code. Fortunately, the GNU C grammar comes with a
GnuCEmittter which does just that, it prints out a tree back to code.
If I have
line i: a=b;
line i+1: (left blank)
line i+2: return 0;
I want to have
line i: tmp=b;
line i+1: a=tmp;
line i+2: tmp=NULL;
line i+3: (left blank)
line i+4: return 0;
As you can see I need to change the node for a=b for three nodes, that I want
to print to different lines and still get the proper separation with the
following code.
But I get
line i: tmp=b;
line i+1: a=tmp;
line i+2: tmp=NULL; return 0;
I can easily specify the line numbers for the newly created nodes but in order
to keep the separations right, I would need to update the line number for
every node that comes afterwards.
As I am extending the treeparser grammar and don't want to override the rules
I don't need to work with, I would need to update the line numbers in the
INPUT tree so automatic tree generation for the rules I don't override would
copy the rest of the input nodes(with the updated line numbers) to the ouput
tree.
And the question is, how can I do that? How can I have access to the input
tree for an AST-transforming treeparser?
Or is there a better way to handle this problem?
Any help appreciated. Thanks.
Adrian Tineo
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/antlr-interest/
<*> To unsubscribe from this group, send an email to:
antlr-interest-unsubscribe at yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list