Reading a node tree

I'm working on a basic parser and I want to be able to read through the node tree generated by the parser.

Right now, I'm attempting to use a recursion-method but the function seems to only call the child function without the child function calling its child function. Can anyone please help with this issue?

ASTNode.h
1
2
3
4
5
6
7
8
9
10
class ASTNode
{
public:
//more declarations
	std::string *toString();

	Token token;
	int level;
	vector<ASTNode> children;
}


ASTNode.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
std::string *ASTNode::toString()
{
	std::string str = token.cargo;

	for (ASTNode child : children) {
		str += '\n';
		for (int i = 0; i < child.level; ++i) {
			str += '\t';
		}
		
		str += *child.toString();
	}

	return new string(str);
}
Last edited on
Topic archived. No new replies allowed.