From d480769ca6510710333f609d404d4a0f82955930 Mon Sep 17 00:00:00 2001 From: orbitcowboy Date: Wed, 18 Mar 2015 13:42:40 +0100 Subject: [PATCH] Potential wrong evaluation of A and B or C or not(D). --- exprtk_simple_example_07.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/exprtk_simple_example_07.cpp b/exprtk_simple_example_07.cpp index aa949ee..c5b1828 100644 --- a/exprtk_simple_example_07.cpp +++ b/exprtk_simple_example_07.cpp @@ -25,12 +25,13 @@ template void logic() { typedef exprtk::expression expression_t; - std::string expression_string = "not(A and B) or C"; + std::string expression_string = "A and B or C or not(D)"; exprtk::symbol_table symbol_table; symbol_table.create_variable("A"); symbol_table.create_variable("B"); symbol_table.create_variable("C"); + symbol_table.create_variable("D"); expression_t expression; expression.register_symbol_table(symbol_table); @@ -38,24 +39,26 @@ void logic() exprtk::parser parser; parser.compile(expression_string,expression); - printf(" # | A | B | C | %s\n" - "---+---+---+---+-%s\n", + printf(" # | A | B | C | D | %s\n" + "----+---+---+---+---+ %s\n", expression_string.c_str(), std::string(expression_string.size(),'-').c_str()); - for (int i = 0; i < 8; ++i) + for (int i = 0; i < 16; ++i) { symbol_table.get_variable("A")->ref() = T(i & 0x01 ? 1 : 0); symbol_table.get_variable("B")->ref() = T(i & 0x02 ? 1 : 0); symbol_table.get_variable("C")->ref() = T(i & 0x04 ? 1 : 0); + symbol_table.get_variable("D")->ref() = T(i & 0x08 ? 1 : 0); int result = static_cast(expression.value()); - printf(" %d | %d | %d | %d | %d \n", + printf(" %2d | %d | %d | %d | %d | %d\n", i, static_cast(symbol_table.get_variable("A")->value()), static_cast(symbol_table.get_variable("B")->value()), static_cast(symbol_table.get_variable("C")->value()), + static_cast(symbol_table.get_variable("D")->value()), result); } }