示例#1
0
        private static Value unaryOperation(Operator Op, Value v1)
        {
            if (v1.GetType() == typeof(Nac))
            {
                return(Nac.Create());
            }
            if (v1.GetType() == typeof(Undef))
            {
                return(Undef.Create());
            }
            switch (Op)
            {
            case Operator.INC:
                return(Constant.Create(((Constant)v1).Value + 1));

            case Operator.DEC:
                return(Constant.Create(((Constant)v1).Value - 1));

            case Operator.NEG:
                return(Constant.Create(-((Constant)v1).Value));

            case Operator.NOT:
                return(Constant.Create(((Constant)v1).Value > 0 ? 0 : 1));
            }

            return(null);
        }
示例#2
0
        private static Value binaryOperation(Operator Op, Value v1, Value v2)
        {
            if (v1.GetType() == typeof(Nac) || v2.GetType() == typeof(Nac))
            {
                return(Nac.Create());
            }
            if (v1.GetType() == typeof(Undef) || v2.GetType() == typeof(Undef))
            {
                return(Undef.Create());
            }
            switch (Op)
            {
            case Operator.MUL:
                return(Constant.Create(((Constant)v1).Value * ((Constant)v2).Value));

            case Operator.DIV:
                return(Constant.Create(((Constant)v1).Value / ((Constant)v2).Value));

            case Operator.ADD:
                return(Constant.Create(((Constant)v1).Value + ((Constant)v2).Value));

            case Operator.SUB:
                return(Constant.Create(((Constant)v1).Value - ((Constant)v2).Value));
            }

            return(null);
        }