コード例 #1
0
ファイル: Interpreter.cs プロジェクト: scadiot/Dopascript
        InstructionResult ExecuteInstructionCondition(Instruction instruction)
        {
            InstructionCondition instructionCondition = instruction as InstructionCondition;

            for (int i = 0; i < instructionCondition.TestInstructions.Count; i++)
            {
                if (ExecuteInstruction(instructionCondition.TestInstructions[i]).Value.BoolValue)
                {
                    return(ExecuteBloc(instructionCondition.BlocInstructions[i].ToArray()));
                }
            }

            if (instructionCondition.TestInstructions.Count != instructionCondition.BlocInstructions.Count)
            {
                return(ExecuteBloc(instructionCondition.BlocInstructions.Last().ToArray()));
            }

            return(new InstructionResult());
        }
コード例 #2
0
        Instruction AnalyseCondition(Tokenizer.Token[] Tokens, int index, out int tokenCount)
        {
            InstructionCondition instructionCondition = new InstructionCondition();

            int tc = 0;

            tokenCount = 0;

            do
            {
                if (Tokens[index + tokenCount].TokenName == Tokenizer.TokenName.Else)
                {
                    tokenCount++;
                }

                if (Tokens[index + tokenCount].TokenName == Tokenizer.TokenName.Condition)
                {
                    Tokenizer.Token[] tokensTest = GetTokensBetweenParentheses(Tokens, index + tokenCount + 1);
                    instructionCondition.TestInstructions.Add(AnalyseInstruction(tokensTest, 0, out tc));
                    tokenCount += 3 + tokensTest.Length;
                }

                Tokenizer.Token[] tokensBloc = GetTokensInsideBloc(Tokens, index + tokenCount);
                int indexBloc = 0;
                List <Instruction> blocInstructions = new List <Instruction>();
                while (indexBloc < tokensBloc.Length)
                {
                    Instruction instruction = AnalyseInstruction(tokensBloc, indexBloc, out tc);
                    blocInstructions.Add(instruction);
                    indexBloc += tc;
                }
                instructionCondition.BlocInstructions.Add(blocInstructions);
                tokenCount += 2 + tokensBloc.Length;
            } while (index + tokenCount < Tokens.Length && Tokens[index + tokenCount].TokenName == Tokenizer.TokenName.Else);

            return(instructionCondition);
        }