40 #ifndef __SIM_MATHEXPR_HH__
41 #define __SIM_MATHEXPR_HH__
78 typedef double (*
binOp)(double, double);
88 std::array<OpSearch, uNeg + 1>
ops;
94 const char opStr[] = {
'+',
'-',
'*',
'/',
'^',
'-'};
101 return std::to_string(
value);
103 return std::string(1, opStr[
op]);
120 std::string
toStr(
Node *
n, std::string prefix)
const;
std::string toStr() const
Prints an ASCII representation of the expression tree.
std::array< OpSearch, uNeg+1 > ops
Operator list.
Node * parse(std::string expr)
Parse and create nodes from string.
MathExpr(std::string expr)
std::function< double(std::string)> EvalCallback
std::string toStr() const
double(* binOp)(double, double)
double eval(EvalCallback fn) const
Evaluates the expression.