예제 #1
0
        //获取一个Object
        private CodeObject GetObject()
        {
            Stack <TempOperator> operateStack = new Stack <TempOperator>();
            Stack <CodeObject>   objectStack  = new Stack <CodeObject>();

            while (true)
            {
                objectStack.Push(GetOneObject());
                if (!P_Operator(operateStack, objectStack))
                {
                    break;
                }
            }
            while (operateStack.Count > 0)
            {
                objectStack.Push(new CodeOperator(objectStack.Pop(), objectStack.Pop(), operateStack.Pop().Operator, m_strBreviary, GetSourceLine()));
            }
            CodeObject ret = objectStack.Pop();

            if (ret is CodeMember)
            {
                CodeMember member = ret as CodeMember;
                if (member.Calc == CALC.NONE)
                {
                    Token token = ReadToken();
                    switch (token.Type)
                    {
                    case TokenType.Assign:
                    case TokenType.AssignPlus:
                    case TokenType.AssignMinus:
                    case TokenType.AssignMultiply:
                    case TokenType.AssignDivide:
                    case TokenType.AssignModulo:
                    case TokenType.AssignCombine:
                    case TokenType.AssignInclusiveOr:
                    case TokenType.AssignXOR:
                    case TokenType.AssignShr:
                    case TokenType.AssignShi:
                        ret = new CodeAssign(member, GetObject(), token.Type, m_strBreviary, token.SourceLine);
                        break;

                    default:
                        UndoToken();
                        break;
                    }
                }
            }
            if (PeekToken().Type == TokenType.QuestionMark)
            {
                ReadToken();
                CodeTernary ternary = new CodeTernary();
                ternary.Allow = ret;
                ternary.True  = GetObject();
                ReadColon();
                ternary.False = GetObject();
                return(ternary);
            }
            return(ret);
        }
예제 #2
0
 private ScriptObject ParseAssign(CodeAssign assign)
 {
     if (assign.AssignType == Scorpio.Compiler.TokenType.Assign)
     {
         ScriptObject variable = this.ResolveOperand(assign.value);
         this.SetVariable(assign.member, variable);
         return(variable);
     }
     return(this.GetVariable(assign.member).AssignCompute(assign.AssignType, this.ResolveOperand(assign.value)));
 }
예제 #3
0
        private CodeObject GetObject()
        {
            Stack <TempOperator> operateStack = new Stack <TempOperator>();
            Stack <CodeObject>   objectStack  = new Stack <CodeObject>();

            do
            {
                objectStack.Push(this.GetOneObject());
            }while (this.P_Operator(operateStack, objectStack));
            while (operateStack.Count > 0)
            {
                objectStack.Push(new CodeOperator(objectStack.Pop(), objectStack.Pop(), operateStack.Pop().Operator, this.m_strBreviary, this.GetSourceLine()));
            }
            CodeObject obj2 = objectStack.Pop();

            if (obj2 is CodeMember)
            {
                CodeMember member = obj2 as CodeMember;
                if (member.Calc == CALC.NONE)
                {
                    Token token = this.ReadToken();
                    switch (token.Type)
                    {
                    case Scorpio.Compiler.TokenType.AssignShi:
                    case Scorpio.Compiler.TokenType.AssignShr:
                    case Scorpio.Compiler.TokenType.Assign:
                    case Scorpio.Compiler.TokenType.AssignCombine:
                    case Scorpio.Compiler.TokenType.AssignXOR:
                    case Scorpio.Compiler.TokenType.AssignMinus:
                    case Scorpio.Compiler.TokenType.AssignMultiply:
                    case Scorpio.Compiler.TokenType.AssignDivide:
                    case Scorpio.Compiler.TokenType.AssignModulo:
                    case Scorpio.Compiler.TokenType.AssignInclusiveOr:
                    case Scorpio.Compiler.TokenType.AssignPlus:
                        obj2 = new CodeAssign(member, this.GetObject(), token.Type, this.m_strBreviary, token.SourceLine);
                        goto Label_0121;
                    }
                    this.UndoToken();
                }
            }
Label_0121:
            if (this.PeekToken().Type == Scorpio.Compiler.TokenType.QuestionMark)
            {
                this.ReadToken();
                CodeTernary ternary = new CodeTernary {
                    Allow = obj2,
                    True  = this.GetObject()
                };
                this.ReadColon();
                ternary.False = this.GetObject();
                return(ternary);
            }
            return(obj2);
        }
예제 #4
0
        ScriptObject ParseAssign(CodeAssign assign)
        {
            if (assign.AssignType == TokenType.Assign)
            {
                var ret = ResolveOperand(assign.value);
                SetVariable(assign.member, ret);
                return(ret);
            }
            else
            {
                ScriptObject obj = GetVariable(assign.member);
                ScriptString str = obj as ScriptString;
                if (str != null)
                {
                    if (assign.AssignType == TokenType.AssignPlus)
                    {
                        return(str.AssignPlus(ResolveOperand(assign.value)));
                    }
                    else
                    {
                        throw new ExecutionException("string类型只支持[+=]赋值操作");
                    }
                }
                ScriptNumber num = obj as ScriptNumber;
                if (num != null)
                {
                    ScriptNumber right = ResolveOperand(assign.value) as ScriptNumber;
                    if (right == null)
                    {
                        throw new ExecutionException("[+= -=...]值只能为 number类型");
                    }
                    switch (assign.AssignType)
                    {
                    case TokenType.AssignPlus:
                        return(num.AssignPlus(right));

                    case TokenType.AssignMinus:
                        return(num.AssignMinus(right));

                    case TokenType.AssignMultiply:
                        return(num.AssignMultiply(right));

                    case TokenType.AssignDivide:
                        return(num.AssignDivide(right));

                    case TokenType.AssignModulo:
                        return(num.AssignModulo(right));
                    }
                }
                throw new ExecutionException("[+= -=...]左边值只能为number或者string");
            }
        }
예제 #5
0
 ScriptObject ParseAssign(CodeAssign assign)
 {
     if (assign.AssignType == TokenType.Assign)
     {
         var ret = ResolveOperand(assign.value);
         SetVariable(assign.member, ret);
         return(ret);
     }
     else
     {
         return(GetVariable(assign.member).AssignCompute(assign.AssignType, ResolveOperand(assign.value)));
     }
 }