This question is a followup on a similar question with java code - how-to-report-grammar-ambiguity-in-antlr4. I am trying to port that code to c++, but I am facing some compilation errors with using the antlr templates.
The main program in c++ is the following:
// TestA_Main.cpp
using namespace std;
using namespace antlr4;
using namespace atn;
int main(int argc, char **argv)
{
string filename = argv[0];
ifstream stream;
stream.open(filename);
ANTLRInputStream input(stream);
AmbigLexer lexer(&input);
CommonTokenStream tokens(&lexer);
AmbigParser parser(&tokens);
parser.addErrorListener(new DiagnosticErrorListener());
// the following line has an error on the call to getInterpreter
parser.getInterpreter().setPredictionMode(PredictionMode::LL_EXACT_AMBIG_DETECTION);
parser.stat();
}
I ran the following commands on it:
java org.antlr.v4.Tool -Dlanguage=Cpp Ambig.g4
g++ -std=gnu++0x -I. -I/antlr4_cpp/runtime/include -I/antlr4_cpp/runtime/include/atn TestA_Main.cpp
And I am getting the following compilation errors, on the call to getInterpreter:
TestA_Main.cpp: In function ‘int main(int, char**)’:
TestA_Main.cpp:27:27: error: no matching function for call to ‘AmbigParser::getInterpreter()’
parser.getInterpreter().setPredictionMode(PredictionMode::LL_EXACT_AMBIG_DETECTION);
^
In file included from /softwares/antlr4/antlr4_cpp/runtime/include/Lexer.h:8:0,
from /softwares/antlr4/antlr4_cpp/runtime/include/antlr4-runtime.h:32,
from TestA_Main.cpp:4:
/softwares/antlr4/antlr4_cpp/runtime/include/Recognizer.h:73:8: note: candidate: template<class T> T* antlr4::Recognizer::getInterpreter() const
T* getInterpreter() const {
^
/softwares/antlr4/antlr4_cpp/runtime/include/Recognizer.h:73:8: note: template argument deduction/substitution failed:
TestA_Main.cpp:27:27: note: couldn't deduce template parameter ‘T’
parser.getInterpreter().setPredictionMode(PredictionMode::LL_EXACT_AMBIG_DETECTION);
Can you please tell me how to fix the above code? I am using antlr-4.6
Aucun commentaire:
Enregistrer un commentaire