void
processFile(const char *aFilename)
{
std::ifstream stream;
stream.open(aFilename);
outputSourceReview(stream);
CPP14Parser *parser = parseSource(stream);
tree::ParseTree *tree = parser->translationunit();
outputANTLRTreeLikeLisp(std::cout, tree, *parser);
}
CPP14Parser *
parseSource(std::istream &stream)
{
ANTLRInputStream *input = new ANTLRInputStream(stream);
CPP14Lexer *lexer = new CPP14Lexer(input);
CommonTokenStream *tokens = new CommonTokenStream(lexer);
tokens->fill();
CPP14Parser *p = new CPP14Parser(tokens);
return (p);
}
void
outputANTLRTreeLikeLisp(std::ostream &aStream, tree::ParseTree *aTree, CPP14Parser &aParser)
{
aStream << aTree->toStringTree(&aParser) << std::endl;
}
void
outputSourceReview(std::ifstream &aStream)
{
if(aStream.is_open())
{
std::cout << "Parsing source:" << std::endl;
std::cout << aStream.rdbuf();
std::cout << "<EOF>" << std::endl << std::endl;
aStream.clear();
aStream.seekg(0);
}
}
It still runs correctly. So far so good.
I created a Cocoa app, and in an Objective-C++ file I import that code. On the CPP14BaseVisitor.cpp generated by antlr4 it has no trouble. But it goes into an infinite loop when parsing the header file, wherein ParserATNSimulator::closureCheckingStopState() invokes ParserATNSimulator::closure_() which invokes ParserATNSimulator::closureCheckingStopState() repeating decimal.
The parser also barfs on the example source files helloworld.cpp, macro.cpp, and template_args_text.cpp when run from this Cocoa app, but parses without fail .
The tokens parsed, as indicated by the following code, appear to be identical.
for (auto token : tokens.getTokens()) {
std::cout << token->toString() << std::endl;
}
Any ideas what else to look for? How one goes about debugging the runtime?
Warmest regards,
Alfonso Guerra
I created a Cocoa app, and in an Objective-C++ file I import that code. On the CPP14BaseVisitor.cpp generated by antlr4 it has no trouble. But it goes into an infinite loop when parsing the header file, wherein ParserATNSimulator::closureCheckingStopState() invokes ParserATNSimulator::closure_() which invokes ParserATNSimulator::closureCheckingStopState() repeating decimal.The parser also barfs on the example source files helloworld.cpp, macro.cpp, and template_args_text.cpp when run from this Cocoa app, but parses without fail .
The C++14 grammar is a pretty complex beast and I don’t know how complete and correct it is. Hard to say from your description what could be wrong. Can you create a Github project with a demo that shows the problem? Would make it much easier for someone will to take a look.
The C++14 grammar is a pretty complex beast and I don’t know how complete and correct it is. Hard to say from your description what could be wrong. Can you create a Github project with a demo that shows the problem? Would make it much easier for someone will to take a look.Thanks for your reply, Mike. I copied the project and stripped it down, and it ran without crashing. The short version of the cause was parsing the source files in background threads using GCD where Cocoa's default stack size of 512K caused a stack overflow. Moving the parsing to the main thread eliminated the crash.