Пример #1
0
        public static IOperandTerm ReduceBinaryTerm(OperatorCode op, IOperandTerm left, IOperandTerm right)
        {
            OperatorMethod method = null;

            if ((left.GetOperandType() == typeof(Int64)) && (right.GetOperandType() == typeof(Int64)))
            {
                if (binaryIntIntDic.ContainsKey(op))
                {
                    method = binaryIntIntDic[op];
                }
            }
            else if ((left.GetOperandType() == typeof(string)) && (right.GetOperandType() == typeof(string)))
            {
                if (binaryStrStrDic.ContainsKey(op))
                {
                    method = binaryStrStrDic[op];
                }
            }
            else if (((left.GetOperandType() == typeof(Int64)) && (right.GetOperandType() == typeof(string))) ||
                     ((left.GetOperandType() == typeof(string)) && (right.GetOperandType() == typeof(Int64))))
            {
                if (op == OperatorCode.Mult)
                {
                    method = binaryMultIntStr;
                }
            }
            if (method != null)
            {
                return(new FunctionMethodTerm(method, new IOperandTerm[] { left, right }));
            }
            string errMes = "";

            if (left.GetOperandType() == typeof(Int64))
            {
                errMes += "数値型と";
            }
            else if (left.GetOperandType() == typeof(string))
            {
                errMes += "文字列型と";
            }
            else
            {
                errMes += "不定型と";
            }
            if (right.GetOperandType() == typeof(Int64))
            {
                errMes += "数値型の";
            }
            else if (right.GetOperandType() == typeof(string))
            {
                errMes += "文字列型の";
            }
            else
            {
                errMes += "不定型の";
            }
            errMes += "演算に二項演算子\'" + OperatorManager.ToOperatorString(op) + "\'は適用できません";
            throw new CodeEE(errMes);
        }
Пример #2
0
        public static IOperandTerm ReduceUnaryTerm(OperatorCode op, IOperandTerm o1)
        {
            OperatorMethod method = null;

            if (op == OperatorCode.Increment || op == OperatorCode.Decrement)
            {
                VariableTerm var = o1 as VariableTerm;
                if (var == null)
                {
                    throw new CodeEE("変数以外をインクリメントすることはできません");
                }
                if (var.Identifier.IsConst)
                {
                    throw new CodeEE("変更できない変数をインクリメントすることはできません");
                }
            }
            if (o1.GetOperandType() == typeof(Int64))
            {
                if (op == OperatorCode.Plus)
                {
                    return(o1);
                }
                OperatorMethod operator_method = null;
                if (unaryDic.TryGetValue(op, out operator_method))
                {
                    method = operator_method;
                }
            }
            if (method != null)
            {
                return(new FunctionMethodTerm(method, new IOperandTerm[] { o1 }));
            }
            string errMes = "";

            if (o1.GetOperandType() == typeof(Int64))
            {
                errMes += "数値型";
            }
            else if (o1.GetOperandType() == typeof(string))
            {
                errMes += "文字列型";
            }
            else
            {
                errMes += "不定型";
            }
            errMes += "に単項演算子\'" + OperatorManager.ToOperatorString(op) + "\'は適用できません";
            throw new CodeEE(errMes);
        }
Пример #3
0
        public static IOperandTerm ReduceUnaryAfterTerm(OperatorCode op, IOperandTerm o1)
        {
            OperatorMethod method = null;

            if (op == OperatorCode.Increment || op == OperatorCode.Decrement)
            {
                var var = o1 as VariableTerm;
                if (var == null)
                {
                    throw new CodeEE("変数以外をインクリメントすることはできません");
                }
                if (var.Identifier.IsConst)
                {
                    throw new CodeEE("変更できない変数をインクリメントすることはできません");
                }
            }
            if (o1.GetOperandType() == typeof(long))
            {
                if (unaryAfterDic.ContainsKey(op))
                {
                    method = unaryAfterDic[op];
                }
            }
            if (method != null)
            {
                return(new FunctionMethodTerm(method, new[] { o1 }));
            }
            var errMes = "";

            if (o1.GetOperandType() == typeof(long))
            {
                errMes += "数値型";
            }
            else if (o1.GetOperandType() == typeof(string))
            {
                errMes += "文字列型";
            }
            else
            {
                errMes += "不定型";
            }
            errMes += "に後置単項演算子\'" + OperatorManager.ToOperatorString(op) + "\'は適用できません";
            throw new CodeEE(errMes);
        }