コード例 #1
0
        Instruction AnalyseFor(Tokenizer.Token[] tokens, int index, out int tokenCount)
        {
            tokenCount = 0;

            InstructionFor instructionFor = new InstructionFor();

            Tokenizer.Token[]   tokensInstructions        = GetTokensBetweenParentheses(tokens, index + 1);
            Tokenizer.Token[][] tokensInstructionSplitted = SplitTokens(tokensInstructions, t => t.TokenName == Tokenizer.TokenName.LineEnd);

            int tc = 0;

            instructionFor.InitInstruction      = AnalyseInstruction(tokensInstructionSplitted[0], 0, out tc);
            instructionFor.TestInstruction      = AnalyseInstruction(tokensInstructionSplitted[1], 0, out tc);
            instructionFor.IncrementInstruction = AnalyseInstruction(tokensInstructionSplitted[2], 0, out tc);

            tokenCount += tokensInstructions.Length + 3;

            Tokenizer.Token[] tokensBloc = GetTokensInsideBloc(tokens, index + tokenCount);
            int indexBloc = 0;

            while (indexBloc < tokensBloc.Length)
            {
                Instruction instruction = AnalyseInstruction(tokensBloc, indexBloc, out tc);
                instructionFor.BlocInstruction.Add(instruction);
                indexBloc += tc;
            }

            tokenCount += 2 + tokensBloc.Length;

            return(instructionFor);
        }
コード例 #2
0
ファイル: Interpreter.cs プロジェクト: scadiot/Dopascript
        InstructionResult ExecuteInstructionFor(Instruction instruction)
        {
            InstructionFor instructionFor = instruction as InstructionFor;

            ExecuteInstruction(instructionFor.InitInstruction);

            while (ExecuteInstruction(instructionFor.TestInstruction).Value.BoolValue)
            {
                InstructionResult result = ExecuteBloc(instructionFor.BlocInstruction.ToArray());
                if (result != null)
                {
                    if (result.Return)
                    {
                        return(result);
                    }
                    else if (result.Break)
                    {
                        return(new InstructionResult()
                        {
                            Return = false
                        });
                    }
                }

                ExecuteInstruction(instructionFor.IncrementInstruction);
            }

            return(new InstructionResult());
        }