Bot Tiger wrote:
I just found out that pANTLR3_BASE_TREE->getChild() returns the same node in memory, but pANTLR3_BASE_TREE->getText() creates an entirely new pANTLR3_STRING even when called from the same node.It does not do anything in the lexer but store the start and end points. There is no point in allocatinog memory and copying the strings and so on if you are not going to use the text, which is the case for 95% of the tokens you will parse. As explained in the docs and the examples, it always creates a new copy because I cannot know what you intend to do with it. If you take the string and then use the append functions and so on, you will probaly later require a new copy from the input stream, not the one you last played with. However, if you really want to use the runtime strings (and you do not have to), because perhaps performance isn't that important, then you can pin the pANTLR3_STRING pointer in the token like this in the parser: ... s=STRING_LITERAL { $s.setText($s, $s.text); } The token will then always return the pointer you give it and not make another copy from the input stream. However, if you ask for the text of a span of tokens in a tree, then you probably will get a new string, so when you know your node has just the one token, call getText() on that token directly. Jim
--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~--- |
List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
