ExpressionParser: Add less-than and greater-than operators.

This commit is contained in:
Jordan Woyak 2018-12-30 16:11:42 -06:00
parent 35e51ebbaa
commit 718efce1dc
1 changed files with 20 additions and 0 deletions

View File

@ -36,6 +36,8 @@ enum TokenType
TOK_DIV, TOK_DIV,
TOK_MOD, TOK_MOD,
TOK_ASSIGN, TOK_ASSIGN,
TOK_LTHAN,
TOK_GTHAN,
TOK_CONTROL, TOK_CONTROL,
TOK_LITERAL, TOK_LITERAL,
TOK_VARIABLE, TOK_VARIABLE,
@ -61,6 +63,10 @@ inline std::string OpName(TokenType op)
return "Mod"; return "Mod";
case TOK_ASSIGN: case TOK_ASSIGN:
return "Assign"; return "Assign";
case TOK_LTHAN:
return "LThan";
case TOK_GTHAN:
return "GThan";
case TOK_VARIABLE: case TOK_VARIABLE:
return "Var"; return "Var";
default: default:
@ -105,6 +111,10 @@ public:
return "%"; return "%";
case TOK_ASSIGN: case TOK_ASSIGN:
return "="; return "=";
case TOK_LTHAN:
return "<";
case TOK_GTHAN:
return ">";
case TOK_CONTROL: case TOK_CONTROL:
return "Device(" + data + ")"; return "Device(" + data + ")";
case TOK_LITERAL: case TOK_LITERAL:
@ -226,6 +236,10 @@ public:
return Token(TOK_MOD); return Token(TOK_MOD);
case '=': case '=':
return Token(TOK_ASSIGN); return Token(TOK_ASSIGN);
case '<':
return Token(TOK_LTHAN);
case '>':
return Token(TOK_GTHAN);
case '\'': case '\'':
return GetLiteral(); return GetLiteral();
case '$': case '$':
@ -348,6 +362,10 @@ public:
// TODO: Should this instead GetValue(lhs) ? // TODO: Should this instead GetValue(lhs) ?
return rhsValue; return rhsValue;
} }
case TOK_LTHAN:
return lhsValue < rhsValue;
case TOK_GTHAN:
return lhsValue > rhsValue;
default: default:
assert(false); assert(false);
return 0; return 0;
@ -733,6 +751,8 @@ private:
case TOK_DIV: case TOK_DIV:
case TOK_MOD: case TOK_MOD:
case TOK_ASSIGN: case TOK_ASSIGN:
case TOK_LTHAN:
case TOK_GTHAN:
return true; return true;
default: default:
return false; return false;