private ushort ApplyOperation(ExpressionTokenParser.Tokens operation, ushort a, ushort b) { switch (operation) { case ExpressionTokenParser.Tokens.Plus: return (ushort)(a + b); case ExpressionTokenParser.Tokens.Minus: return (ushort)(b - a); case ExpressionTokenParser.Tokens.Asterisk: return (ushort)(a * b); } return 0; }
private bool HasPrecedence(ExpressionTokenParser.Tokens operator1, ExpressionTokenParser.Tokens operator2) { if (operator2 == ExpressionTokenParser.Tokens.Lparen || operator2 == ExpressionTokenParser.Tokens.Rparen) { return false; } if (operator1 == ExpressionTokenParser.Tokens.Asterisk && (operator2 == ExpressionTokenParser.Tokens.Plus || operator2 == ExpressionTokenParser.Tokens.Minus)) { return false; } return true; }