I am trying to build an AST from bison grammar. Bison correctly generates a parser, but when I try to parse a sample code with some mathematical operations, its following error:
[Fatal] calling `.get<Tag__::EXPR>()', but Tag INT is encountered.
After debugging, I notice that the problem is with the non-terminal exprwith the following work:
expr:
...
| operator
{
$$ = $1;
}
And operatorhas the following production:
operator:
...
| INTEGER
{
$$ = new ast::expression::IntASTNode(std::stoi(d_scanner.matched()));
}
I use polymorphic semantic types, exprand operatormarked ones exprthat respond to ExprASTNodetype witch is the base class for IntASTNodewith a tag INT. I guess the bison gets the type from the tag and checks the tags before making any cast. Is there any way to resolve this?