Skip to content
Permalink
Browse files

Merge pull request #8419 from jordan-woyak/xor-op

ExpressionParser: Add XOR operator.
  • Loading branch information...
lioncash committed Oct 24, 2019
2 parents 291c056 + 1fe4423 commit 6991b3928933d2cb276e137255c761d7883ffda6
@@ -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)
@@ -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 @@ class BinaryExpression : public Expression
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 @@ class Parser
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;
@@ -39,6 +39,7 @@ enum TokenType
TOK_LTHAN,
TOK_GTHAN,
TOK_COMMA,
TOK_XOR,
TOK_BINARY_OPS_END,
};

0 comments on commit 6991b39

Please sign in to comment.
You can’t perform that action at this time.