If you just want to evaluate it, then don't duplicate it, just keep the pointer 
- it won't be deallocated until you free the main tree. Also, you should only 
use the toString stuff if you don't really care about performance and memory 
usage. Without knowing what you tried to code, I can't really help, but it is 
unlikely that you need to duplicate the tree. Usually such questions mean that 
you are trying to achieve something that should be achieved differently, so why 
don't you step back and say what you are trying to do rather than ask how to 
duplicate the tree?

Jim



-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Stefan Lind
Sent: Friday, October 22, 2010 1:26 AM
To: [email protected]
Subject: [antlr-interest] copy a tree in c

Hi,
I am trying to copy a part of a tree with the goal to evaluate this part to a 
later point. I wasn't able to find any tutorials or posts which describes a 
solution for my problem so i hope you can help me.
The most promising function i found is the dupTree() function from the 
pANTLR_BASE_TREE which i used as follows:
pANTLR3_BASE_TREE pBaseTree = (pANTLR3_BASE_TREE) 
FUNCTION_DEF10->dupTree(FUNCTION_DEF10);
Then i tryed to reuse the tree pBaseTree to a later point but it failed already 
when i used the toStringTree() function on it.
std::string treeString = (const char*)
pBaseTree->toStringTree(pBaseTree)->chars;
The output of the string treeString is nil. Between the dupTree() and 
toStringTree(), antlr continues to evaluate the tree.
When i call the toStringTree() function right after the dupTree() call, it 
delivers the correct ouput.

Does anyone see my mistake, or has any suggestion where i can find help?

Regards,
Stefan

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address




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