protected IPrimitiveToken EvaluateOperation(IPrimitiveToken x, IPrimitiveToken y, Tokens o) { switch(o) { case Tokens.EQ: return new BooleanToken(x.CompareTo(y) == 0); case Tokens.NEQ: return new BooleanToken(x.CompareTo(y) != 0); case Tokens.GT: return new BooleanToken(x.CompareTo(y) > 0); case Tokens.GEQ: return new BooleanToken(x.CompareTo(y) >= 0); case Tokens.LT: return new BooleanToken(x.CompareTo(y) < 0); case Tokens.LEQ: return new BooleanToken(x.CompareTo(y) <= 0); case Tokens.PLUS: return new NumberToken(x.ToDouble() + y.ToDouble()); case Tokens.MINUS: return new NumberToken(x.ToDouble() - y.ToDouble()); case Tokens.MULT: return new NumberToken(x.ToDouble() * y.ToDouble()); case Tokens.DIV: return new NumberToken(x.ToDouble() / y.ToDouble()); case Tokens.EXP: return new NumberToken(Math.Pow(x.ToDouble(), y.ToDouble())); case Tokens.CONCAT: return new StringToken(x.ToString() + y.ToString()); default: throw new ArgumentException("Unknown Operator"); } }
EvaluateOperation(IPrimitiveToken x, IPrimitiveToken y, Tokens o) { switch (o) { case Tokens.EQ: return(new BooleanToken(x.CompareTo(y) == 0)); case Tokens.NEQ: return(new BooleanToken(x.CompareTo(y) != 0)); case Tokens.GT: return(new BooleanToken(x.CompareTo(y) > 0)); case Tokens.GEQ: return(new BooleanToken(x.CompareTo(y) >= 0)); case Tokens.LT: return(new BooleanToken(x.CompareTo(y) < 0)); case Tokens.LEQ: return(new BooleanToken(x.CompareTo(y) <= 0)); case Tokens.PLUS: return(new NumberToken(x.ToDouble() + y.ToDouble())); case Tokens.MINUS: return(new NumberToken(x.ToDouble() - y.ToDouble())); case Tokens.MULT: return(new NumberToken(x.ToDouble() * y.ToDouble())); case Tokens.DIV: return(new NumberToken(x.ToDouble() / y.ToDouble())); case Tokens.EXP: return(new NumberToken(Math.Pow(x.ToDouble(), y.ToDouble()))); case Tokens.CONCAT: return(new StringToken(x.ToString() + y.ToString())); default: throw new ArgumentException("Unknown Operator"); } }