I'm trying to use a custom visitor class for a simple expression grammar.
// .h
class MyVisitor: public MyParserBaseVisitor {...}
// .cpp
Any MyVisitor::visitExpr(MyParser::ExprContext *ctx) {
auto result = visitChildren(ctx);
std::cout<< result.as<int>() << std::endl;
return result;
}
Any MyVisitor::visitInteger(MyParser::IntegerContext *ctx) {
return atoi(ctx->start->getText().c_str());
}
result.as() throws a bad_cast exception and result.isNull() always return true. What am I doing wrong here?
Also, can I use anltrcpp::Any to return a pointer to a custom class object or does it only work with primitive types?