Skip to content
Permalink
Browse files

ExpressionParser: Add multiplication and division operators. (divisio…

…n by zero evaluates as zero). Don't clamp result of addition operator. Clamping will be done later.
  • Loading branch information...
jordan-woyak committed Dec 30, 2018
1 parent f3192ca commit bf63f85d732db2fdab169823f2cf8a5fcbde0ec4
Showing with 24 additions and 1 deletion.
  1. +24 −1 Source/Core/InputCommon/ControlReference/ExpressionParser.cpp
@@ -28,6 +28,8 @@ enum TokenType
TOK_OR,
TOK_NOT,
TOK_ADD,
TOK_MUL,
TOK_DIV,
TOK_CONTROL,
TOK_LITERAL,
};
@@ -44,6 +46,10 @@ inline std::string OpName(TokenType op)
return "Not";
case TOK_ADD:
return "Add";
case TOK_MUL:
return "Mul";
case TOK_DIV:
return "Div";
default:
assert(false);
return "";
@@ -78,6 +84,10 @@ class Token
return "!";
case TOK_ADD:
return "+";
case TOK_MUL:
return "*";
case TOK_DIV:
return "/";
case TOK_CONTROL:
return "Device(" + data + ")";
case TOK_LITERAL:
@@ -170,6 +180,10 @@ class Lexer
return Token(TOK_NOT);
case '+':
return Token(TOK_ADD);
case '*':
return Token(TOK_MUL);
case '/':
return Token(TOK_DIV);
case '\'':
return GetLiteral();
case '`':
@@ -266,7 +280,14 @@ class BinaryExpression : public Expression
case TOK_OR:
return std::max(lhsValue, rhsValue);
case TOK_ADD:
return std::min(lhsValue + rhsValue, 1.0);
return lhsValue + rhsValue;
case TOK_MUL:
return lhsValue * rhsValue;
case TOK_DIV:
{
const ControlState result = lhsValue / rhsValue;
return std::isinf(result) ? 0.0 : result;
}
default:
assert(false);
return 0;
@@ -508,6 +529,8 @@ class Parser
case TOK_AND:
case TOK_OR:
case TOK_ADD:
case TOK_MUL:
case TOK_DIV:
return true;
default:
return false;

0 comments on commit bf63f85

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