コード例 #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 ParseTernary(CodeTernary ternary)
 {
     if (!this.ResolveOperand(ternary.Allow).LogicOperation())
     {
         return(this.ResolveOperand(ternary.False));
     }
     return(this.ResolveOperand(ternary.True));
 }
コード例 #3
0
        ScriptObject ParseTernary(CodeTernary ternary)
        {
            ScriptBoolean b = ResolveOperand(ternary.Allow) as ScriptBoolean;

            if (b == null)
            {
                throw new ExecutionException("三目运算符 条件必须是一个bool型");
            }
            return(b.Value ? ResolveOperand(ternary.True) : ResolveOperand(ternary.False));
        }
コード例 #4
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);
        }
コード例 #5
0
 //返回三元运算符
 private CodeObject GetTernary(CodeObject parent)
 {
     if (PeekToken().Type == TokenType.QuestionMark)
     {
         CodeTernary ret = new CodeTernary();
         ret.Allow = parent;
         ReadToken();
         ret.True = GetObject();
         ReadColon();
         ret.False = GetObject();
         return(ret);
     }
     return(parent);
 }
コード例 #6
0
 ScriptObject ParseTernary(CodeTernary ternary)
 {
     return(ResolveOperand(ternary.Allow).LogicOperation() ? ResolveOperand(ternary.True) : ResolveOperand(ternary.False));
 }