Ejemplo n.º 1
0
        public DILOperationSet(LanguageInstruction[] languageInstructions)
        {
            for (int i = 0; i < languageInstructions.Length; i++)
            {
                var instruction = languageInstructions[i];

                if ((instruction == LanguageInstruction.Inc || instruction == LanguageInstruction.Dec))
                {
                    Add(new AdditionMemoryOp(0, instruction == LanguageInstruction.Inc ? 1 : -1));
                    continue;
                }

                if (instruction == LanguageInstruction.IncPtr || instruction == LanguageInstruction.DecPtr)
                {
                    Add(new PtrOp(instruction == LanguageInstruction.IncPtr ? 1 : -1));
                    continue;
                }

                if (instruction == LanguageInstruction.StartLoop || instruction == LanguageInstruction.EndLoop)
                {
                    if (instruction == LanguageInstruction.StartLoop)
                    {
                        var loop = Loop.Construct(languageInstructions, i);
                        Add(new LoopOp(loop));

                        i += loop.Instructions.Length + 1;
                    }

                    continue;
                }

                switch (instruction)
                {
                case LanguageInstruction.Output: Add(new WriteOp(0, 1)); break;

                case LanguageInstruction.Input: Add(new ReadOp(0, 1)); break;
                }
            }
        }