コード例 #1
0
ファイル: Assign.cs プロジェクト: fabrimaciel/colosoft
        public object Evaluate(INode node, IEvaluator pv)
        {
            if (node.JjtGetNumChildren() != 2)
            {
                throw new EvaluationException("Assignment operator must have 2 operators.");
            }
            object obj2  = pv.Eval(node.JjtGetChild(1));
            INode  node2 = node.JjtGetChild(0);

            if (node2 is ASTVarNode)
            {
                ASTVarNode node3 = (ASTVarNode)node2;
                if (!node3.Var.SetValue(obj2))
                {
                    throw new EvaluationException("Attempt to set the value of a constant variable");
                }
                return(obj2);
            }
            if (!(node2 is ASTFunNode) || !(((ASTFunNode)node2).GetPFMC() is ILValue))
            {
                throw new EvaluationException("Assignment should have a variable or LValue for the lhs.");
            }
            ((ILValue)((ASTFunNode)node2).GetPFMC()).Set(pv, node2, obj2);
            return(obj2);
        }
コード例 #2
0
        public object Visit(ASTVarNode node, object data)
        {
            Variable var = node.Var;

            if (var == null)
            {
                throw new EvaluationException("var was null in StandardEvaluator");
            }
            object item = var.Value;

            if (this._trapNullValues && (item == null))
            {
                throw new EvaluationException("Could not evaluate " + node.GetName() + ": no value set for the variable.");
            }
            if (this._trapNaN && (((item is double) && double.IsNaN((double)item)) || ((item is float) && float.IsNaN((float)item))))
            {
                throw new EvaluationException("NaN value detected for variable " + node.GetName());
            }
            if (this._trapInfinity && (((item is double) && double.IsInfinity((double)item)) || ((item is float) && float.IsInfinity((float)item))))
            {
                throw new EvaluationException("Infinite value " + item.ToString() + "detected for variable " + node.GetName());
            }
            this.stack.Push(item);
            return(data);
        }
コード例 #3
0
        public ASTVarNode BuildVariableNode(string name)
        {
            ASTVarNode node = new ASTVarNode(JJTVARNODE);
            Variable   var  = this.vt.AddVariable(name);

            node.Var = var;
            return(this.BuildVariableNode(var));
        }
コード例 #4
0
ファイル: RealEvaluator.cs プロジェクト: fabrimaciel/colosoft
        protected double VisitVariable(ASTVarNode node)
        {
            object o = node.Var.Value;

            if (o == null)
            {
                throw new EvaluationException("Variable " + node.GetName() + " has a null value");
            }
            return(FromObject(o));
        }
コード例 #5
0
ファイル: Ele.cs プロジェクト: fabrimaciel/colosoft
        public void Set(IEvaluator pv, INode node, object value)
        {
            INode node2 = node.JjtGetChild(0);

            if (!(node2 is ASTVarNode))
            {
                throw new EvaluationException("Ele: lhs must be a variable");
            }
            ASTVarNode node3 = (ASTVarNode)node2;
            Variable   var   = node3.Var;

            if (node.JjtGetNumChildren() == 2)
            {
                object obj2 = pv.Eval(node.JjtGetChild(1));
                int    num  = -1;
                if (obj2 is JepDouble)
                {
                    num = ((JepDouble)obj2).IntValue - 1;
                }
                else
                {
                    if (!(obj2 is ArrayList))
                    {
                        throw new EvaluationException("Ele: rhs must be a number");
                    }
                    ArrayList list = (ArrayList)obj2;
                    if (list.Count != 1)
                    {
                        throw new EvaluationException("Ele: only single dimension arrays supported in JEP");
                    }
                    num = ((JepDouble)list[0]).IntValue - this.indexShift;
                }
                object obj3 = var.Value;
                if (!(obj3 is ArrayList))
                {
                    throw new EvaluationException("Ele: the value of the variable must be a Vector");
                }
                ArrayList list2 = new ArrayList((ArrayList)obj3);
                list2[num] = value;
                var.SetValue(list2);
            }
            else
            {
                int[] indicies = new int[node.JjtGetNumChildren() - 1];
                for (int i = 0; i < indicies.Length; i++)
                {
                    object obj4 = pv.Eval(node.JjtGetChild(i + 1));
                    if (!(obj4 is JepDouble))
                    {
                        throw new EvaluationException("Ele: index should be integers, it is " + obj4);
                    }
                    indicies[i] = ((JepDouble)obj4).IntValue - this.indexShift;
                }
                object o = var.Value;
                if (!(o is ArrayList))
                {
                    throw new EvaluationException("Ele: the value of the variable must be a ArrayList");
                }
                object obj6 = this.SetEle(o, indicies, 0, value);
                var.SetValue(obj6);
            }
        }
コード例 #6
0
 public virtual object Visit(ASTVarNode node, object data)
 {
     this.sb.Append(node.GetName());
     return(data);
 }
コード例 #7
0
 public ASTVarNode BuildVariableNode(ASTVarNode node)
 {
     return(this.BuildVariableNode(node.Var));
 }