Arithmetic expression evalutaion in C/C++.
double eval(const char *expr);Returns the result of expr.
double eval_v(const char *expr, const EvalValues *values);Returns the result of expr, with constants/variables from values.
int eval_assign(const char *expression, const EvalValue *values);Performs assignment to a variable from values.
Format of expression: val = expr (whitespace does not matter), where val recieves the result of evaluating expr.
Example:
const EvalValue values[] = {
  EvalConst("pi", 3.14159),
  EvalConst("e", 2.71828),
  EvalVar("argc", &argc),
  EvalEnd
};- EvalConstCreates a constant value
- EvalVarUses the value of the pointed to variable
- EvalEndTerminates the array
- Operators: +,-,*and/
- Operator precedences
- Parentheses
- Variables and constants
- Assignment expressions
- Implicit multiplication with parentheses
By default an expression like 48 / 2(9 + 3) is interpreted as 48 / (2 * (9 + 3)).
When compiling with -DEVAL_DISAMBIG_ALT, it gets changed to (48 / 2) * (9 + 3).