[antlr-interest] Modifying and printing AST under C target
Jim Idle
jimi at temporal-wave.com
Thu Oct 1 07:18:32 PDT 2009
You don't need to do that. There is a user field in the COMMON_TREE node that you can use to store a pointer to your own data - this is much simpler. If you use a custom node, it must really embed COMMON_TREE, which embeds BASE_TREE. Each of these has super pointers to the larger structure but passes around BASE_TREE (though the pointers are void * in the grammar).
-----Original Message-----
From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Heiko Folkerts
Sent: Thursday, October 01, 2009 6:21 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Modifying and printing AST under C target
Hello,
I have a parser that creates an AST. Now I want to annotate the AST with own data. It would be enough to change the payload coresponding to each node. Afterwards I want to print out the AST so I can write unit tests to check everything works as expected.
When I use the ASTLabelType pANTLR3_BASE_TREE and set the $type attribute within a rule I can run the parser, but the function toStringTree only prints out the tokentext. But I'd like to get also the type of the token in the output to check whether the assignment to the $type-Attribute was correct.
I tried using pANTLR3_COMMON_TREE but when running the function tostring (tostringTree is only in pANTLR3_BASE_TREE) my program crashes.
So: 1. Do I have to use the base tree or the common tree?
2. If I need the common tree what do I have to do to use it correctly?
Thx
Heiko
Mit freundlichem Gruß
Heiko Folkerts
Systementwicklung und -design
--
______________________________________________
DAVID GmbH · Wendenring 1 · 38114 Braunschweig
Tel.: +49 531 24379-14
Fax.: +49 531 24379-79
E-Mail: mailto:Heiko.Folkerts at david-bs.de
WWW: http://www.david-bs.de
Eintragung: Amtsgericht Braunschweig, HRB 3167
Geschäftsführer: Frank Ptok
______________________________________________
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
More information about the antlr-interest
mailing list