[antlr-interest] Stack overflow problem with C++

Jorg Halker jogi1978 at gmx.de
Mon Jul 18 16:38:24 PDT 2005


Hi!

If i run the following code i get a stack overflow error:

****************************************
#include <antlr/CommonAST.hpp>

using namespace antlr;
using namespace std;

int main(int argc, char * * argv)
{
	RefCommonAST first = RefCommonAST( new CommonAST());
	RefCommonAST current = first;
	for (unsigned int counter = 0; counter < 9000; ++counter)
	{
		current->setNextSibling(RefAST( new CommonAST()));
		current = current->getNextSibling();
	}
}
****************************************

It looks like a problem with the destructor of CommonAST or its base
classes. The error occours if 'first' runs out of the scope. 
If i create a parser that parses an input file into the same AST scheme,
everything works fine. But if i create a copy of the AST from the parser i
run into the same problem.

What's wrong? The code snippet should not produce an stack overflow error,
am i right?

Thank you very much,

Joerg



More information about the antlr-interest mailing list