Eval is a simple, header-only, expression parser for C++.
- easy to integrate - just include
eval.h
- simple API:
eval("your expression", ?vars, ?functions)
- operators
* / + - ^ %
- numbers and strings
- variable argument functions
- built-in constants and functions like
pi
,sqrt()
,sin()
,ceil()
etc. - tests
C++11 compiler
#include "eval.h"
using namespace jgod;
assert(eval("3*2 + 4") == 10);
std::map<std::string, double> vars;
vars["myvar"] = 2;
assert(eval("3*myvar + 4", vars) == 10);
try {return eval("3.14q59");}
catch (const std::invalid_argument &e) {...}
- flow
- strip whitespace
- rewrite adjacent operators
- tokenize
- Shunting-yard algorithm to build RPN queue
- process queue with RPN calculator
- values: numbers and strings
- base value type is
std::string
(casts are necessary) - numbers == doubles
- "null" expressions return 0
- base value type is
- unary
+ -
- function binding using
std::function
- variable length functions using
std::vector
std::exception
s for error handling
Copyright Justin Godesky. Released under the AGPLv3 License.