예제 #1
0
        /// <summary>
        ///     Combines two types to create a new one
        /// </summary>
        /// <param name="right"></param>
        /// <returns></returns>
        public override Type CombineType(Type right, BinaryExpression.Operator Operator)
        {
            Type retVal = null;

            if (Operator == BinaryExpression.Operator.Mult)
            {
                if (FullName.CompareTo("Default.BaseTypes.Speed") == 0 &&
                    right.FullName.CompareTo("Default.BaseTypes.Time") == 0)
                {
                    NameSpace nameSpace = EnclosingNameSpaceFinder.find(this);
                    retVal = nameSpace.findTypeByName("Distance");
                }
            }
            else
            {
                if (IsDouble())
                {
                    if (right == EFSSystem.DoubleType)
                    {
                        retVal = this;
                    }
                }
                else
                {
                    if (right == EFSSystem.IntegerType)
                    {
                        retVal = this;
                    }
                }
            }

            return(retVal);
        }
예제 #2
0
        /// <summary>
        ///     Indicates that binary operation is valid for this type and the other type
        /// </summary>
        /// <param name="otherType"></param>
        /// <returns></returns>
        public override bool ValidBinaryOperation(BinaryExpression.Operator operation, Type otherType)
        {
            bool retVal = base.ValidBinaryOperation(operation, otherType);

            if (!retVal)
            {
                if (operation == BinaryExpression.Operator.Add || operation == BinaryExpression.Operator.Div ||
                    operation == BinaryExpression.Operator.Mult || operation == BinaryExpression.Operator.Sub)
                {
                    // Allow implicit conversions
                    IntegerType integerType = otherType as IntegerType;
                    if (integerType != null)
                    {
                        retVal = true;
                    }
                    else
                    {
                        DoubleType doubleType = otherType as DoubleType;
                        retVal = (doubleType != null);
                    }
                }
            }

            return(retVal);
        }
예제 #3
0
        /// <summary>
        ///     Indicates that binary operation is valid for this type and the other type
        /// </summary>
        /// <param name="operation"></param>
        /// <param name="otherType"></param>
        /// <returns></returns>
        public override bool ValidBinaryOperation(BinaryExpression.Operator operation, Type otherType)
        {
            bool retVal;

            if (operation == BinaryExpression.Operator.Less || operation == BinaryExpression.Operator.LessOrEqual ||
                operation == BinaryExpression.Operator.Greater ||
                operation == BinaryExpression.Operator.GreaterOrEqual)
            {
                retVal = false;
            }
            else
            {
                retVal = base.ValidBinaryOperation(operation, otherType);
            }

            return(retVal);
        }
예제 #4
0
        /// <summary>
        ///     Combines two types to create a new one
        /// </summary>
        /// <param name="right"></param>
        /// <returns></returns>
        public override Type CombineType(Type right, BinaryExpression.Operator Operator)
        {
            Type retVal = null;

            if (Operator == BinaryExpression.Operator.Mult)
            {
                Range range = right as Range;
                if (range != null)
                {
                    if (range.getPrecision() == acceptor.PrecisionEnum.aIntegerPrecision)
                    {
                        retVal = this;
                    }
                }
            }

            return(retVal);
        }
예제 #5
0
        /// <summary>
        ///     Performs the arithmetic operation based on the type of the result
        /// </summary>
        /// <param name="context">The context used to perform this operation</param>
        /// <param name="left"></param>
        /// <param name="operation"></param>
        /// <param name="right"></param>
        /// <returns></returns>
        public override IValue PerformArithmericOperation(InterpretationContext context, IValue left,
                                                          BinaryExpression.Operator operation, IValue right) // left +/-/*/div/exp right
        {
            DoubleValue retVal = null;

            double double1 = getValue(left);
            double double2 = getValue(right);

            switch (operation)
            {
            case BinaryExpression.Operator.Exp:
                retVal = new DoubleValue(this, Math.Pow(double1, double2));
                break;

            case BinaryExpression.Operator.Mult:
                retVal = new DoubleValue(this, (double1 * double2));
                break;

            case BinaryExpression.Operator.Div:
                if (double2 == 0)
                {
                    throw new Exception("Division by zero");
                }
                else
                {
                    retVal = new DoubleValue(this, (double1 / double2));
                }
                break;

            case BinaryExpression.Operator.Add:
                retVal = new DoubleValue(this, (double1 + double2));
                break;

            case BinaryExpression.Operator.Sub:
                retVal = new DoubleValue(this, (double1 - double2));
                break;
            }

            return(retVal);
        }
