C++ Mathematical Expression Library (ExprTk) http://www.partow.net/programming/exprtk/index.html
This commit is contained in:
parent
e8cf66e55e
commit
36ef9e611f
105
Makefile
105
Makefile
|
@ -19,7 +19,7 @@ COMPILER = -c++
|
|||
#COMPILER = -clang
|
||||
OPTIMIZATION_OPT = -O1
|
||||
BASE_OPTIONS = -pedantic-errors -Wall -Wextra -Werror -Wno-long-long
|
||||
OPTIONS = $(BASE_OPTIONS) $(OPTIMIZATION_OPT) -o
|
||||
OPTIONS = $(BASE_OPTIONS) $(OPTIMIZATION_OPT)
|
||||
LINKER_OPT = -L/usr/lib -lstdc++ -lm
|
||||
|
||||
BUILD_LIST+=exprtk_test
|
||||
|
@ -41,106 +41,27 @@ BUILD_LIST+=exprtk_simple_example_14
|
|||
BUILD_LIST+=exprtk_simple_example_15
|
||||
BUILD_LIST+=exprtk_simple_example_16
|
||||
|
||||
|
||||
all: $(BUILD_LIST)
|
||||
|
||||
exprtk_test: exprtk_test.cpp exprtk.hpp
|
||||
$(COMPILER) $(OPTIONS) exprtk_test exprtk_test.cpp $(LINKER_OPT)
|
||||
$(BUILD_LIST) : %: %.cpp exprtk.hpp
|
||||
$(COMPILER) $(OPTIONS) -o $@ $@.cpp $(LINKER_OPT)
|
||||
|
||||
exprtk_benchmark: exprtk_benchmark.cpp exprtk.hpp
|
||||
$(COMPILER) $(OPTIONS) exprtk_benchmark exprtk_benchmark.cpp $(LINKER_OPT)
|
||||
strip_bin :
|
||||
@for f in $(BUILD_LIST); do if [ -f $$f ]; then strip -s $$f; echo $$f; fi done;
|
||||
|
||||
exprtk_simple_example_01: exprtk_simple_example_01.cpp exprtk.hpp
|
||||
$(COMPILER) $(OPTIONS) exprtk_simple_example_01 exprtk_simple_example_01.cpp $(LINKER_OPT)
|
||||
|
||||
exprtk_simple_example_02: exprtk_simple_example_02.cpp exprtk.hpp
|
||||
$(COMPILER) $(OPTIONS) exprtk_simple_example_02 exprtk_simple_example_02.cpp $(LINKER_OPT)
|
||||
|
||||
exprtk_simple_example_03: exprtk_simple_example_03.cpp exprtk.hpp
|
||||
$(COMPILER) $(OPTIONS) exprtk_simple_example_03 exprtk_simple_example_03.cpp $(LINKER_OPT)
|
||||
|
||||
exprtk_simple_example_04: exprtk_simple_example_04.cpp exprtk.hpp
|
||||
$(COMPILER) $(OPTIONS) exprtk_simple_example_04 exprtk_simple_example_04.cpp $(LINKER_OPT)
|
||||
|
||||
exprtk_simple_example_05: exprtk_simple_example_05.cpp exprtk.hpp
|
||||
$(COMPILER) $(OPTIONS) exprtk_simple_example_05 exprtk_simple_example_05.cpp $(LINKER_OPT)
|
||||
|
||||
exprtk_simple_example_06: exprtk_simple_example_06.cpp exprtk.hpp
|
||||
$(COMPILER) $(OPTIONS) exprtk_simple_example_06 exprtk_simple_example_06.cpp $(LINKER_OPT)
|
||||
|
||||
exprtk_simple_example_07: exprtk_simple_example_07.cpp exprtk.hpp
|
||||
$(COMPILER) $(OPTIONS) exprtk_simple_example_07 exprtk_simple_example_07.cpp $(LINKER_OPT)
|
||||
|
||||
exprtk_simple_example_08: exprtk_simple_example_08.cpp exprtk.hpp
|
||||
$(COMPILER) $(OPTIONS) exprtk_simple_example_08 exprtk_simple_example_08.cpp $(LINKER_OPT)
|
||||
|
||||
exprtk_simple_example_09: exprtk_simple_example_09.cpp exprtk.hpp
|
||||
$(COMPILER) $(OPTIONS) exprtk_simple_example_09 exprtk_simple_example_09.cpp $(LINKER_OPT)
|
||||
|
||||
exprtk_simple_example_10: exprtk_simple_example_10.cpp exprtk.hpp
|
||||
$(COMPILER) $(OPTIONS) exprtk_simple_example_10 exprtk_simple_example_10.cpp $(LINKER_OPT)
|
||||
|
||||
exprtk_simple_example_11: exprtk_simple_example_11.cpp exprtk.hpp
|
||||
$(COMPILER) $(OPTIONS) exprtk_simple_example_11 exprtk_simple_example_11.cpp $(LINKER_OPT)
|
||||
|
||||
exprtk_simple_example_12: exprtk_simple_example_12.cpp exprtk.hpp
|
||||
$(COMPILER) $(OPTIONS) exprtk_simple_example_12 exprtk_simple_example_12.cpp $(LINKER_OPT)
|
||||
|
||||
exprtk_simple_example_13: exprtk_simple_example_13.cpp exprtk.hpp
|
||||
$(COMPILER) $(OPTIONS) exprtk_simple_example_13 exprtk_simple_example_13.cpp $(LINKER_OPT)
|
||||
|
||||
exprtk_simple_example_14: exprtk_simple_example_14.cpp exprtk.hpp
|
||||
$(COMPILER) $(OPTIONS) exprtk_simple_example_14 exprtk_simple_example_14.cpp $(LINKER_OPT)
|
||||
|
||||
exprtk_simple_example_15: exprtk_simple_example_15.cpp exprtk.hpp
|
||||
$(COMPILER) $(OPTIONS) exprtk_simple_example_15 exprtk_simple_example_15.cpp $(LINKER_OPT)
|
||||
|
||||
exprtk_simple_example_16: exprtk_simple_example_16.cpp exprtk.hpp
|
||||
$(COMPILER) $(OPTIONS) exprtk_simple_example_16 exprtk_simple_example_16.cpp $(LINKER_OPT)
|
||||
valgrind :
|
||||
@for f in $(BUILD_LIST); do \
|
||||
if [ -f $$f ]; then \
|
||||
cmd="valgrind --leak-check=full --show-reachable=yes --track-origins=yes --log-file=$$f.log -v ./$$f"; \
|
||||
echo $$cmd; \
|
||||
$$cmd; \
|
||||
fi done;
|
||||
|
||||
pgo: exprtk_benchmark.cpp exprtk.hpp
|
||||
$(COMPILER) $(BASE_OPTIONS) -O3 -march=native -fprofile-generate -o exprtk_benchmark exprtk_benchmark.cpp $(LINKER_OPT)
|
||||
./exprtk_benchmark
|
||||
$(COMPILER) $(BASE_OPTIONS) -O3 -march=native -fprofile-use -o exprtk_benchmark exprtk_benchmark.cpp $(LINKER_OPT)
|
||||
|
||||
strip_bin:
|
||||
strip -s exprtk_test
|
||||
strip -s exprtk_benchmark
|
||||
strip -s exprtk_simple_example_01
|
||||
strip -s exprtk_simple_example_02
|
||||
strip -s exprtk_simple_example_03
|
||||
strip -s exprtk_simple_example_04
|
||||
strip -s exprtk_simple_example_05
|
||||
strip -s exprtk_simple_example_06
|
||||
strip -s exprtk_simple_example_07
|
||||
strip -s exprtk_simple_example_08
|
||||
strip -s exprtk_simple_example_09
|
||||
strip -s exprtk_simple_example_10
|
||||
strip -s exprtk_simple_example_11
|
||||
strip -s exprtk_simple_example_12
|
||||
strip -s exprtk_simple_example_13
|
||||
strip -s exprtk_simple_example_14
|
||||
strip -s exprtk_simple_example_15
|
||||
strip -s exprtk_simple_example_16
|
||||
|
||||
valgrind_check:
|
||||
valgrind --leak-check=full --show-reachable=yes --track-origins=yes --log-file=exprtk_test_valgrind.log -v ./exprtk_test
|
||||
valgrind --leak-check=full --show-reachable=yes --track-origins=yes --log-file=exprtk_benchmark_valgrind.log -v ./exprtk_benchmark
|
||||
valgrind --leak-check=full --show-reachable=yes --track-origins=yes --log-file=exprtk_simple_example_01_valgrind.log -v ./exprtk_simple_example_01
|
||||
valgrind --leak-check=full --show-reachable=yes --track-origins=yes --log-file=exprtk_simple_example_02_valgrind.log -v ./exprtk_simple_example_02
|
||||
valgrind --leak-check=full --show-reachable=yes --track-origins=yes --log-file=exprtk_simple_example_03_valgrind.log -v ./exprtk_simple_example_03
|
||||
valgrind --leak-check=full --show-reachable=yes --track-origins=yes --log-file=exprtk_simple_example_04_valgrind.log -v ./exprtk_simple_example_04
|
||||
valgrind --leak-check=full --show-reachable=yes --track-origins=yes --log-file=exprtk_simple_example_05_valgrind.log -v ./exprtk_simple_example_05
|
||||
valgrind --leak-check=full --show-reachable=yes --track-origins=yes --log-file=exprtk_simple_example_06_valgrind.log -v ./exprtk_simple_example_06
|
||||
valgrind --leak-check=full --show-reachable=yes --track-origins=yes --log-file=exprtk_simple_example_07_valgrind.log -v ./exprtk_simple_example_07
|
||||
valgrind --leak-check=full --show-reachable=yes --track-origins=yes --log-file=exprtk_simple_example_08_valgrind.log -v ./exprtk_simple_example_08
|
||||
valgrind --leak-check=full --show-reachable=yes --track-origins=yes --log-file=exprtk_simple_example_09_valgrind.log -v ./exprtk_simple_example_09
|
||||
valgrind --leak-check=full --show-reachable=yes --track-origins=yes --log-file=exprtk_simple_example_10_valgrind.log -v ./exprtk_simple_example_10
|
||||
valgrind --leak-check=full --show-reachable=yes --track-origins=yes --log-file=exprtk_simple_example_11_valgrind.log -v ./exprtk_simple_example_11
|
||||
valgrind --leak-check=full --show-reachable=yes --track-origins=yes --log-file=exprtk_simple_example_12_valgrind.log -v ./exprtk_simple_example_12
|
||||
valgrind --leak-check=full --show-reachable=yes --track-origins=yes --log-file=exprtk_simple_example_13_valgrind.log -v ./exprtk_simple_example_13
|
||||
valgrind --leak-check=full --show-reachable=yes --track-origins=yes --log-file=exprtk_simple_example_14_valgrind.log -v ./exprtk_simple_example_14
|
||||
valgrind --leak-check=full --show-reachable=yes --track-origins=yes --log-file=exprtk_simple_example_15_valgrind.log -v ./exprtk_simple_example_15
|
||||
valgrind --leak-check=full --show-reachable=yes --track-origins=yes --log-file=exprtk_simple_example_16_valgrind.log -v ./exprtk_simple_example_16
|
||||
|
||||
clean:
|
||||
rm -f core.* *~ *.o *.bak *stackdump gmon.out *.gcda *.gcno *.gcnor *.gch
|
||||
|
|
43
exprtk.hpp
43
exprtk.hpp
|
@ -2542,8 +2542,8 @@ namespace exprtk
|
|||
{
|
||||
lexer::token t = generator[i];
|
||||
printf("Token[%02d] @ %03d %6s --> '%s'\n",
|
||||
static_cast<unsigned int>(i),
|
||||
static_cast<unsigned int>(t.position),
|
||||
static_cast<int>(i),
|
||||
static_cast<int>(t.position),
|
||||
t.to_str(t.type).c_str(),
|
||||
t.value.c_str());
|
||||
}
|
||||
|
@ -3981,7 +3981,6 @@ namespace exprtk
|
|||
|
||||
private:
|
||||
|
||||
operator_type operation_;
|
||||
expression_ptr branch_;
|
||||
bool branch_deletable_;
|
||||
bool equality_;
|
||||
|
@ -6888,7 +6887,6 @@ namespace exprtk
|
|||
private:
|
||||
|
||||
vector_node<T>* vec_node_ptr_;
|
||||
vector_node<T>* vec1_node_ptr_;
|
||||
};
|
||||
|
||||
template <typename T, typename Operation>
|
||||
|
@ -6960,7 +6958,6 @@ namespace exprtk
|
|||
private:
|
||||
|
||||
vector_node<T>* vec_node_ptr_;
|
||||
vector_node<T>* vec1_node_ptr_;
|
||||
};
|
||||
|
||||
template <typename T, typename Operation>
|
||||
|
@ -12667,6 +12664,12 @@ namespace exprtk
|
|||
|
||||
struct type
|
||||
{
|
||||
type()
|
||||
: mode(parser_error::e_unknown),
|
||||
line_no(0),
|
||||
column_no(0)
|
||||
{}
|
||||
|
||||
lexer::token token;
|
||||
error_mode mode;
|
||||
std::string diagnostic;
|
||||
|
@ -12681,13 +12684,11 @@ namespace exprtk
|
|||
t.mode = mode;
|
||||
t.token.type = lexer::token::e_error;
|
||||
t.diagnostic = diagnostic;
|
||||
t.line_no = 0;
|
||||
t.column_no = 0;
|
||||
exprtk_debug(((diagnostic + "\n").c_str()));
|
||||
return t;
|
||||
}
|
||||
|
||||
inline type make_error(error_mode mode, const lexer::token tk, const std::string& diagnostic = "")
|
||||
inline type make_error(error_mode mode, const lexer::token& tk, const std::string& diagnostic = "")
|
||||
{
|
||||
type t;
|
||||
t.mode = mode;
|
||||
|
@ -12756,7 +12757,7 @@ namespace exprtk
|
|||
inline void dump_error(const type& error)
|
||||
{
|
||||
printf("Position: %02d Type: [%s] Msg: %s\n",
|
||||
static_cast<unsigned int>(error.token.position),
|
||||
static_cast<int>(error.token.position),
|
||||
exprtk::parser_error::to_str(error.mode).c_str(),
|
||||
error.diagnostic.c_str());
|
||||
}
|
||||
|
@ -12937,7 +12938,8 @@ namespace exprtk
|
|||
typedef parser<T> parser_t;
|
||||
|
||||
scope_element_manager(parser<T>& p)
|
||||
: parser_(p)
|
||||
: parser_(p),
|
||||
input_param_cnt_(0)
|
||||
{}
|
||||
|
||||
inline std::size_t size() const
|
||||
|
@ -14350,7 +14352,6 @@ namespace exprtk
|
|||
}
|
||||
}
|
||||
|
||||
std::string symbol = current_token_.value;
|
||||
if (result)
|
||||
{
|
||||
if (details::imatch(current_token_.value,"else"))
|
||||
|
@ -14942,8 +14943,6 @@ namespace exprtk
|
|||
std::vector<expression_node_ptr> arg_list;
|
||||
expression_node_ptr result = error_node();
|
||||
|
||||
const std::string symbol = current_token_.value;
|
||||
|
||||
if (!details::imatch(current_token_.value,"switch"))
|
||||
{
|
||||
set_error(
|
||||
|
@ -15077,8 +15076,6 @@ namespace exprtk
|
|||
std::vector<expression_node_ptr> arg_list;
|
||||
expression_node_ptr result = error_node();
|
||||
|
||||
const std::string symbol = current_token_.value;
|
||||
|
||||
if (!details::imatch(current_token_.value,"[*]"))
|
||||
{
|
||||
set_error(
|
||||
|
@ -15813,8 +15810,6 @@ namespace exprtk
|
|||
std::vector<expression_node_ptr> arg_list;
|
||||
expression_node_ptr result = error_node();
|
||||
|
||||
const std::string symbol = current_token_.value;
|
||||
|
||||
scoped_vec_delete<expression_node_t> sdd(*this,arg_list);
|
||||
|
||||
next_token();
|
||||
|
@ -16255,7 +16250,7 @@ namespace exprtk
|
|||
|
||||
exprtk_debug(("parse_define_vector_statement() - INFO - Added new local vector: %s[%d]\n",
|
||||
nse.name.c_str(),
|
||||
static_cast<unsigned int>(nse.size)));
|
||||
static_cast<int>(nse.size)));
|
||||
}
|
||||
|
||||
expression_node_ptr result =
|
||||
|
@ -16503,8 +16498,6 @@ namespace exprtk
|
|||
return error_node();
|
||||
}
|
||||
|
||||
var_node = nse.var_node;
|
||||
|
||||
exprtk_debug(("parse_uninitialised_var_statement() - INFO - Added new local variable: %s\n",nse.name.c_str()));
|
||||
}
|
||||
|
||||
|
@ -16734,8 +16727,8 @@ namespace exprtk
|
|||
|
||||
if (vararg_function)
|
||||
{
|
||||
expression_node_ptr vararg_func_node = error_node();
|
||||
vararg_func_node = parse_vararg_function_call(vararg_function,symbol);
|
||||
expression_node_ptr vararg_func_node =
|
||||
parse_vararg_function_call(vararg_function,symbol);
|
||||
|
||||
if (vararg_func_node)
|
||||
return vararg_func_node;
|
||||
|
@ -21576,7 +21569,7 @@ namespace exprtk
|
|||
return (synthesis_result) ? result : error_node();
|
||||
}
|
||||
// (v0 * c0) / (v1 / c1) --> (covov) (c0 * c1) * (v0 / v1)
|
||||
else if ((details::e_mul == o0) && (details::e_div == o1) && (details::e_mul == o2))
|
||||
else if ((details::e_mul == o0) && (details::e_div == o1) && (details::e_div == o2))
|
||||
{
|
||||
const bool synthesis_result =
|
||||
synthesize_sf3ext_expression::
|
||||
|
@ -21921,7 +21914,7 @@ namespace exprtk
|
|||
return (synthesis_result) ? result : error_node();
|
||||
}
|
||||
// (v0 * c0) / (c1 / v1) --> (covov) (c0 / c1) * (v0 * v1)
|
||||
else if ((details::e_mul == o0) && (details::e_mul == o1) && (details::e_mul == o2))
|
||||
else if ((details::e_mul == o0) && (details::e_div == o1) && (details::e_div == o2))
|
||||
{
|
||||
const bool synthesis_result =
|
||||
synthesize_sf3ext_expression::
|
||||
|
@ -25270,8 +25263,6 @@ namespace exprtk
|
|||
const Sequence<std::string,Allocator>& var_list)
|
||||
{
|
||||
const std::size_t n = var_list.size();
|
||||
std::vector<T*> v(n,0);
|
||||
std::vector<std::string> sv(n);
|
||||
|
||||
if (expr_map_.end() != expr_map_.find(name))
|
||||
return false;
|
||||
|
|
|
@ -511,7 +511,7 @@ void perform_file_based_benchmark(const std::string& file_name, const std::size_
|
|||
static_cast<int>(i + 1),
|
||||
static_cast<int>(expression_list.size()),
|
||||
(timer.time() * 1000000000.0) / (1.0 * rounds),
|
||||
static_cast<unsigned int>(timer.time() * 1000000000.0),
|
||||
static_cast<int>(timer.time() * 1000000000.0),
|
||||
sum,
|
||||
expr_str_list[i].c_str());
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ void fibonacci()
|
|||
x = i;
|
||||
T result = expression.value();
|
||||
printf("fibonacci(%3d) = %10.0f\n",
|
||||
static_cast<unsigned int>(i),
|
||||
static_cast<int>(i),
|
||||
result);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue