Exemplo n.º 1
0
        private ScriptObject ParseOperate(CodeOperator operate)
        {
            Scorpio.Compiler.TokenType @operator = operate.Operator;
            ScriptObject obj2 = this.ResolveOperand(operate.Left);

            switch (@operator)
            {
            case Scorpio.Compiler.TokenType.Plus:
            {
                ScriptObject obj3 = this.ResolveOperand(operate.Right);
                if ((obj2 is ScriptString) || (obj3 is ScriptString))
                {
                    return(new ScriptString(this.m_script, obj2.ToString() + obj3.ToString()));
                }
                return(obj2.Compute(@operator, obj3));
            }

            case Scorpio.Compiler.TokenType.Minus:
            case Scorpio.Compiler.TokenType.Multiply:
            case Scorpio.Compiler.TokenType.Divide:
            case Scorpio.Compiler.TokenType.Modulo:
            case Scorpio.Compiler.TokenType.InclusiveOr:
            case Scorpio.Compiler.TokenType.Combine:
            case Scorpio.Compiler.TokenType.XOR:
            case Scorpio.Compiler.TokenType.Shi:
            case Scorpio.Compiler.TokenType.Shr:
                return(obj2.Compute(@operator, this.ResolveOperand(operate.Right)));

            case Scorpio.Compiler.TokenType.Or:
                if (!obj2.LogicOperation())
                {
                    return(this.m_script.CreateBool(this.ResolveOperand(operate.Right).LogicOperation()));
                }
                return(this.m_script.True);

            case Scorpio.Compiler.TokenType.And:
                if (obj2.LogicOperation())
                {
                    return(this.m_script.CreateBool(this.ResolveOperand(operate.Right).LogicOperation()));
                }
                return(this.m_script.False);

            case Scorpio.Compiler.TokenType.Equal:
                return(this.m_script.CreateBool(obj2.Equals(this.ResolveOperand(operate.Right))));

            case Scorpio.Compiler.TokenType.NotEqual:
                return(this.m_script.CreateBool(!obj2.Equals(this.ResolveOperand(operate.Right))));

            case Scorpio.Compiler.TokenType.Greater:
            case Scorpio.Compiler.TokenType.GreaterOrEqual:
            case Scorpio.Compiler.TokenType.Less:
            case Scorpio.Compiler.TokenType.LessOrEqual:
                return(this.m_script.CreateBool(obj2.Compare(@operator, this.ResolveOperand(operate.Right))));
            }
            throw new ExecutionException(this.m_script, "不支持的运算符 " + @operator);
        }
Exemplo n.º 2
0
        ScriptObject ParseOperate(CodeOperator operate)
        {
            TokenType    type = operate.Operator;
            ScriptObject left = ResolveOperand(operate.Left);

            switch (type)
            {
            case TokenType.Plus:
                ScriptObject right = ResolveOperand(operate.Right);
                if (left is ScriptString || right is ScriptString)
                {
                    return(new ScriptString(m_script, left.ToString() + right.ToString()));
                }
                return(left.Compute(type, right));

            case TokenType.Minus:
            case TokenType.Multiply:
            case TokenType.Divide:
            case TokenType.Modulo:
            case TokenType.InclusiveOr:
            case TokenType.Combine:
            case TokenType.XOR:
            case TokenType.Shr:
            case TokenType.Shi:
                return(left.Compute(type, ResolveOperand(operate.Right)));

            case TokenType.And:
                if (!left.LogicOperation())
                {
                    return(m_script.False);
                }
                return(m_script.CreateBool(ResolveOperand(operate.Right).LogicOperation()));

            case TokenType.Or:
                if (left.LogicOperation())
                {
                    return(m_script.True);
                }
                return(m_script.CreateBool(ResolveOperand(operate.Right).LogicOperation()));

            case TokenType.Equal:
                return(m_script.CreateBool(left.Equals(ResolveOperand(operate.Right))));

            case TokenType.NotEqual:
                return(m_script.CreateBool(!left.Equals(ResolveOperand(operate.Right))));

            case TokenType.Greater:
            case TokenType.GreaterOrEqual:
            case TokenType.Less:
            case TokenType.LessOrEqual:
                return(m_script.CreateBool(left.Compare(type, ResolveOperand(operate.Right))));

            default:
                throw new ExecutionException(m_script, "不支持的运算符 " + type);
            }
        }
Exemplo n.º 3
0
        ScriptObject ParseOperate(CodeOperator operate)
        {
            TokenType    type = operate.Operator;
            ScriptObject left = ResolveOperand(operate.Left);

            if (type == TokenType.Plus)
            {
                ScriptObject right = ResolveOperand(operate.Right);
                if (left is ScriptString || right is ScriptString)
                {
                    return(m_script.CreateString(left.ToString() + right.ToString()));
                }
                return(left.Compute(type, right));
            }
            else if (type == TokenType.And)
            {
                if (left.LogicOperation() == false)
                {
                    return(m_script.False);
                }
                return(m_script.GetBoolean(ResolveOperand(operate.Right).LogicOperation()));
            }
            else if (type == TokenType.Or)
            {
                if (left.LogicOperation() == true)
                {
                    return(m_script.True);
                }
                return(m_script.GetBoolean(ResolveOperand(operate.Right).LogicOperation()));
            }
            else if (type == TokenType.Equal)
            {
                return(m_script.GetBoolean(left.Equals(ResolveOperand(operate.Right))));
            }
            else if (type == TokenType.NotEqual)
            {
                return(m_script.GetBoolean(!left.Equals(ResolveOperand(operate.Right))));
            }
            else if (type == TokenType.Greater || type == TokenType.GreaterOrEqual || type == TokenType.Less || type == TokenType.LessOrEqual)
            {
                return(m_script.GetBoolean(left.Compare(type, ResolveOperand(operate.Right))));
            }
            else
            {
                return(left.Compute(type, ResolveOperand(operate.Right)));
            }
        }