Permalink
Browse files

Extract out tape related methods

  • Loading branch information...
michaelgwelch committed Mar 23, 2012
1 parent 7ad3fd6 commit 746f4e3bbdd869b0863e2b18fe63423d59170152
Showing with 40 additions and 8 deletions.
  1. +40 −8 csharp/BrainmessShort/Main.cs
@@ -20,6 +20,38 @@ public static void Main(string[] args)
new Brainmess(reader.ReadToEnd()).Run();
reader.Close();
}
int MoveForward()
{
return tc++;
}
int MoveBackward()
{
return tc--;
}
int Increment()
{
return tape[tc]++;
}
int Decrement()
{
return tape[tc]--;
}
int Current
{
get
{
return tape[tc];
}
set
{
tape[tc] = value;
}
}
public void Run()
{
@@ -29,31 +61,31 @@ public void Run()
switch(instruction)
{
case '>':
tc++;
MoveForward();
break;
case '<':
tc--;
MoveBackward();
break;
case '+':
tape[tc]++;
Increment();
break;
case '-':
tape[tc]--;
Decrement();
break;
case '.':
Console.Write((char)tape[tc]);
Console.Write((char)Current);
break;
case ',':
tape[tc] = Console.Read();
Current = Console.Read();
break;
case '[':
if (tape[tc] == 0)
if (Current == 0)
{
_program.JumpForward();
}
break;
case ']':
if (tape[tc] != 0)
if (Current != 0)
{
_program.JumpBackward();
}

0 comments on commit 746f4e3

Please sign in to comment.