Exemple #1
0
 void Run()
 {
     Tape tape = new Tape();
     for (int pc = 0; pc < code.Length; ++pc)
     {
         switch (code[pc])
         {
         case '+':
             tape.Inc();
             break;
         case '-':
             tape.Dec();
             break;
         case '>':
             tape.Advance();
             break;
         case '<':
             tape.Devance();
             break;
         case '[':
             if (tape.Get() == 0) pc = bracket_map[pc];
             break;
         case ']':
             if (tape.Get() != 0) pc = bracket_map[pc];
             break;
         case '.':
             Console.Write((char)tape.Get());
             break;
         }
     }
 }
Exemple #2
0
        void Run()
        {
            Tape tape = new Tape();

            for (int pc = 0; pc < code.Length; ++pc)
            {
                switch (code[pc])
                {
                case '+':
                    tape.Inc();
                    break;

                case '-':
                    tape.Dec();
                    break;

                case '>':
                    tape.Advance();
                    break;

                case '<':
                    tape.Devance();
                    break;

                case '[':
                    if (tape.Get() == 0)
                    {
                        pc = bracket_map[pc];
                    }
                    break;

                case ']':
                    if (tape.Get() != 0)
                    {
                        pc = bracket_map[pc];
                    }
                    break;

                case '.':
                    Console.Write((char)tape.Get());
                    break;
                }
            }
        }
Exemple #3
0
        private void _run(List <Op> program, Tape tape)
        {
            foreach (Op op in program)
            {
                switch (op.op)
                {
                case OpT.INC: tape.Inc(op.v); break;

                case OpT.MOVE: tape.Move(op.v); break;

                case OpT.LOOP: while (tape.Get() > 0)
                    {
                        _run(op.loop, tape);
                    }
                    break;

                case OpT.PRINT: Console.Write((char)tape.Get()); break;
                }
            }
        }
Exemple #4
0
        private void _run(Op[] program, Tape tape)
        {
            foreach (Op op in program)
            {
                switch (op.op)
                {
                case OpT.INC: tape.Inc(op.v); break;

                case OpT.MOVE: tape.Move(op.v); break;

                case OpT.LOOP: while (tape.Get() > 0)
                    {
                        _run(op.loop, tape);
                    }
                    break;

                case OpT.PRINT: p.Print(tape.Get()); break;
                }
            }
        }
Exemple #5
0
        private void _run(Op[] program, Tape tape)
        {
            foreach (Op op in program)
            {
                switch (op.op)
                {
                case OpT.INC: tape.Inc(op.v); break;

                case OpT.MOVE: tape.Move(op.v); break;

                case OpT.LOOP: while (tape.Get() > 0)
                    {
                        _run(op.loop, tape);
                    }
                    break;

                case OpT.INPUT: tape.Set((int)Console.ReadKey().KeyChar); break;

                case OpT.PRINT: Console.Write((char)tape.Get()); break;
                }
            }
        }
Exemple #6
0
 private void _run(List<Op> program, Tape tape)
 {
     foreach (Op op in program) {
         switch (op.op) {
             case OpT.INC: tape.Inc(op.v); break;
             case OpT.MOVE: tape.Move(op.v); break;
             case OpT.LOOP: while (tape.Get() != 0) _run(op.loop, tape); break;
             case OpT.PRINT: Console.Write((char)tape.Get()); break;
         }
     }
 }