Go to the documentation of this file.
56 return std::pow(
a,
b); }
61 expr.erase(remove_if(expr.begin(), expr.end(), isspace), expr.end());
64 panic_if(!root,
"Invalid expression\n");
82 for (
int i = expr.size() - 1;
i >= 0;
i--) {
88 if (par < 0)
return NULL;
89 if (par > 0)
continue;
91 for (
unsigned opt = 0; opt <
ops.size(); opt++) {
92 if (
ops[opt].priority !=
p)
continue;
93 if (
ops[opt].
c == expr[
i]) {
99 if ((
l &&
r) || (!
ops[opt].binary &&
r)) {
113 if (expr.size() >= 2 && expr[0] ==
'(' && expr[expr.size() - 1] ==
')')
114 return parse(expr.substr(1, expr.size() - 2));
119 double v = strtod(expr.c_str(), &sptr);
120 if (sptr != expr.c_str()) {
130 bool contains_non_alpha =
false;
132 contains_non_alpha = contains_non_alpha or
133 !( (
c >=
'a' &&
c <=
'z') ||
134 (
c >=
'A' &&
c <=
'Z') ||
135 (
c >=
'0' &&
c <=
'9') ||
136 c ==
'$' ||
c ==
'\\' ||
c ==
'.' ||
c ==
'_');
138 if (!contains_non_alpha) {
156 return fn(
n->variable);
158 for (
auto & opt :
ops)
162 panic(
"Invalid node!\n");
169 ret += prefix +
"|-- " +
n->toStr() +
"\n";
171 ret +=
toStr(
n->r, prefix +
"| ");
173 ret +=
toStr(
n->l, prefix +
"| ");
184 variables.push_back(
n->variable);
MathExpr(std::string expr)
std::vector< std::string > getVariables() const
Return all variables in the this expression.
Node * parse(std::string expr)
Parse and create nodes from string.
std::string toStr() const
Prints an ASCII representation of the expression tree.
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Overload hash function for BasicBlockRange type.
std::array< OpSearch, uNeg+1 > ops
Operator list.
double eval(EvalCallback fn) const
Evaluates the expression.
#define panic(...)
This implements a cprintf based panic() function.
std::function< double(std::string)> EvalCallback
Generated on Wed Sep 30 2020 14:02:14 for gem5 by doxygen 1.8.17