Provides support for evaluating arbitrary C-like artithmetic/string expressions like govaluate.
"1 + 1 == 2"."a + 1 == 2"."a.b == 1"."foo(a, b)".[x] Parse expression and get tokens.
[x] Build expression tree by tokens.
1 + 49.[x] Support basic math expression.
+-*/."1 + 101 % 2 * 5". Because 2 * 5 is in the right stage of operator %, so it will calculate 2 * 5 first. In this case, we will get wrong answer 2 rather than 6. This issue can be fixed by reorderStages.[x] Support variable and accessors.
Eval(params), params is a map like name: object in gvaluate .params is int ,float, string.params should reload operator[] and operator for access and compare. Maybe we can accomplish it by define a base object or use template to support accessors.[x] Add benchmark for Cvaluate.
[ ] Performance enhancement.
Download this repository git clone https://github.com/casbin-cpp/Cvaluate.
Make a directory to complie mkdir build && cd build.
Prepare build file cmake -DCMAKE_BUILD_TYPE=Release ...
Build and install make install.
void test_cvaluate() { using namespace std; string s = "1 + 2 > 1.3"; auto expression = Cvaluate::EvaluableExpression(s); cout << expression.Evaluate({}) << endl; // output true }