I want to write a small expression compiler by using boost spirit x3 and yap. The idea are like these:
Write a parser to parser the syntax into an AST;
Than compile the ast into the expression, like A = B(a,b) + C(a,b) - 1.2;
When needed, pass the expression to where it is needed, and use yap evaluate to get the result.
Following is my code to implement some ideas. However, i met a problem in the eval struct operator, like following. I just want to know if i use this pattern, what exactly the return value is(not auto), to adapt plus and minus expression template? thanks.....
auto operator()(operation const& x,int rhs, int lhs) const
{
//int rhs = boost::apply_visitor(*this, x.operand_);
auto rhs_w = boost::yap::make_terminal<tarray_expr>(rhs);
auto lhs_w = boost::yap::make_terminal<tarray_expr>(lhs);
switch (x.operator_)
{
case '+': return lhs_w + rhs_w;
case '-': return lhs_w - rhs_w;
}
//return rhs;
}
I re-editted the post, and attached the code as a txt file, and looking forward for the help, thanks!
main.cpp.txt
I want to write a small expression compiler by using boost spirit x3 and yap. The idea are like these:
Following is my code to implement some ideas. However, i met a problem in the eval struct operator, like following. I just want to know if i use this pattern, what exactly the return value is(not auto), to adapt plus and minus expression template? thanks.....
I re-editted the post, and attached the code as a txt file, and looking forward for the help, thanks! main.cpp.txt