I wrote a CPP parser using antlr4 and I’m aware that there’s the getNumberOfSyntaxErrors() funtion which return the number of SyntaxErrors that can be found in Parser.cpp in the runtime. I would like to write them into a file(eg output.txt) whenever theres and error output as below:
line 5681:1 mismatched input 'public' expecting '}'
line 5715:37 no viable alternative at input 'SourceLocationgetBeginLoc()constLLVM_READONLY'
line 5719:35 no viable alternative at input 'SourceLocationgetEndLoc()constLLVM_READONLY'
line 5722:0 mismatched input '}' expecting <EOF>
Just like how I could get the lexer and tree output by doing
for(auto t: tokens.getTokens()){
ofs<<t->toString()<<std::endl;
}
and
ofs<<tree->toStringTree(&parser)<<std::endl<<std::endl;
Note:I’m using CPP target.
Is it possible to do so? If yes what are the related functions?
New contributor
EggDi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.