예제 #6
0
        /// <summary>
        ///     Performs the arithmetic operation based on the type of the result
        /// </summary>
        /// <param name="context">The context used to perform this operation</param>
        /// <param name="left"></param>
        /// <param name="operation"></param>
        /// <param name="right"></param>
        /// <returns></returns>
        public override IValue PerformArithmericOperation(InterpretationContext context, IValue left,
                                                          BinaryExpression.Operator operation, IValue right) // left +/-/*/div/exp right
        {
            IntValue retVal = null;

            int int1 = getValue(left);
            int int2 = getValue(right);

            switch (operation)
            {
            case BinaryExpression.Operator.Exp:
                retVal = new IntValue(EFSSystem.IntegerType, (Decimal)Math.Pow((double)int1, (double)int2));
                break;

            case BinaryExpression.Operator.Mult:
                retVal = new IntValue(EFSSystem.IntegerType, (int1 * int2));
                break;

            case BinaryExpression.Operator.Div:
                if (int2 == 0)
                {
                    throw new Exception("Division by zero");
                }
                else
                {
                    retVal = new IntValue(EFSSystem.IntegerType, (int1 / int2));
                }
                break;

            case BinaryExpression.Operator.Add:
                retVal = new IntValue(EFSSystem.IntegerType, (int1 + int2));
                break;

            case BinaryExpression.Operator.Sub:
                retVal = new IntValue(EFSSystem.IntegerType, (int1 - int2));
                break;
            }

            return(retVal);
        }
예제 #7
0
        /// <summary>
        ///     Performs the arithmetic operation based on the type of the result
        /// </summary>
        /// <param name="context">The context used to perform this operation</param>
        /// <param name="left"></param>
        /// <param name="operation"></param>
        /// <param name="right"></param>
        /// <returns></returns>
        public override IValue PerformArithmericOperation(InterpretationContext context, IValue left,
                                                          BinaryExpression.Operator operation, IValue right) // left +/-/*/div/exp right
        {
            IValue retVal = null;

            left  = derefEnumForArithmeticOperation(left);
            right = derefEnumForArithmeticOperation(right);

            IntValue int1 = left as IntValue;
            IntValue int2 = right as IntValue;

            if (int1 == null || int2 == null)
            {
                retVal = EFSSystem.DoubleType.PerformArithmericOperation(context, left, operation, right);
            }
            else
            {
                retVal = EFSSystem.IntegerType.PerformArithmericOperation(context, left, operation, right);
            }

            return(retVal);
        }
예제 #8
0
        /// <summary>
        ///     Indicates that binary operation is valid for this type and the other type
        /// </summary>
        /// <param name="otherType"></param>
        /// <returns></returns>
        public virtual bool ValidBinaryOperation(BinaryExpression.Operator operation, Type otherType)
        {
            bool retVal;

            if (operation == BinaryExpression.Operator.In || operation == BinaryExpression.Operator.NotIn)
            {
                Collection collectionType = otherType as Collection;
                if (collectionType != null)
                {
                    retVal = Match(collectionType.Type);
                }
                else
                {
                    retVal = Match(otherType);
                }
            }
            else
            {
                retVal = Match(otherType);
            }

            return(retVal);
        }
예제 #9
0
 /// <summary>
 ///     Combines two types to create a new one
 /// </summary>
 /// <param name="right"></param>
 /// <returns></returns>
 public virtual Type CombineType(Type right, BinaryExpression.Operator Operator)
 {
     return(null);
 }
