public ArithmeticExpression MakeArithmeticExperssion(SubExpressionType expression) { ArithmeticExpression arithmeticExpression = new ArithmeticExpression(); arithmeticExpression.AddSubExpression(expression); return(arithmeticExpression); }
string GetSubExpressionString(SubExpressionType exp) { string retVal; ArithemticOperator op = exp.GetArithmeticOperator(); string lhs = GetArithmeticExpressionString(exp.GetLHSArithmeticExpression()); string rhs = GetArithmeticExpressionString(exp.GetRHSArithmeticExpression()); string opString = ""; //Add if (op.HasAdd()) { opString = "+"; } //Subtract else if (op.HasSubtract()) { opString = "-"; } //Divide else if (op.HasDivide()) { opString = "/"; } //Multiply else if (op.HasMultiply()) { opString = "*"; } //Power else if (op.HasPower()) { opString = "^"; } //Log : assumes that RHS is the base and LHS is the number. else if (op.HasLog()) { opString = "log"; } retVal = lhs + " " + opString + " " + rhs; return(retVal); }
NodeBase CreateMathNode(SubExpressionType exp) { ArithemticOperator op = exp.GetArithmeticOperator(); OperationType operationType = OperationType.ADD; //Add if (op.HasAdd()) { operationType = OperationType.ADD; } //Subtract else if (op.HasSubtract()) { operationType = OperationType.SUBTRACT; } //Divide else if (op.HasDivide()) { operationType = OperationType.DIVIDE; } //Multiply else if (op.HasMultiply()) { operationType = OperationType.MULTIPLY; } //Power else if (op.HasPower()) { operationType = OperationType.POWER; } //Log : assumes that RHS is the base and LHS is the number. else if (op.HasLog()) { operationType = OperationType.LOG; } ArithmeticNode node = new ArithmeticNode(m_Container); node.m_OperationType = operationType; node.AddChild(CreateArithmeticNode(exp.GetLHSArithmeticExpression())); node.AddChild(CreateArithmeticNode(exp.GetRHSArithmeticExpression())); return(node); }
ConstantType EvalSubExpression(SubExpressionType exp) { ConstantType retVal = new ConstantType(); ArithemticOperator op = exp.GetArithmeticOperator(); decimal lhs = (decimal)GetFloatOrIntValue(EvaluateArithmeticExpression(exp.GetLHSArithmeticExpression())); decimal rhs = (decimal)GetFloatOrIntValue(EvaluateArithmeticExpression(exp.GetRHSArithmeticExpression())); //Add if (op.HasAdd()) { retVal.AddFloat2(new SchemaDecimal(lhs + rhs)); } //Subtract else if (op.HasSubtract()) { retVal.AddFloat2(new SchemaDecimal(lhs - rhs)); } //Divide else if (op.HasDivide()) { retVal.AddFloat2(new SchemaDecimal(lhs / rhs)); } //Multiply else if (op.HasMultiply()) { retVal.AddFloat2(new SchemaDecimal(lhs * rhs)); } //Power else if (op.HasPower()) { retVal.AddFloat2(new SchemaDecimal((decimal)Math.Pow((double)lhs, (double)rhs))); } //Log : assumes that RHS is the base and LHS is the number. else if (op.HasLog()) { retVal.AddFloat2(new SchemaDecimal((decimal)(Math.Log((double)lhs) / Math.Log((double)rhs)))); } return(retVal); }
public ArithmeticExpression MakeArithmeticSubExperssion(string op, ArithmeticExpression lhs, ArithmeticExpression rhs) { ArithemticOperator arithmeticOP = new ArithemticOperator(); SubExpressionType newArithmetic = new SubExpressionType(); if (op == "+") { arithmeticOP.AddAdd(new Altova.Types.SchemaString("Addition")); } else if (op == "-") { arithmeticOP.AddSubtract(new Altova.Types.SchemaString("Subtract")); } else if (op == "*") { arithmeticOP.AddMultiply(new Altova.Types.SchemaString("Multiply")); } else if (op == "/") { arithmeticOP.AddDivide(new Altova.Types.SchemaString("Divide")); } else if (op == "^") { arithmeticOP.AddPower(new Altova.Types.SchemaString("Mod")); } else if (op == "Log") { arithmeticOP.AddLog(new Altova.Types.SchemaString("Log")); } newArithmetic.AddLHSArithmeticExpression(lhs); newArithmetic.AddArithmeticOperator(arithmeticOP); newArithmetic.AddRHSArithmeticExpression(rhs); return(MakeArithmeticExperssion(newArithmetic)); }
void VisitSubExpression(SubExpressionType exp) { VisitArithmeticExpression(exp.GetLHSArithmeticExpression()); VisitArithmeticExpression(exp.GetRHSArithmeticExpression()); }