ExpressionParser: Add XOR operator.

This commit is contained in:
Jordan Woyak 2019-10-20 09:51:19 -05:00
parent 6282b0d83e
commit 1fe44238b1
3 changed files with 15 additions and 3 deletions

View File

@ -234,6 +234,7 @@ void IOWindow::CreateMainLayout()
m_operators_combo->addItem(tr("> Greater-than"));
m_operators_combo->addItem(tr("< Less-than"));
m_operators_combo->addItem(tr("& And"));
m_operators_combo->addItem(tr("^ Xor"));
}
m_operators_combo->addItem(tr("| Or"));
if (m_type == Type::Input)

View File

@ -136,6 +136,8 @@ Token Lexer::NextToken()
return Token(TOK_GTHAN);
case ',':
return Token(TOK_COMMA);
case '^':
return Token(TOK_XOR);
case '\'':
return GetDelimitedLiteral();
case '$':
@ -278,6 +280,12 @@ public:
lhs->GetValue();
return rhs->GetValue();
}
case TOK_XOR:
{
const auto lval = lhs->GetValue();
const auto rval = rhs->GetValue();
return std::max(std::min(1 - lval, rval), std::min(lval, 1 - rval));
}
default:
assert(false);
return 0;
@ -621,12 +629,14 @@ private:
return 3;
case TOK_AND:
return 4;
case TOK_OR:
case TOK_XOR:
return 5;
case TOK_ASSIGN:
case TOK_OR:
return 6;
case TOK_COMMA:
case TOK_ASSIGN:
return 7;
case TOK_COMMA:
return 8;
default:
assert(false);
return 0;

View File

@ -39,6 +39,7 @@ enum TokenType
TOK_LTHAN,
TOK_GTHAN,
TOK_COMMA,
TOK_XOR,
TOK_BINARY_OPS_END,
};