Ejemplo n.º 1
0
        public ArithmeticExpression MakeArithmeticExperssion(SubExpressionType expression)
        {
            ArithmeticExpression arithmeticExpression = new ArithmeticExpression();

            arithmeticExpression.AddSubExpression(expression);

            return(arithmeticExpression);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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));
        }
Ejemplo n.º 6
0
 void VisitSubExpression(SubExpressionType exp)
 {
     VisitArithmeticExpression(exp.GetLHSArithmeticExpression());
     VisitArithmeticExpression(exp.GetRHSArithmeticExpression());
 }