From e7d96c48ef68fe2532b7c3f093a3ec6356b2241f Mon Sep 17 00:00:00 2001 From: Arash Partow Date: Thu, 6 Apr 2017 08:26:48 +1000 Subject: [PATCH] C++ Mathematical Expression Library (ExprTk) http://www.partow.net/programming/exprtk/index.html --- exprtk.hpp | 49 ++++++++++++++++++++++++++++++------ exprtk_benchmark.cpp | 2 +- exprtk_simple_example_01.cpp | 2 +- exprtk_simple_example_02.cpp | 2 +- exprtk_simple_example_03.cpp | 2 +- exprtk_simple_example_04.cpp | 2 +- exprtk_simple_example_05.cpp | 2 +- exprtk_simple_example_06.cpp | 2 +- exprtk_simple_example_07.cpp | 2 +- exprtk_simple_example_08.cpp | 2 +- exprtk_simple_example_09.cpp | 2 +- exprtk_simple_example_10.cpp | 2 +- exprtk_simple_example_11.cpp | 2 +- exprtk_simple_example_12.cpp | 2 +- exprtk_simple_example_13.cpp | 2 +- exprtk_simple_example_14.cpp | 2 +- exprtk_simple_example_15.cpp | 2 +- exprtk_simple_example_16.cpp | 2 +- exprtk_simple_example_17.cpp | 2 +- exprtk_simple_example_18.cpp | 2 +- exprtk_simple_example_19.cpp | 2 +- exprtk_test.cpp | 2 +- readme.txt | 41 +++++++++++++++++------------- 23 files changed, 85 insertions(+), 47 deletions(-) diff --git a/exprtk.hpp b/exprtk.hpp index c29cd08..f942a2c 100644 --- a/exprtk.hpp +++ b/exprtk.hpp @@ -2,7 +2,7 @@ ****************************************************************** * C++ Mathematical Expression Toolkit Library * * * - * Author: Arash Partow (1999-2017) * + * Author: Arash Partow (1999-2017) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * @@ -409,7 +409,7 @@ namespace exprtk static const std::string cntrl_struct_list[] = { - "if", "switch", "for", "while", "repeat" + "if", "switch", "for", "while", "repeat", "return" }; static const std::size_t cntrl_struct_list_size = sizeof(cntrl_struct_list) / sizeof(std::string); @@ -4207,11 +4207,13 @@ namespace exprtk return std::string(view.begin(),view.size()); } + #ifndef exprtk_disable_return_statement namespace details { template class return_node; template class return_envelope_node; } + #endif template class results_context @@ -4261,8 +4263,10 @@ namespace exprtk bool results_available_; ts_list_t parameter_list_; + #ifndef exprtk_disable_return_statement friend class details::return_node; friend class details::return_envelope_node; + #endif }; namespace details @@ -11526,6 +11530,7 @@ namespace exprtk } }; + #ifndef exprtk_disable_return_statement template class return_node : public generic_function_node > { @@ -11626,6 +11631,7 @@ namespace exprtk expression_ptr body_; bool body_deletable_; }; + #endif #define exprtk_define_unary_op(OpName) \ template \ @@ -18889,7 +18895,8 @@ namespace exprtk e_ctrl_switch, e_ctrl_for_loop, e_ctrl_while_loop, - e_ctrl_repeat_loop + e_ctrl_repeat_loop, + e_ctrl_return }; enum settings_logic_opr @@ -24003,6 +24010,7 @@ namespace exprtk return result; } + #ifndef exprtk_disable_return_statement inline expression_node_ptr parse_return_statement() { if (state_.parsing_return_stmt) @@ -24112,6 +24120,12 @@ namespace exprtk return result; } + #else + inline expression_node_ptr parse_return_statement() + { + return error_node(); + } + #endif inline bool post_variable_process(const std::string& symbol) { @@ -24522,7 +24536,10 @@ namespace exprtk { return parse_swap_statement(); } - else if (details::imatch(current_token().value,symbol_return)) + else if ( + details::imatch(current_token().value,symbol_return) && + settings_.control_struct_enabled(current_token().value) + ) { return parse_return_statement(); } @@ -26522,6 +26539,7 @@ namespace exprtk } #endif + #ifndef exprtk_disable_return_statement inline expression_node_ptr return_call(std::vector& arg_list) { if (!all_nodes_valid(arg_list)) @@ -26565,6 +26583,19 @@ namespace exprtk return result; } + #else + inline expression_node_ptr return_call(std::vector&) + { + return error_node(); + } + + inline expression_node_ptr return_envelope(expression_node_ptr, + results_context_t*, + bool*&) + { + return error_node(); + } + #endif inline expression_node_ptr vector_element(const std::string& symbol, vector_holder_ptr vector_base, @@ -33518,6 +33549,7 @@ namespace exprtk inline void return_cleanup() { + #ifndef exprtk_disable_return_statement if (results_context_) { delete results_context_; @@ -33525,6 +33557,7 @@ namespace exprtk } state_.return_stmt_present = false; + #endif } private: @@ -36619,7 +36652,7 @@ namespace exprtk vector_t vec(parameters[0]); T increment = scalar_t(parameters[1])(); - T base = ((1 == ps_index) || (3 == ps_index))? scalar_t(parameters[2])() : T(0); + T base = ((1 == ps_index) || (3 == ps_index)) ? scalar_t(parameters[2])() : T(0); std::size_t r0 = 0; std::size_t r1 = vec.size() - 1; @@ -37097,9 +37130,9 @@ namespace exprtk namespace information { static const char* library = "Mathematical Expression Toolkit"; - static const char* version = "2.718281828459045235360287471352662497757247" - "09369995957496696762772407663035354759457138"; - static const char* date = "20170107"; + static const char* version = "2.71828182845904523536028747135266249775724709" + "3699959574966967627724076630353547594571382178"; + static const char* date = "20170404"; static inline std::string data() { diff --git a/exprtk_benchmark.cpp b/exprtk_benchmark.cpp index a38da99..6cb8167 100644 --- a/exprtk_benchmark.cpp +++ b/exprtk_benchmark.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * ExprTk vs Native Benchmarks * - * Author: Arash Partow (1999-2017) * + * Author: Arash Partow (1999-2017) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * diff --git a/exprtk_simple_example_01.cpp b/exprtk_simple_example_01.cpp index 3bd9a26..4c0037b 100644 --- a/exprtk_simple_example_01.cpp +++ b/exprtk_simple_example_01.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 1 * - * Author: Arash Partow (1999-2017) * + * Author: Arash Partow (1999-2017) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * diff --git a/exprtk_simple_example_02.cpp b/exprtk_simple_example_02.cpp index 0b3477b..cb18b35 100644 --- a/exprtk_simple_example_02.cpp +++ b/exprtk_simple_example_02.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 2 * - * Author: Arash Partow (1999-2017) * + * Author: Arash Partow (1999-2017) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * diff --git a/exprtk_simple_example_03.cpp b/exprtk_simple_example_03.cpp index a7e7947..16b627f 100644 --- a/exprtk_simple_example_03.cpp +++ b/exprtk_simple_example_03.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 3 * - * Author: Arash Partow (1999-2017) * + * Author: Arash Partow (1999-2017) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * diff --git a/exprtk_simple_example_04.cpp b/exprtk_simple_example_04.cpp index 7830a13..7cf9393 100644 --- a/exprtk_simple_example_04.cpp +++ b/exprtk_simple_example_04.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 4 * - * Author: Arash Partow (1999-2017) * + * Author: Arash Partow (1999-2017) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * diff --git a/exprtk_simple_example_05.cpp b/exprtk_simple_example_05.cpp index fa3a67e..a4dbe0c 100644 --- a/exprtk_simple_example_05.cpp +++ b/exprtk_simple_example_05.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 5 * - * Author: Arash Partow (1999-2017) * + * Author: Arash Partow (1999-2017) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * diff --git a/exprtk_simple_example_06.cpp b/exprtk_simple_example_06.cpp index 6566be5..9a5c431 100644 --- a/exprtk_simple_example_06.cpp +++ b/exprtk_simple_example_06.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 6 * - * Author: Arash Partow (1999-2017) * + * Author: Arash Partow (1999-2017) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * diff --git a/exprtk_simple_example_07.cpp b/exprtk_simple_example_07.cpp index 76d02fa..9f50b6d 100644 --- a/exprtk_simple_example_07.cpp +++ b/exprtk_simple_example_07.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 7 * - * Author: Arash Partow (1999-2017) * + * Author: Arash Partow (1999-2017) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * diff --git a/exprtk_simple_example_08.cpp b/exprtk_simple_example_08.cpp index e263bce..a785d82 100644 --- a/exprtk_simple_example_08.cpp +++ b/exprtk_simple_example_08.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 8 * - * Author: Arash Partow (1999-2017) * + * Author: Arash Partow (1999-2017) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * diff --git a/exprtk_simple_example_09.cpp b/exprtk_simple_example_09.cpp index 69f45c2..469c910 100644 --- a/exprtk_simple_example_09.cpp +++ b/exprtk_simple_example_09.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 9 * - * Author: Arash Partow (1999-2017) * + * Author: Arash Partow (1999-2017) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * diff --git a/exprtk_simple_example_10.cpp b/exprtk_simple_example_10.cpp index 006fc2a..43cb0b1 100644 --- a/exprtk_simple_example_10.cpp +++ b/exprtk_simple_example_10.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 10 * - * Author: Arash Partow (1999-2017) * + * Author: Arash Partow (1999-2017) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * diff --git a/exprtk_simple_example_11.cpp b/exprtk_simple_example_11.cpp index fe87553..c6c4daf 100644 --- a/exprtk_simple_example_11.cpp +++ b/exprtk_simple_example_11.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 11 * - * Author: Arash Partow (1999-2017) * + * Author: Arash Partow (1999-2017) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * diff --git a/exprtk_simple_example_12.cpp b/exprtk_simple_example_12.cpp index 162a9ad..5acea5f 100644 --- a/exprtk_simple_example_12.cpp +++ b/exprtk_simple_example_12.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 12 * - * Author: Arash Partow (1999-2017) * + * Author: Arash Partow (1999-2017) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * diff --git a/exprtk_simple_example_13.cpp b/exprtk_simple_example_13.cpp index 1dfa1e5..ec9d3b1 100644 --- a/exprtk_simple_example_13.cpp +++ b/exprtk_simple_example_13.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 13 * - * Author: Arash Partow (1999-2017) * + * Author: Arash Partow (1999-2017) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * diff --git a/exprtk_simple_example_14.cpp b/exprtk_simple_example_14.cpp index c07c4b3..ec7e66a 100644 --- a/exprtk_simple_example_14.cpp +++ b/exprtk_simple_example_14.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 14 * - * Author: Arash Partow (1999-2017) * + * Author: Arash Partow (1999-2017) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * diff --git a/exprtk_simple_example_15.cpp b/exprtk_simple_example_15.cpp index 830a1af..e3a1ec2 100644 --- a/exprtk_simple_example_15.cpp +++ b/exprtk_simple_example_15.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 15 * - * Author: Arash Partow (1999-2017) * + * Author: Arash Partow (1999-2017) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * diff --git a/exprtk_simple_example_16.cpp b/exprtk_simple_example_16.cpp index 512bc8c..ffad092 100644 --- a/exprtk_simple_example_16.cpp +++ b/exprtk_simple_example_16.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 16 * - * Author: Arash Partow (1999-2017) * + * Author: Arash Partow (1999-2017) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * diff --git a/exprtk_simple_example_17.cpp b/exprtk_simple_example_17.cpp index 94e3bf2..300aaed 100644 --- a/exprtk_simple_example_17.cpp +++ b/exprtk_simple_example_17.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 17 * - * Author: Arash Partow (1999-2017) * + * Author: Arash Partow (1999-2017) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * diff --git a/exprtk_simple_example_18.cpp b/exprtk_simple_example_18.cpp index a02663f..54e1775 100644 --- a/exprtk_simple_example_18.cpp +++ b/exprtk_simple_example_18.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 18 * - * Author: Arash Partow (1999-2017) * + * Author: Arash Partow (1999-2017) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * diff --git a/exprtk_simple_example_19.cpp b/exprtk_simple_example_19.cpp index a173df7..e088ecc 100644 --- a/exprtk_simple_example_19.cpp +++ b/exprtk_simple_example_19.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 19 * - * Author: Arash Partow (1999-2017) * + * Author: Arash Partow (1999-2017) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * diff --git a/exprtk_test.cpp b/exprtk_test.cpp index d55cfdf..ab3c06c 100644 --- a/exprtk_test.cpp +++ b/exprtk_test.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Examples and Unit-Tests * - * Author: Arash Partow (1999-2017) * + * Author: Arash Partow (1999-2017) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * diff --git a/readme.txt b/readme.txt index 39dc5b2..210418f 100644 --- a/readme.txt +++ b/readme.txt @@ -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. 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 statements will all remain. The optimised form of the expression is as follows: @@ -1325,7 +1325,7 @@ follows: var y := x + 2; // Statement 2 y := x + 3y; // Statement 3 x - y; // Statement 4 - +8 (3) Conditional Statements (If-Then-Else) ExprTk support two forms of conditional branching or otherwise known @@ -1358,7 +1358,7 @@ most imperative languages. There are two variations of the statement: (a) If-Statement This version of the conditional statement returns the value of the 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: x := if (y < z) y + 3; @@ -2877,8 +2877,8 @@ simple user defined USR: In the example above, a user specified USR is defined, and is -registered with the parser enabling the USR functionality. The when an -unknown symbol is encountered during the compilation process, the +registered with the parser enabling the USR functionality. Then when +an unknown symbol is encountered during the compilation process, the 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 variables, all other unknown symbols will result in a compilation @@ -4338,14 +4338,16 @@ disable certain features and capabilities. The defines can either be part of a compiler command line switch or scoped around the include to the ExprTk header. The defines are as follows: - (1) exprtk_enable_debugging - (2) exprtk_disable_comments - (3) exprtk_disable_break_continue - (4) exprtk_disable_sc_andor - (5) exprtk_disable_enhanced_features - (6) exprtk_disable_string_capabilities - (7) exprtk_disable_superscalar_unroll - (8) exprtk_disable_rtl_io_file + (01) exprtk_enable_debugging + (02) exprtk_disable_comments + (03) exprtk_disable_break_continue + (04) exprtk_disable_sc_andor + (05) exprtk_disable_return_statement + (06) exprtk_disable_enhanced_features + (07) exprtk_disable_string_capabilities + (08) exprtk_disable_superscalar_unroll + (09) exprtk_disable_rtl_io_file + (10) exprtk_disable_rtl_vecops (1) exprtk_enable_debugging @@ -4366,19 +4368,22 @@ in a compilation failure. This define will disable the short-circuit '&' (and) and '|' (or) operators -(5) exprtk_disable_enhanced_features +(5) exprtk_disable_return_statement +This define will disable use of return statements within expressions. + +(6) exprtk_disable_enhanced_features This define will disable all enhanced features such as strength reduction and special function optimisations and expression specific type instantiations. This feature will reduce compilation times and binary sizes but will also result in massive performance degradation of expression evaluations. -(6) exprtk_disable_string_capabilities +(7) exprtk_disable_string_capabilities This define will disable all string processing capabilities. Any expression that contains a string or string related syntax will result in a compilation failure. -(7) exprtk_disable_superscalar_unroll +(8) exprtk_disable_superscalar_unroll 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 operations that involve vectors and aggregations over vectors. When @@ -4386,12 +4391,12 @@ targeting non-superscalar architectures, it may be recommended to build using this particular option if efficiency of evaluations is of concern. -(8) exprtk_disable_rtl_io_file +(9) exprtk_disable_rtl_io_file 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 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 features. When present, any attempts to register the vector operations package with a given symbol table will fail causing a compilation