public override Object PerformOperation(Executer exec, Operator op, Object otherTerm) { if (op == null) return this; this.CheckOperation(op); string sReturn = ""; string sThis = (string)this.GetUnboxed(exec); string sOther = otherTerm.GetUnboxed(exec).ToString(); switch (op.InternalTokens) { case "+": sReturn = sThis + sOther; break; case "-": sReturn = sThis.Replace(sOther, ""); break; case "*": for (int i = Convert.ToInt32(sOther)-1; i>=0; i--) sReturn+=sThis; break; } //this.m_value = sReturn; //return this; return Types.Object.CreateType(sReturn); }
public override Object PerformOperation(Executer exec, Operator op, Object otherTerm) { if (op == null) { return(this); } this.CheckOperation(op); string sReturn = ""; string sThis = (string)this.GetUnboxed(exec); string sOther = otherTerm.GetUnboxed(exec).ToString(); switch (op.InternalTokens) { case "+": sReturn = sThis + sOther; break; case "-": sReturn = sThis.Replace(sOther, ""); break; case "*": for (int i = Convert.ToInt32(sOther) - 1; i >= 0; i--) { sReturn += sThis; } break; } //this.m_value = sReturn; //return this; return(Types.Object.CreateType(sReturn)); }
public override Object PerformOperation(Executer exec, Operator op, Object otherTerm) { if (op == null) { return(this); } if (op.InternalTokens == ".") { object oUnboxed = null; oUnboxed = this.Evaluate(exec).GetUnboxed(exec); if (otherTerm.GetType() == typeof(Method)) { Method func = (Method)otherTerm; func.BelongsToObject = oUnboxed; return(func.Evaluate(exec)); } if (otherTerm.GetType() == typeof(Variable)) { Variable var = (Variable)otherTerm; var.BelongsToObject = oUnboxed; var.EvaluateToWrapper(exec); return(var); } return(null); } if (op.IsSettingOperator) { this.EvaluateToWrapper(exec); if (!op.IsBinary) { //TODO: ++ and -- operators return(this); } Object oNewVal = otherTerm.Evaluate(exec); if (op.InternalTokens != "=") { //for other than "=", we need to know the current value string sSubOp = op.InternalTokens.Substring(0, 1); Operator subOp = Parser.GetOperator(sSubOp); this.PerformOperation(exec, op, oNewVal); oNewVal = this; } this.ValueWrapper.Value = oNewVal.GetUnboxed(exec); return(oNewVal); } Object oEvaluated = this.Evaluate(exec); return(oEvaluated.PerformOperation(exec, op, otherTerm)); }
/// <summary> /// Get the dotnet value /// </summary> /// <returns></returns> public virtual object GetUnboxed(Executer exec) { //Methods and Variables have no value, they must be evaluated into basic types first: if (this.IsNull) { return(null); } if (this.m_value == null) { Object o = this.Evaluate(exec); return(o.GetUnboxed(exec)); } return(this.m_value); }
public override Object PerformOperation(Executer exec, Operator op, Object otherTerm) { if (op == null) return this; this.CheckOperation(op); double dReturn = 0; double dThis = Convert.ToDouble(this.GetUnboxed(exec)); if (op.IsBinary) { double dOther = Convert.ToDouble(otherTerm.GetUnboxed(exec)); switch (op.InternalTokens) { case "+": dReturn = dThis + dOther; break; case "-": dReturn = dThis - dOther; break; case "*": dReturn = dThis * dOther; break; case "/": dReturn = dThis / dOther; break; case "==": return Types.Object.CreateType(dThis == dOther); case ">=": return Types.Object.CreateType(dThis >= dOther); case "<=": return Types.Object.CreateType(dThis <= dOther); case ">": return Types.Object.CreateType(dThis > dOther); case "<": return Types.Object.CreateType(dThis < dOther); case "!=": return Types.Object.CreateType(dThis != dOther); } } else //unary { switch (op.InternalTokens) { case "pre-": dReturn=-dThis; break; } } System.Type type = this.GetType(); //Nope - never change the actual value, instead return a new object with the value! // if (type == typeof(Int)) // this.m_value = (int)dReturn; // else if (type == typeof(Float)) // this.m_value = (float)dReturn; // return this; if (type == typeof(Int)) return Types.Object.CreateType((int)dReturn); else if (type == typeof(Float)) return Types.Object.CreateType((float)dReturn); throw new Exception("Unknown number type"); }
public override Object PerformOperation(Executer exec, Operator op, Object otherTerm) { if (op == null) { return(this); } this.CheckOperation(op); double dReturn = 0; double dThis = Convert.ToDouble(this.GetUnboxed(exec)); if (op.IsBinary) { double dOther = Convert.ToDouble(otherTerm.GetUnboxed(exec)); switch (op.InternalTokens) { case "+": dReturn = dThis + dOther; break; case "-": dReturn = dThis - dOther; break; case "*": dReturn = dThis * dOther; break; case "/": dReturn = dThis / dOther; break; case "==": return(Types.Object.CreateType(dThis == dOther)); case ">=": return(Types.Object.CreateType(dThis >= dOther)); case "<=": return(Types.Object.CreateType(dThis <= dOther)); case ">": return(Types.Object.CreateType(dThis > dOther)); case "<": return(Types.Object.CreateType(dThis < dOther)); case "!=": return(Types.Object.CreateType(dThis != dOther)); } } else //unary { switch (op.InternalTokens) { case "pre-": dReturn = -dThis; break; } } System.Type type = this.GetType(); //Nope - never change the actual value, instead return a new object with the value! // if (type == typeof(Int)) // this.m_value = (int)dReturn; // else if (type == typeof(Float)) // this.m_value = (float)dReturn; // return this; if (type == typeof(Int)) { return(Types.Object.CreateType((int)dReturn)); } else if (type == typeof(Float)) { return(Types.Object.CreateType((float)dReturn)); } throw new Exception("Unknown number type"); }