Fix order of operations for prefix and '*', '/'

The problem is that Prefix did not properly participate in
operator precedence. I've fixed this, at least for the moment,
by adding a final depth of precedence that can be called when
the depth gets to the bottom.

closes #285
This commit is contained in:
Jason Turner 2016-10-06 14:41:45 -06:00
parent 21495ebb40
commit 8b7fe33bf1
2 changed files with 10 additions and 3 deletions

View File

@ -219,6 +219,10 @@ namespace chaiscript
m_operators.emplace_back(AST_Node_Type::Multiplication);
m_operator_matches.emplace_back(std::initializer_list<std::string>({"*", "/", "%"}));
// Prefix placeholder
m_operators.emplace_back(AST_Node_Type::Prefix);
m_operator_matches.emplace_back(std::initializer_list<std::string>({}));
for (auto & elem : m_alphabet) {
std::fill(std::begin(elem), std::end(elem), false);
}
@ -2197,7 +2201,7 @@ namespace chaiscript
bool retval = false;
const auto prev_stack_top = m_match_stack.size();
if (t_precedence < m_operators.size()) {
if (m_operators[t_precedence] != AST_Node_Type::Prefix) {
if (Operator(t_precedence+1)) {
retval = true;
if (Operator_Helper(t_precedence)) {
@ -2257,8 +2261,7 @@ namespace chaiscript
} while (Operator_Helper(t_precedence));
}
}
}
else {
} else {
return Value();
}

View File

@ -0,0 +1,4 @@
var i = 2;
assert_equal(++i * i, 9)