예제 #10
0
        /// <summary>
        ///     Performs the arithmetic operation based on the type of the result
        /// </summary>
        /// <param name="context">The context used to perform this operation</param>
        /// <param name="left"></param>
        /// <param name="operation"></param>
        /// <param name="right"></param>
        /// <returns></returns>
        public virtual IValue PerformArithmericOperation(InterpretationContext context, IValue left,
                                                         BinaryExpression.Operator operation, IValue right) // left +/-/*/div/exp right
        {
            IValue retVal = null;

            Function leftFunction  = left as Function;
            Function rigthFunction = right as Function;

            if (leftFunction != null)
            {
                if (rigthFunction == null)
                {
                    if (leftFunction.Graph != null)
                    {
                        Graph graph = Graph.createGraph(Function.GetDoubleValue(right));
                        rigthFunction = graph.Function;
                    }
                    else
                    {
                        Surface surface = Surface.createSurface(Function.GetDoubleValue(right),
                                                                leftFunction.Surface.XParameter, leftFunction.Surface.YParameter);
                        rigthFunction = surface.Function;
                    }
                }

                if (leftFunction.Graph != null)
                {
                    IGraph tmp = null;
                    switch (operation)
                    {
                    case BinaryExpression.Operator.Add:
                        tmp = leftFunction.Graph.AddGraph(rigthFunction.Graph);
                        break;

                    case BinaryExpression.Operator.Sub:
                        tmp = leftFunction.Graph.SubstractGraph(rigthFunction.Graph);
                        break;

                    case BinaryExpression.Operator.Mult:
                        tmp = leftFunction.Graph.MultGraph(rigthFunction.Graph);
                        break;

                    case BinaryExpression.Operator.Div:
                        tmp = leftFunction.Graph.DivGraph(rigthFunction.Graph);
                        break;
                    }
                    Graph tmpGraph = tmp as Graph;
                    if (tmpGraph != null)
                    {
                        retVal = tmpGraph.Function;
                    }
                }
                else
                {
                    Surface rightSurface = rigthFunction.GetSurface(leftFunction.Surface.XParameter,
                                                                    leftFunction.Surface.YParameter);
                    Surface tmp = null;
                    switch (operation)
                    {
                    case BinaryExpression.Operator.Add:
                        tmp = leftFunction.Surface.AddSurface(rightSurface);
                        break;

                    case BinaryExpression.Operator.Sub:
                        tmp = leftFunction.Surface.SubstractSurface(rightSurface);
                        break;

                    case BinaryExpression.Operator.Mult:
                        tmp = leftFunction.Surface.MultiplySurface(rightSurface);
                        break;

                    case BinaryExpression.Operator.Div:
                        tmp = leftFunction.Surface.DivideSurface(rightSurface);
                        break;
                    }
                    retVal = tmp.Function;
                }
            }

            return(retVal);
        }
예제 #11
0
 public override IValue PerformArithmericOperation(InterpretationContext context, IValue left,
                                                   BinaryExpression.Operator operation, IValue right)
 {
     throw new Exception("Cannot perform arithmetic operation between " + left.LiteralName + " and " +
                         right.LiteralName);
 }
예제 #12
0
        public override IValue PerformArithmericOperation(InterpretationContext context, IValue left, BinaryExpression.Operator operation, IValue right)
        {
            ListValue retVal = null;

            switch (operation)
            {
            case BinaryExpression.Operator.Add:
                Collection leftType  = left.Type as Collection;
                Collection rightType = right.Type as Collection;
                Collection returnType;

                if (leftType != null && rightType != null)
                {
                    if (leftType is GenericCollection)
                    {
                        if (rightType is GenericCollection)
                        {
                            returnType = new GenericCollection(EFSSystem);
                        }
                        else
                        {
                            returnType = rightType;
                        }
                    }
                    else
                    {
                        if (leftType == rightType)
                        {
                            returnType = leftType;
                        }
                        else if (leftType.Type == rightType.Type)
                        {
                            returnType = leftType;
                        }
                        else
                        {
                            throw new Exception("Cannot determine the collection type for expression");
                        }
                    }

                    ListValue leftValue  = left as ListValue;
                    ListValue rightValue = right as ListValue;
                    if (leftValue != null && rightValue != null)
                    {
                        retVal = new ListValue(returnType, new List <IValue>());
                        foreach (IValue val in leftValue.Val)
                        {
                            if (!(val is EmptyValue))
                            {
                                retVal.Val.Add(val.RightSide(null, true, true));
                            }
                        }
                        foreach (IValue val in rightValue.Val)
                        {
                            if (!(val is EmptyValue))
                            {
                                retVal.Val.Add(val.RightSide(null, true, true));
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("Cannot add a collection to a single element");
                    }
                }
                break;
            }

            return(retVal);
        }