Merge d480769ca6
into 73b1e4c9f3
This commit is contained in:
commit
dcc0702e2b
|
@ -25,12 +25,13 @@ template <typename T>
|
||||||
void logic()
|
void logic()
|
||||||
{
|
{
|
||||||
typedef exprtk::expression<T> expression_t;
|
typedef exprtk::expression<T> 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<T> symbol_table;
|
exprtk::symbol_table<T> symbol_table;
|
||||||
symbol_table.create_variable("A");
|
symbol_table.create_variable("A");
|
||||||
symbol_table.create_variable("B");
|
symbol_table.create_variable("B");
|
||||||
symbol_table.create_variable("C");
|
symbol_table.create_variable("C");
|
||||||
|
symbol_table.create_variable("D");
|
||||||
|
|
||||||
expression_t expression;
|
expression_t expression;
|
||||||
expression.register_symbol_table(symbol_table);
|
expression.register_symbol_table(symbol_table);
|
||||||
|
@ -38,24 +39,26 @@ void logic()
|
||||||
exprtk::parser<T> parser;
|
exprtk::parser<T> parser;
|
||||||
parser.compile(expression_string,expression);
|
parser.compile(expression_string,expression);
|
||||||
|
|
||||||
printf(" # | A | B | C | %s\n"
|
printf(" # | A | B | C | D | %s\n"
|
||||||
"---+---+---+---+-%s\n",
|
"----+---+---+---+---+ %s\n",
|
||||||
expression_string.c_str(),
|
expression_string.c_str(),
|
||||||
std::string(expression_string.size(),'-').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("A")->ref() = T(i & 0x01 ? 1 : 0);
|
||||||
symbol_table.get_variable("B")->ref() = T(i & 0x02 ? 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("C")->ref() = T(i & 0x04 ? 1 : 0);
|
||||||
|
symbol_table.get_variable("D")->ref() = T(i & 0x08 ? 1 : 0);
|
||||||
|
|
||||||
int result = static_cast<int>(expression.value());
|
int result = static_cast<int>(expression.value());
|
||||||
|
|
||||||
printf(" %d | %d | %d | %d | %d \n",
|
printf(" %2d | %d | %d | %d | %d | %d\n",
|
||||||
i,
|
i,
|
||||||
static_cast<int>(symbol_table.get_variable("A")->value()),
|
static_cast<int>(symbol_table.get_variable("A")->value()),
|
||||||
static_cast<int>(symbol_table.get_variable("B")->value()),
|
static_cast<int>(symbol_table.get_variable("B")->value()),
|
||||||
static_cast<int>(symbol_table.get_variable("C")->value()),
|
static_cast<int>(symbol_table.get_variable("C")->value()),
|
||||||
|
static_cast<int>(symbol_table.get_variable("D")->value()),
|
||||||
result);
|
result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue