C++ Mathematical Expression Library (ExprTk) https://www.partow.net/programming/exprtk/index.html
This commit is contained in:
parent
e8c253fa60
commit
9cddffaf52
3085
exprtk.hpp
3085
exprtk.hpp
File diff suppressed because it is too large
Load Diff
|
@ -3,7 +3,7 @@
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* ExprTk vs Native Benchmarks *
|
* ExprTk vs Native Benchmarks *
|
||||||
* Author: Arash Partow (1999-2017) *
|
* Author: Arash Partow (1999-2017) *
|
||||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 1 *
|
* Simple Example 1 *
|
||||||
* Author: Arash Partow (1999-2017) *
|
* Author: Arash Partow (1999-2017) *
|
||||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 2 *
|
* Simple Example 2 *
|
||||||
* Author: Arash Partow (1999-2017) *
|
* Author: Arash Partow (1999-2017) *
|
||||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 3 *
|
* Simple Example 3 *
|
||||||
* Author: Arash Partow (1999-2017) *
|
* Author: Arash Partow (1999-2017) *
|
||||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 4 *
|
* Simple Example 4 *
|
||||||
* Author: Arash Partow (1999-2017) *
|
* Author: Arash Partow (1999-2017) *
|
||||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 5 *
|
* Simple Example 5 *
|
||||||
* Author: Arash Partow (1999-2017) *
|
* Author: Arash Partow (1999-2017) *
|
||||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 6 *
|
* Simple Example 6 *
|
||||||
* Author: Arash Partow (1999-2017) *
|
* Author: Arash Partow (1999-2017) *
|
||||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 7 *
|
* Simple Example 7 *
|
||||||
* Author: Arash Partow (1999-2017) *
|
* Author: Arash Partow (1999-2017) *
|
||||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 8 *
|
* Simple Example 8 *
|
||||||
* Author: Arash Partow (1999-2017) *
|
* Author: Arash Partow (1999-2017) *
|
||||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 9 *
|
* Simple Example 9 *
|
||||||
* Author: Arash Partow (1999-2017) *
|
* Author: Arash Partow (1999-2017) *
|
||||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 10 *
|
* Simple Example 10 *
|
||||||
* Author: Arash Partow (1999-2017) *
|
* Author: Arash Partow (1999-2017) *
|
||||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 11 *
|
* Simple Example 11 *
|
||||||
* Author: Arash Partow (1999-2017) *
|
* Author: Arash Partow (1999-2017) *
|
||||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 12 *
|
* Simple Example 12 *
|
||||||
* Author: Arash Partow (1999-2017) *
|
* Author: Arash Partow (1999-2017) *
|
||||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 13 *
|
* Simple Example 13 *
|
||||||
* Author: Arash Partow (1999-2017) *
|
* Author: Arash Partow (1999-2017) *
|
||||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 14 *
|
* Simple Example 14 *
|
||||||
* Author: Arash Partow (1999-2017) *
|
* Author: Arash Partow (1999-2017) *
|
||||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 15 *
|
* Simple Example 15 *
|
||||||
* Author: Arash Partow (1999-2017) *
|
* Author: Arash Partow (1999-2017) *
|
||||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 16 *
|
* Simple Example 16 *
|
||||||
* Author: Arash Partow (1999-2017) *
|
* Author: Arash Partow (1999-2017) *
|
||||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 17 *
|
* Simple Example 17 *
|
||||||
* Author: Arash Partow (1999-2017) *
|
* Author: Arash Partow (1999-2017) *
|
||||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 18 *
|
* Simple Example 18 *
|
||||||
* Author: Arash Partow (1999-2017) *
|
* Author: Arash Partow (1999-2017) *
|
||||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 19 *
|
* Simple Example 19 *
|
||||||
* Author: Arash Partow (1999-2017) *
|
* Author: Arash Partow (1999-2017) *
|
||||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
|
223
exprtk_test.cpp
223
exprtk_test.cpp
|
@ -3,7 +3,7 @@
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Examples and Unit-Tests *
|
* Examples and Unit-Tests *
|
||||||
* Author: Arash Partow (1999-2017) *
|
* Author: Arash Partow (1999-2017) *
|
||||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
@ -1308,13 +1308,13 @@ inline bool run_test01()
|
||||||
test_xy<T>(" ((2) y) == (2*y)" ,T(2.0),T(3.0),T(1.0)),
|
test_xy<T>(" ((2) y) == (2*y)" ,T(2.0),T(3.0),T(1.0)),
|
||||||
test_xy<T>(" (2 (y)) == (2*y)" ,T(2.0),T(3.0),T(1.0)),
|
test_xy<T>(" (2 (y)) == (2*y)" ,T(2.0),T(3.0),T(1.0)),
|
||||||
test_xy<T>("var a := 2; (a)(3) == 6" ,T(2.0),T(3.0),T(1.0)),
|
test_xy<T>("var a := 2; (a)(3) == 6" ,T(2.0),T(3.0),T(1.0)),
|
||||||
test_xy<T>("var a := 2; (a){3} == 6" ,T(2.0),T(3.0),T(1.0)),
|
test_xy<T>("var a := 2; (A){3} == 6" ,T(2.0),T(3.0),T(1.0)),
|
||||||
test_xy<T>("var a := 2; (a)[3] == 6" ,T(2.0),T(3.0),T(1.0)),
|
test_xy<T>("var a := 2; (a)[3] == 6" ,T(2.0),T(3.0),T(1.0)),
|
||||||
test_xy<T>("var a := 2; {a}(3) == 6" ,T(2.0),T(3.0),T(1.0)),
|
test_xy<T>("var a := 2; {a}(3) == 6" ,T(2.0),T(3.0),T(1.0)),
|
||||||
test_xy<T>("var a := 2; {a}{3} == 6" ,T(2.0),T(3.0),T(1.0)),
|
test_xy<T>("var a := 2; {a}{3} == 6" ,T(2.0),T(3.0),T(1.0)),
|
||||||
test_xy<T>("var a := 2; {a}[3] == 6" ,T(2.0),T(3.0),T(1.0)),
|
test_xy<T>("var a := 2; {a}[3] == 6" ,T(2.0),T(3.0),T(1.0)),
|
||||||
test_xy<T>("var a := 2; var b := 3; (a)(b) == 6" ,T(2.0),T(3.0),T(1.0)),
|
test_xy<T>("var a := 2; var b := 3; (a)(b) == 6" ,T(2.0),T(3.0),T(1.0)),
|
||||||
test_xy<T>("var a := 2; var b := 3; (a){b} == 6" ,T(2.0),T(3.0),T(1.0)),
|
test_xy<T>("var a := 2; var b := 3; (a){B} == 6" ,T(2.0),T(3.0),T(1.0)),
|
||||||
test_xy<T>("var a := 2; var b := 3; (a)[b] == 6" ,T(2.0),T(3.0),T(1.0)),
|
test_xy<T>("var a := 2; var b := 3; (a)[b] == 6" ,T(2.0),T(3.0),T(1.0)),
|
||||||
test_xy<T>("var a := 2; var b := 3; {a}(b) == 6" ,T(2.0),T(3.0),T(1.0)),
|
test_xy<T>("var a := 2; var b := 3; {a}(b) == 6" ,T(2.0),T(3.0),T(1.0)),
|
||||||
test_xy<T>("var a := 2; var b := 3; {a}{b} == 6" ,T(2.0),T(3.0),T(1.0)),
|
test_xy<T>("var a := 2; var b := 3; {a}{b} == 6" ,T(2.0),T(3.0),T(1.0)),
|
||||||
|
@ -1604,7 +1604,7 @@ inline bool run_test01()
|
||||||
test_xy<T>("var a := 2; (1 * a) == a",T(0),T(0),T(1)),
|
test_xy<T>("var a := 2; (1 * a) == a",T(0),T(0),T(1)),
|
||||||
test_xy<T>("var a.b := 3; (2 * a.b ) == 6",T(0),T(0),T(1)),
|
test_xy<T>("var a.b := 3; (2 * a.b ) == 6",T(0),T(0),T(1)),
|
||||||
test_xy<T>("var aa.bb := 3; (2 * aa.bb ) == 6",T(0),T(0),T(1)),
|
test_xy<T>("var aa.bb := 3; (2 * aa.bb ) == 6",T(0),T(0),T(1)),
|
||||||
test_xy<T>("var aaa.bbb := 3; (2 * aaa.bbb) == 6",T(0),T(0),T(1)),
|
test_xy<T>("var aaa.bbb := 3; (2 * aAa.BbB) == 6",T(0),T(0),T(1)),
|
||||||
test_xy<T>("var a1.b2 := 3; (2 * a1.b2 ) == 6",T(0),T(0),T(1))
|
test_xy<T>("var a1.b2 := 3; (2 * a1.b2 ) == 6",T(0),T(0),T(1))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3273,15 +3273,15 @@ struct myfunc : public exprtk::ifunction<T>
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#define define_free_functions(Type) \
|
#define define_free_functions(N,Type) \
|
||||||
Type foo1(Type v0) { return v0; } \
|
Type N##1(Type v0) { return v0; } \
|
||||||
Type foo2(Type v0, Type v1) { return v0 + v1; } \
|
Type N##2(Type v0, Type v1) { return v0 + v1; } \
|
||||||
Type foo3(Type v0, Type v1, Type v2) { return v0 + v1 + v2; } \
|
Type N##3(Type v0, Type v1, Type v2) { return v0 + v1 + v2; } \
|
||||||
Type foo4(Type v0, Type v1, Type v2, Type v3) { return v0 + v1 + v2 + v3; } \
|
Type N##4(Type v0, Type v1, Type v2, Type v3) { return v0 + v1 + v2 + v3; } \
|
||||||
Type foo5(Type v0, Type v1, Type v2, Type v3, Type v4) { return v0 + v1 + v2 + v3 + v4; } \
|
Type N##5(Type v0, Type v1, Type v2, Type v3, Type v4) { return v0 + v1 + v2 + v3 + v4; } \
|
||||||
Type foo6(Type v0, Type v1, Type v2, Type v3, Type v4, Type v5) { return v0 + v1 + v2 + v3 + v4 + v5; } \
|
Type N##6(Type v0, Type v1, Type v2, Type v3, Type v4, Type v5) { return v0 + v1 + v2 + v3 + v4 + v5; } \
|
||||||
|
|
||||||
define_free_functions(numeric_type)
|
define_free_functions(foo,numeric_type)
|
||||||
#undef define_free_functions
|
#undef define_free_functions
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -4269,10 +4269,10 @@ inline bool run_test10()
|
||||||
"var x[3] := [8]; var y[3] := {1,2,3}; (x += 1) <=> (y += 1); (x[0] == 2) and (x[1] == 3) and (x[2] == 4)",
|
"var x[3] := [8]; var y[3] := {1,2,3}; (x += 1) <=> (y += 1); (x[0] == 2) and (x[1] == 3) and (x[2] == 4)",
|
||||||
"var x[3] := [8]; var y[2] := {1,2}; (x += 1) <=> (y += 1); (x[0] == 2) and (x[1] == 3) and (x[2] == 9)",
|
"var x[3] := [8]; var y[2] := {1,2}; (x += 1) <=> (y += 1); (x[0] == 2) and (x[1] == 3) and (x[2] == 9)",
|
||||||
"var x[3] := [8]; var y[1] := {1}; (x += 1) <=> (y += 1); (x[0] == 2) and (x[1] == 9) and (x[2] == 9)",
|
"var x[3] := [8]; var y[1] := {1}; (x += 1) <=> (y += 1); (x[0] == 2) and (x[1] == 9) and (x[2] == 9)",
|
||||||
"var x[3] := [0]; var y[4] := {1,2,3,4}; x < y",
|
"var x[3] := [0]; var y[4] := {1,2,3,4}; X < y",
|
||||||
"var x[3] := [0]; var y[3] := {1,2,3}; x < y",
|
"var x[3] := [0]; var y[3] := {1,2,3}; x < Y",
|
||||||
"var x[3] := [0]; var y[2] := {1,2}; x < y",
|
"var x[3] := [0]; var y[2] := {1,2}; X < y",
|
||||||
"var x[3] := [0]; var y[1] := {1}; x < y",
|
"var x[3] := [0]; var y[1] := {1}; x < Y",
|
||||||
"var x[3] := [0]; var y[4] := {1,2,3,4}; x <= y",
|
"var x[3] := [0]; var y[4] := {1,2,3,4}; x <= y",
|
||||||
"var x[3] := [0]; var y[3] := {1,2,3}; x <= y",
|
"var x[3] := [0]; var y[3] := {1,2,3}; x <= y",
|
||||||
"var x[3] := [0]; var y[2] := {1,2}; x <= y",
|
"var x[3] := [0]; var y[2] := {1,2}; x <= y",
|
||||||
|
@ -4382,6 +4382,15 @@ inline bool run_test10()
|
||||||
"0 == (for (var i := 0; i < 10; i += 1) { ~{continue; break[7]; i += i} })",
|
"0 == (for (var i := 0; i < 10; i += 1) { ~{continue; break[7]; i += i} })",
|
||||||
"1 == (for (var i := 0; i < 10; i += 1) { ~{break[i += 1]; continue; i += i} })",
|
"1 == (for (var i := 0; i < 10; i += 1) { ~{break[i += 1]; continue; i += i} })",
|
||||||
|
|
||||||
|
"var s := 'abc'; s == ~{'abc' } ",
|
||||||
|
"var s := 'abc'; s == ~{s } ",
|
||||||
|
"var s := 'abc'; s == ~{'ab' + 'c'} ",
|
||||||
|
"var s := 'abc'; ~{'abc' } == s ",
|
||||||
|
"var s := 'abc'; ~{s } == s ",
|
||||||
|
"var s := 'abc'; ~{'ab' + 'c'} == s ",
|
||||||
|
"var s := 'abc'; ~{1 + 2; 'abc' + s; s} == s ",
|
||||||
|
"var s := 'abc'; ~{1 + 2; var x := 'ab'; x + 'c'} == s ",
|
||||||
|
|
||||||
"var x[10^6] := null; var y[10^7] := null; 0 * (min(x) + min(y)) + x[] + y[] == 10^7 + 10^6"
|
"var x[10^6] := null; var y[10^7] := null; 0 * (min(x) + min(y)) + x[] + y[] == 10^7 + 10^6"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -7656,54 +7665,164 @@ struct my_usr : public exprtk::parser<T>::unknown_symbol_resolver
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct my_usr_ext : public exprtk::parser<T>::unknown_symbol_resolver
|
||||||
|
{
|
||||||
|
typedef exprtk::symbol_table<T> symbol_table_t;
|
||||||
|
typedef typename exprtk::parser<T>::unknown_symbol_resolver usr_t;
|
||||||
|
|
||||||
|
my_usr_ext()
|
||||||
|
: usr_t(usr_t::e_usrmode_extended)
|
||||||
|
{}
|
||||||
|
|
||||||
|
virtual bool process(const std::string& unknown_symbol,
|
||||||
|
symbol_table_t& symbol_table,
|
||||||
|
std::string& error_message)
|
||||||
|
{
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
if (unknown_symbol[0] == 'v')
|
||||||
|
{
|
||||||
|
static T var_default_value = 1.0;
|
||||||
|
|
||||||
|
if (!(result = symbol_table.create_variable(unknown_symbol, var_default_value++)))
|
||||||
|
{
|
||||||
|
error_message = "Failed to create variable(" + unknown_symbol + ") in primary symbol table";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (unknown_symbol[0] == 'c')
|
||||||
|
{
|
||||||
|
static T cvar_default_value = 1.0;
|
||||||
|
|
||||||
|
if (!(result = symbol_table.add_constant(unknown_symbol, cvar_default_value++)))
|
||||||
|
{
|
||||||
|
error_message = "Failed to create const variable(" + unknown_symbol + ") in primary symbol table";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (0 == unknown_symbol.find("foo"))
|
||||||
|
{
|
||||||
|
//functions of form: fooXX
|
||||||
|
if (4 >= unknown_symbol.size())
|
||||||
|
{
|
||||||
|
switch(unknown_symbol[3])
|
||||||
|
{
|
||||||
|
case '1' : result = symbol_table.add_function(unknown_symbol,foo1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '2' : result = symbol_table.add_function(unknown_symbol,foo2);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '3' : result = symbol_table.add_function(unknown_symbol,foo3);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '4' : result = symbol_table.add_function(unknown_symbol,foo4);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '5' : result = symbol_table.add_function(unknown_symbol,foo5);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '6' : result = symbol_table.add_function(unknown_symbol,foo6);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
error_message = "Failed to add function(" + unknown_symbol + ") in primary symbol table";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
error_message = "Indeterminable symbol type.";
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline bool run_test20()
|
inline bool run_test20()
|
||||||
{
|
{
|
||||||
typedef exprtk::expression<T> expression_t;
|
typedef exprtk::expression<T> expression_t;
|
||||||
|
|
||||||
for (std::size_t i = 0; i < 100; ++i)
|
|
||||||
{
|
{
|
||||||
exprtk::symbol_table<T> symbol_table0;
|
for (std::size_t i = 0; i < 100; ++i)
|
||||||
exprtk::symbol_table<T> symbol_table1;
|
|
||||||
exprtk::symbol_table<T> symbol_table2;
|
|
||||||
exprtk::symbol_table<T> symbol_table3;
|
|
||||||
|
|
||||||
symbol_table0.add_constants();
|
|
||||||
|
|
||||||
expression_t expression;
|
|
||||||
expression.register_symbol_table(symbol_table0);
|
|
||||||
expression.register_symbol_table(symbol_table1);
|
|
||||||
expression.register_symbol_table(symbol_table2);
|
|
||||||
expression.register_symbol_table(symbol_table3);
|
|
||||||
|
|
||||||
exprtk::parser<T> parser;
|
|
||||||
|
|
||||||
my_usr<T> musr;
|
|
||||||
musr.next_value(true);
|
|
||||||
parser.enable_unknown_symbol_resolver(&musr);
|
|
||||||
|
|
||||||
std::string expr_str = "v01+c02+v03+c04+v05+c06+v07+c08+v09+c10+"
|
|
||||||
"v11+c12+v13+c14+v15+c16+v17+c18+v19+c20+"
|
|
||||||
"v21+c22+v23+c24+v25+c26+v27+c28+v29+c30 ";
|
|
||||||
|
|
||||||
if (!parser.compile(expr_str,expression))
|
|
||||||
{
|
{
|
||||||
printf("run_test20() - Error: %s Expression: %s\n",
|
exprtk::symbol_table<T> symbol_table0; // primary symbol_table
|
||||||
parser.error().c_str(),
|
exprtk::symbol_table<T> symbol_table1;
|
||||||
expr_str.c_str());
|
exprtk::symbol_table<T> symbol_table2;
|
||||||
|
exprtk::symbol_table<T> symbol_table3;
|
||||||
|
|
||||||
return false;
|
symbol_table0.add_constants();
|
||||||
|
|
||||||
|
expression_t expression;
|
||||||
|
expression.register_symbol_table(symbol_table0);
|
||||||
|
expression.register_symbol_table(symbol_table1);
|
||||||
|
expression.register_symbol_table(symbol_table2);
|
||||||
|
expression.register_symbol_table(symbol_table3);
|
||||||
|
|
||||||
|
exprtk::parser<T> parser;
|
||||||
|
|
||||||
|
my_usr<T> musr;
|
||||||
|
musr.next_value(true);
|
||||||
|
parser.enable_unknown_symbol_resolver(&musr);
|
||||||
|
|
||||||
|
std::string expr_str = "v01+c02+v03+c04+v05+c06+v07+c08+v09+c10+"
|
||||||
|
"v11+c12+v13+c14+v15+c16+v17+c18+v19+c20+"
|
||||||
|
"v21+c22+v23+c24+v25+c26+v27+c28+v29+c30 ";
|
||||||
|
|
||||||
|
if (!parser.compile(expr_str,expression))
|
||||||
|
{
|
||||||
|
printf("run_test20() - [1] Error: %s Expression: %s\n",
|
||||||
|
parser.error().c_str(),
|
||||||
|
expr_str.c_str());
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
T sum_1_30 = T((1 + 30) * 15);
|
||||||
|
T result = expression.value();
|
||||||
|
|
||||||
|
if (sum_1_30 != result)
|
||||||
|
{
|
||||||
|
printf("run_test20() - [1] Error in evaluation! (1) Expression: %s\n",
|
||||||
|
expr_str.c_str());
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
T sum_1_30 = T((1 + 30) * 15);
|
{
|
||||||
T result = expression.value();
|
for (std::size_t i = 0; i < 100; ++i)
|
||||||
|
|
||||||
if (sum_1_30 != result)
|
|
||||||
{
|
{
|
||||||
printf("run_test20() - Error in evaluation! (1) Expression: %s\n",
|
exprtk::symbol_table<T> symbol_table0; // primary symbol_table
|
||||||
expr_str.c_str());
|
exprtk::symbol_table<T> symbol_table1;
|
||||||
|
exprtk::symbol_table<T> symbol_table2;
|
||||||
|
exprtk::symbol_table<T> symbol_table3;
|
||||||
|
|
||||||
return false;
|
symbol_table0.add_constants();
|
||||||
|
|
||||||
|
expression_t expression;
|
||||||
|
expression.register_symbol_table(symbol_table0);
|
||||||
|
expression.register_symbol_table(symbol_table1);
|
||||||
|
expression.register_symbol_table(symbol_table2);
|
||||||
|
expression.register_symbol_table(symbol_table3);
|
||||||
|
|
||||||
|
exprtk::parser<T> parser;
|
||||||
|
|
||||||
|
my_usr_ext<T> musr;
|
||||||
|
parser.enable_unknown_symbol_resolver(&musr);
|
||||||
|
|
||||||
|
std::string expr_str = "foo6(foo1(v0),foo2(c1,foo4(v2,c3,v4,c5)),foo3"
|
||||||
|
"(v6,c7,foo5(v8,c9,v10,c11,v12)),c13,v14,c15) ";
|
||||||
|
|
||||||
|
if (!parser.compile(expr_str,expression))
|
||||||
|
{
|
||||||
|
printf("run_test20() - [2] Error: %s Expression: %s\n",
|
||||||
|
parser.error().c_str(),
|
||||||
|
expr_str.c_str());
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
128
readme.txt
128
readme.txt
|
@ -84,7 +84,7 @@ arithmetic operations, functions and processes:
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
[SECTION 02 - EXAMPLE EXPRESSIONS]
|
[SECTION 02 - EXAMPLE EXPRESSIONS]
|
||||||
The following is a short listing of the types of mathematical
|
The following is a short listing of infix format based mathematical
|
||||||
expressions that can be parsed and evaluated using the ExprTk library.
|
expressions that can be parsed and evaluated using the ExprTk library.
|
||||||
|
|
||||||
(01) sqrt(1 - (3 / x^2))
|
(01) sqrt(1 - (3 / x^2))
|
||||||
|
@ -1316,7 +1316,7 @@ side-effects, however the latter, statement 5, is the final statement
|
||||||
in the expression and hence will be assumed to have a side-effect.
|
in the expression and hence will be assumed to have a side-effect.
|
||||||
|
|
||||||
During compilation when the DCE optimisation is applied to the above
|
During compilation when the DCE optimisation is applied to the above
|
||||||
expression, statement 2 will be removed from the expression, as it has
|
expression, statement 3 will be removed from the expression, as it has
|
||||||
no bearing on the final result of expression, the rest of the
|
no bearing on the final result of expression, the rest of the
|
||||||
statements will all remain. The optimised form of the expression is as
|
statements will all remain. The optimised form of the expression is as
|
||||||
follows:
|
follows:
|
||||||
|
@ -1358,7 +1358,7 @@ most imperative languages. There are two variations of the statement:
|
||||||
(a) If-Statement
|
(a) If-Statement
|
||||||
This version of the conditional statement returns the value of the
|
This version of the conditional statement returns the value of the
|
||||||
consequent expression when the condition expression is true, else it
|
consequent expression when the condition expression is true, else it
|
||||||
will require a quiet NaN value as its result.
|
will return a quiet NaN value as its result.
|
||||||
|
|
||||||
Example 1:
|
Example 1:
|
||||||
x := if (y < z) y + 3;
|
x := if (y < z) y + 3;
|
||||||
|
@ -2841,7 +2841,7 @@ simple user defined USR:
|
||||||
T& default_value,
|
T& default_value,
|
||||||
std::string& error_message)
|
std::string& error_message)
|
||||||
{
|
{
|
||||||
if (0 != unknown_symbol.find('var_'))
|
if (0 != unknown_symbol.find("var_"))
|
||||||
{
|
{
|
||||||
error_message = "Invalid symbol: " + unknown_symbol;
|
error_message = "Invalid symbol: " + unknown_symbol;
|
||||||
return false;
|
return false;
|
||||||
|
@ -2877,13 +2877,84 @@ simple user defined USR:
|
||||||
|
|
||||||
|
|
||||||
In the example above, a user specified USR is defined, and is
|
In the example above, a user specified USR is defined, and is
|
||||||
registered with the parser enabling the USR functionality. The when an
|
registered with the parser enabling the USR functionality. Then when
|
||||||
unknown symbol is encountered during the compilation process, the
|
an unknown symbol is encountered during the compilation process, the
|
||||||
USR's process method will be invoked. The USR in the example will only
|
USR's process method will be invoked. The USR in the example will only
|
||||||
'accept' unknown symbols that have a prefix of 'var_' as being valid
|
'accept' unknown symbols that have a prefix of 'var_' as being valid
|
||||||
variables, all other unknown symbols will result in a compilation
|
variables, all other unknown symbols will result in a compilation
|
||||||
error being raised.
|
error being raised.
|
||||||
|
|
||||||
|
In the example above the callback of the USR that is invoked during
|
||||||
|
the unknown symbol resolution process only allows for scalar variables
|
||||||
|
to be defined and resolved - as that is the simplest and most common
|
||||||
|
form.
|
||||||
|
|
||||||
|
There is also an extended version of the callback that can be
|
||||||
|
overridden that will allow for more control and choice over the type
|
||||||
|
of symbol being resolved. The following is an example definition of
|
||||||
|
said extended callback:
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct my_usr : public parser_t::unknown_symbol_resolver
|
||||||
|
{
|
||||||
|
typedef typename parser_t::unknown_symbol_resolver usr_t;
|
||||||
|
|
||||||
|
my_usr()
|
||||||
|
: usr_t(usr_t::e_usrmode_extended)
|
||||||
|
{}
|
||||||
|
|
||||||
|
virtual bool process(const std::string& unknown_symbol,
|
||||||
|
symbol_table_t& symbol_table,
|
||||||
|
std::string& error_message)
|
||||||
|
{
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
if (0 == unknown_symbol.find("var_"))
|
||||||
|
{
|
||||||
|
// Default value of zero
|
||||||
|
result = symbol_table.create_variable(unknown_symbol,0);
|
||||||
|
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
error_message = "Failed to create variable...";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (0 == unknown_symbol.find("str_"))
|
||||||
|
{
|
||||||
|
// Default value of empty string
|
||||||
|
result = symbol_table.create_stringvar(unknown_symbol,"");
|
||||||
|
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
error_message = "Failed to create string variable...";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
error_message = "Indeterminable symbol type.";
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
In the example above, the USR callback when invoked will pass the
|
||||||
|
primary symbol table associated with the expression being parsed. The
|
||||||
|
symbol resolution business logic can then determine under what
|
||||||
|
conditions a symbol will be resolved including its type (scalar,
|
||||||
|
string, vector etc) and default value. When the callback successfully
|
||||||
|
returns the symbol parsing and resolution process will again be
|
||||||
|
executed by the parser. The idea here is that given the primary symbol
|
||||||
|
table will now have the previously detected unknown symbol registered,
|
||||||
|
it will be correctly resolved and the general parsing processing can
|
||||||
|
then resume as per normal.
|
||||||
|
|
||||||
|
Note: In order to have the USR's extended mode callback be invoked It
|
||||||
|
is necessary to pass the e_usrmode_extended enum value during the
|
||||||
|
constructor of the user defined USR.
|
||||||
|
|
||||||
|
Note: The primary symbol table for an expression is the first symbol
|
||||||
|
table to be registered with that instance of the expression.
|
||||||
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
[SECTION 19 - ENABLING & DISABLING FEATURES]
|
[SECTION 19 - ENABLING & DISABLING FEATURES]
|
||||||
|
@ -4338,47 +4409,53 @@ disable certain features and capabilities. The defines can either be
|
||||||
part of a compiler command line switch or scoped around the include to
|
part of a compiler command line switch or scoped around the include to
|
||||||
the ExprTk header. The defines are as follows:
|
the ExprTk header. The defines are as follows:
|
||||||
|
|
||||||
(1) exprtk_enable_debugging
|
(01) exprtk_enable_debugging
|
||||||
(2) exprtk_disable_comments
|
(02) exprtk_disable_comments
|
||||||
(3) exprtk_disable_break_continue
|
(03) exprtk_disable_break_continue
|
||||||
(4) exprtk_disable_sc_andor
|
(04) exprtk_disable_sc_andor
|
||||||
(5) exprtk_disable_enhanced_features
|
(05) exprtk_disable_return_statement
|
||||||
(6) exprtk_disable_string_capabilities
|
(06) exprtk_disable_enhanced_features
|
||||||
(7) exprtk_disable_superscalar_unroll
|
(07) exprtk_disable_string_capabilities
|
||||||
(8) exprtk_disable_rtl_io_file
|
(08) exprtk_disable_superscalar_unroll
|
||||||
|
(09) exprtk_disable_rtl_io_file
|
||||||
|
(10) exprtk_disable_rtl_vecops
|
||||||
|
(11) exprtk_disable_caseinsensitivity
|
||||||
|
|
||||||
|
|
||||||
(1) exprtk_enable_debugging
|
(01) exprtk_enable_debugging
|
||||||
This define will enable printing of debug information to stdout during
|
This define will enable printing of debug information to stdout during
|
||||||
the compilation process.
|
the compilation process.
|
||||||
|
|
||||||
(2) exprtk_disable_comments
|
(02) exprtk_disable_comments
|
||||||
This define will disable the ability for expressions to have comments.
|
This define will disable the ability for expressions to have comments.
|
||||||
Expressions that have comments when parsed with a build that has this
|
Expressions that have comments when parsed with a build that has this
|
||||||
option, will result in a compilation failure.
|
option, will result in a compilation failure.
|
||||||
|
|
||||||
(3) exprtk_disable_break_continue
|
(03) exprtk_disable_break_continue
|
||||||
This define will disable the loop-wise 'break' and 'continue'
|
This define will disable the loop-wise 'break' and 'continue'
|
||||||
capabilities. Any expression that contains those keywords will result
|
capabilities. Any expression that contains those keywords will result
|
||||||
in a compilation failure.
|
in a compilation failure.
|
||||||
|
|
||||||
(4) exprtk_disable_sc_andor
|
(04) exprtk_disable_sc_andor
|
||||||
This define will disable the short-circuit '&' (and) and '|' (or)
|
This define will disable the short-circuit '&' (and) and '|' (or)
|
||||||
operators
|
operators
|
||||||
|
|
||||||
(5) exprtk_disable_enhanced_features
|
(05) exprtk_disable_return_statement
|
||||||
|
This define will disable use of return statements within expressions.
|
||||||
|
|
||||||
|
(06) exprtk_disable_enhanced_features
|
||||||
This define will disable all enhanced features such as strength
|
This define will disable all enhanced features such as strength
|
||||||
reduction and special function optimisations and expression specific
|
reduction and special function optimisations and expression specific
|
||||||
type instantiations. This feature will reduce compilation times and
|
type instantiations. This feature will reduce compilation times and
|
||||||
binary sizes but will also result in massive performance degradation
|
binary sizes but will also result in massive performance degradation
|
||||||
of expression evaluations.
|
of expression evaluations.
|
||||||
|
|
||||||
(6) exprtk_disable_string_capabilities
|
(07) exprtk_disable_string_capabilities
|
||||||
This define will disable all string processing capabilities. Any
|
This define will disable all string processing capabilities. Any
|
||||||
expression that contains a string or string related syntax will result
|
expression that contains a string or string related syntax will result
|
||||||
in a compilation failure.
|
in a compilation failure.
|
||||||
|
|
||||||
(7) exprtk_disable_superscalar_unroll
|
(08) exprtk_disable_superscalar_unroll
|
||||||
This define will set the loop unroll batch size to 4 operations per
|
This define will set the loop unroll batch size to 4 operations per
|
||||||
loop instead of the default 8 operations. This define is used in
|
loop instead of the default 8 operations. This define is used in
|
||||||
operations that involve vectors and aggregations over vectors. When
|
operations that involve vectors and aggregations over vectors. When
|
||||||
|
@ -4386,17 +4463,22 @@ targeting non-superscalar architectures, it may be recommended to
|
||||||
build using this particular option if efficiency of evaluations is of
|
build using this particular option if efficiency of evaluations is of
|
||||||
concern.
|
concern.
|
||||||
|
|
||||||
(8) exprtk_disable_rtl_io_file
|
(09) exprtk_disable_rtl_io_file
|
||||||
This define will disable the file I/O RTL package features. When
|
This define will disable the file I/O RTL package features. When
|
||||||
present, any attempts to register the file I/O package with a given
|
present, any attempts to register the file I/O package with a given
|
||||||
symbol table will fail causing a compilation error.
|
symbol table will fail causing a compilation error.
|
||||||
|
|
||||||
(9) exprtk_disable_rtl_vecops
|
(10) exprtk_disable_rtl_vecops
|
||||||
This define will disable the extended vector operations RTL package
|
This define will disable the extended vector operations RTL package
|
||||||
features. When present, any attempts to register the vector operations
|
features. When present, any attempts to register the vector operations
|
||||||
package with a given symbol table will fail causing a compilation
|
package with a given symbol table will fail causing a compilation
|
||||||
error.
|
error.
|
||||||
|
|
||||||
|
(11) exprtk_disable_caseinsensitivity
|
||||||
|
This define will disable case-insensitivity when matching variables
|
||||||
|
and functions. Furthermore all reserved and keywords will only be
|
||||||
|
acknowledged when in all lower-case.
|
||||||
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
[SECTION 28 - FILES]
|
[SECTION 28 - FILES]
|
||||||
|
|
Loading…
Reference in New Issue