Esempio n. 1
0
        public static TokenType ExecuteBinaryOperation(Operator op, TokenType param1, TokenType param2)
        {
            Type pType1           = param1.GetType();
            Type pType2           = param2.GetType();
            BinaryOperatorDef def = new BinaryOperatorDef(pType1, op, pType2);

            if (binary_operators.ContainsKey(def))
            {
                return(binary_operators[def].func(param1, param2));
            }
            else
            {
                def = new BinaryOperatorDef(pType2, op, pType1);
                if (binary_operators.ContainsKey(def))
                {
                    OperationData <BinaryOperateFunc> data = binary_operators[def];
                    if (data.isCommutative)
                    {
                        return(data.func(param2, param1));
                    }
                }
                else
                {
                    def = new BinaryOperatorDef(pType1, op, typeof(TokenType));
                    if (binary_operators.ContainsKey(def))
                    {
                        return(binary_operators[def].func(param1, param2));
                    }
                }
            }

            throw new ExprCoreException("인식할 수 없는 연산자입니다. (" + pType1.Name + ") " + op + " (" + pType2.Name + ")");
        }
Esempio n. 2
0
        public static TokenType ExecuteOperation(OperatorDef op, TokenType param1, TokenType param2)
        {
            if (op is UnaryOperatorDef)
            {
                UnaryOperatorDef def = op as UnaryOperatorDef;
                if (unary_operators.ContainsKey(def))
                {
                    return(unary_operators[def](param1));
                }
            }
            else if (op is BinaryOperatorDef)
            {
                BinaryOperatorDef def = op as BinaryOperatorDef;
                if (binary_operators.ContainsKey(def))
                {
                    return(binary_operators[def](param1, param2));
                }
            }

            throw new ProcessingException("인식할 수 없는 연산자입니다. [" + op + "]");
        }