Ejemplo n.º 1
0
        VariableType ValidateArithmeticExpression(ArithmeticExpression exp, out bool valid)
        {
            VariableType varType = VariableType.INT;

            valid = true;

            if (exp.HasSubExpression())
            {
                bool valid1;
                bool valid2;

                //ArithemticOperator op = exp.GetSubExpression().GetArithmeticOperator();
                VariableType t1 = ValidateArithmeticExpression(exp.GetSubExpression().GetLHSArithmeticExpression(), out valid1);
                VariableType t2 = ValidateArithmeticExpression(exp.GetSubExpression().GetRHSArithmeticExpression(), out valid2);

                valid = IsTypeCompatible(t1, t2, out varType) && valid1 && valid2;
            }
            else //is a value
            {
                if (exp.GetValue().HasVariable()) //is a variable
                {
                    varType = (VariableType)exp.GetValue().GetVariable().GetType2().Value;
                }
                else // is a constant
                {
                    varType = GetConstantType(exp.GetValue().GetConstant());
                }
            }

            return(varType);
        }
Ejemplo n.º 2
0
 void VisitArithmeticExpression(ArithmeticExpression exp)
 {
     if (exp.HasSubExpression())
     {
         VisitSubExpression(exp.GetSubExpression());
     }
     else
     {
         if (exp.GetValue().HasVariable())
         {
             m_VariableReferences.Add(exp.GetValue().GetVariable().GetName().Value);
         }
     }
 }
Ejemplo n.º 3
0
        ConstantType EvaluateArithmeticExpression(ArithmeticExpression exp)
        {
            ConstantType retVal;

            if (exp.HasSubExpression())
            {
                retVal = EvalSubExpression(exp.GetSubExpression());
            }
            else
            {
                if (exp.GetValue().HasConstant())
                {
                    retVal = exp.GetValue().GetConstant();
                }
                else
                {
                    Variable currVar;
                    string   currName = exp.GetValue().GetVariable().GetName().Value;
                    retVal = new ConstantType();

                    if (m_Context.GetState().GetVariable(currName, out currVar))
                    {
                        if (currVar.GetVariableType() == VariableType.BOOLEAN)
                        {
                            retVal.AddBoolean(new SchemaBoolean((bool)currVar.GetValue()));
                        }
                        else if (currVar.GetVariableType() == VariableType.INT)
                        {
                            retVal.AddInteger(new SchemaLong((int)currVar.GetValue()));
                        }
                        else if (currVar.GetVariableType() == VariableType.FLOAT)
                        {
                            retVal.AddFloat2(new SchemaDecimal((decimal)(float)currVar.GetValue()));
                        }
                        else if (currVar.GetVariableType() == VariableType.STRING)
                        {
                            string value = (string)currVar.GetValue();
                            retVal.AddString2(new SchemaString(value));
                        }
                    }
                }
            }

            return(retVal);
        }
Ejemplo n.º 4
0
        string GetArithmeticExpressionString(ArithmeticExpression exp)
        {
            string retVal = "";

            if (exp.HasSubExpression())
            {
                retVal = GetSubExpressionString(exp.GetSubExpression());
            }
            else
            {
                if (exp.GetValue().HasConstant())
                {
                    retVal = GetConstantString(exp.GetValue().GetConstant());
                }
                else
                {
                    retVal = exp.GetValue().GetVariable().GetName().Value;
                }
            }

            return(retVal);
        }
Ejemplo n.º 5
0
        public static bool EvalStr(string s, out float value, out string errMsg)
        {
            int endIndex;

            value = 0;
            try
            {
                ArithmeticExpression <ICalculator> expression = ParseExpression(s, out endIndex, out errMsg);
                if (expression != null && string.IsNullOrEmpty(errMsg))
                {
                    value = expression.GetValue().Value;
                    return(true);
                }
            }
            catch (Exception e)
            {
                errMsg = e.Message;
            }

            return(false);
        }
Ejemplo n.º 6
0
        NodeBase CreateArithmeticNode(ArithmeticExpression exp)
        {
            NodeBase node = null;

            if (exp.HasSubExpression())
            {
                node = CreateMathNode(exp.GetSubExpression());
            }
            else
            {
                if (exp.GetValue().HasConstant())
                {
                    node = new ConstantNode(m_Container);
                    if (exp.GetValue().GetConstant().HasFloat2())
                    {
                        ((ConstantNode)node).m_ConstantValue = (float)exp.GetValue().GetConstant().GetFloat2().Value;
                        ((ConstantNode)node).m_ConstantType  = VariableType.FLOAT;
                    }
                    else if (exp.GetValue().GetConstant().HasInteger())
                    {
                        ((ConstantNode)node).m_ConstantValue = (int)exp.GetValue().GetConstant().GetInteger().Value;
                        ((ConstantNode)node).m_ConstantType  = VariableType.INT;
                    }
                    else if (exp.GetValue().GetConstant().HasBoolean())
                    {
                        ((ConstantNode)node).m_ConstantValue = (bool)exp.GetValue().GetConstant().GetBoolean().Value;
                        ((ConstantNode)node).m_ConstantType  = VariableType.BOOLEAN;
                    }
                    else if (exp.GetValue().GetConstant().HasString2())
                    {
                        ((ConstantNode)node).m_ConstantValue = (string)exp.GetValue().GetConstant().GetString2().Value;
                        ((ConstantNode)node).m_ConstantType  = VariableType.STRING;
                    }
                }
                else
                {
                    node = new VariableNode(m_Container);
                    ((VariableNode)node).m_VariableName = exp.GetValue().GetVariable().GetName().Value;
                    ((VariableNode)node).m_VariableType = (VariableType)exp.GetValue().GetVariable().GetType2().Value;
                }
            }

            return(node);
        }