Пример #1
0
        //解析单纯for循环
        private void ParseFor_Simple(string Identifier, CodeObject obj)
        {
            CodeForSimple ret = new CodeForSimple();

            ret.Identifier = Identifier;
            ret.Begin      = obj;
            ret.Finished   = GetObject();
            if (PeekToken().Type == TokenType.Comma)
            {
                ReadToken();
                ret.Step = GetObject();
            }
            ReadRightParenthesis();
            ret.BlockExecutable = ParseStatementBlock(Executable_Block.For);
            m_scriptExecutable.AddScriptInstruction(new ScriptInstruction(Opcode.CALL_FORSIMPLE, ret));
        }
Пример #2
0
        private void ParseFor_Simple(string Identifier, CodeObject obj)
        {
            CodeForSimple simple = new CodeForSimple {
                Identifier = Identifier,
                Begin      = obj,
                Finished   = this.GetObject()
            };

            if (this.PeekToken().Type == Scorpio.Compiler.TokenType.Comma)
            {
                this.ReadToken();
                simple.Step = this.GetObject();
            }
            this.ReadRightParenthesis();
            simple.BlockExecutable = this.ParseStatementBlock(Executable_Block.For);
            this.m_scriptExecutable.AddScriptInstruction(new ScriptInstruction(Opcode.CALL_FORSIMPLE, simple));
        }
Пример #3
0
        void ProcessCallForSimple()
        {
            CodeForSimple code        = (CodeForSimple)m_scriptInstruction.operand0;
            ScriptNumber  beginNumber = ResolveOperand(code.Begin) as ScriptNumber;

            if (beginNumber == null)
            {
                throw new ExecutionException(m_script, "forsimple 初始值必须是number");
            }
            ScriptNumber finishedNumber = ResolveOperand(code.Finished) as ScriptNumber;

            if (finishedNumber == null)
            {
                throw new ExecutionException(m_script, "forsimple 最大值必须是number");
            }
            int begin    = beginNumber.ToInt32();
            int finished = finishedNumber.ToInt32();
            int step;

            if (code.Step != null)
            {
                ScriptNumber stepNumber = ResolveOperand(code.Step) as ScriptNumber;
                if (stepNumber == null)
                {
                    throw new ExecutionException(m_script, "forsimple Step必须是number");
                }
                step = stepNumber.ToInt32();
            }
            else
            {
                step = 1;
            }
            int           i = begin;
            ScriptContext context;

            for (; i <= finished; i += step)
            {
                context = new ScriptContext(m_script, code.BlockExecutable, this, Executable_Block.For);
                context.Initialize(code.Identifier, new ScriptNumberDouble(m_script, i));
                context.Execute();
                if (context.IsOver)
                {
                    break;
                }
            }
        }
Пример #4
0
        void ProcessCallForSimple()
        {
            CodeForSimple code        = (CodeForSimple)m_scriptInstruction.Operand0;
            ScriptNumber  beginNumber = ResolveOperand(code.Begin) as ScriptNumber;

            if (beginNumber == null)
            {
                throw new ExecutionException(m_script, "forsimple 初始值必须是number");
            }
            ScriptNumber finishedNumber = ResolveOperand(code.Finished) as ScriptNumber;

            if (finishedNumber == null)
            {
                throw new ExecutionException(m_script, "forsimple 最大值必须是number");
            }
            int begin    = beginNumber.ToInt32();
            int finished = finishedNumber.ToInt32();
            int step;

            if (code.Step != null)
            {
                ScriptNumber stepNumber = ResolveOperand(code.Step) as ScriptNumber;
                if (stepNumber == null)
                {
                    throw new ExecutionException(m_script, "forsimple Step必须是number");
                }
                step = stepNumber.ToInt32();
            }
            else
            {
                step = 1;
            }
            var variables = new Dictionary <String, ScriptObject>();

            for (int i = begin; i <= finished; i += step)
            {
                ScriptContext context = code.GetBlockContext();
                variables[code.Identifier] = m_script.CreateNumber(i);
                context.Initialize(this, variables);
                context.Execute();
                if (context.IsOver)
                {
                    break;
                }
            }
        }
Пример #5
0
        private void ProcessCallForSimple()
        {
            int           num3;
            CodeForSimple simple = (CodeForSimple)this.m_scriptInstruction.operand0;
            ScriptNumber  number = this.ResolveOperand(simple.Begin) as ScriptNumber;

            if (number == null)
            {
                throw new ExecutionException(this.m_script, "forsimple 初始值必须是number");
            }
            ScriptNumber number2 = this.ResolveOperand(simple.Finished) as ScriptNumber;

            if (number2 == null)
            {
                throw new ExecutionException(this.m_script, "forsimple 最大值必须是number");
            }
            int num  = number.ToInt32();
            int num2 = number2.ToInt32();

            if (simple.Step != null)
            {
                ScriptNumber number3 = this.ResolveOperand(simple.Step) as ScriptNumber;
                if (number3 == null)
                {
                    throw new ExecutionException(this.m_script, "forsimple Step必须是number");
                }
                num3 = number3.ToInt32();
            }
            else
            {
                num3 = 1;
            }
            for (double i = num; i <= num2; i += num3)
            {
                ScriptContext context = new ScriptContext(this.m_script, simple.BlockExecutable, this, Executable_Block.For);
                context.Initialize(simple.Identifier, new ScriptNumberDouble(this.m_script, i));
                context.Execute();
                if (context.IsOver)
                {
                    return;
                }
            }
        }