Permalink
Browse files

Extract out program related methods in prep for extract class

  • Loading branch information...
michaelgwelch committed Mar 22, 2012
1 parent 74ad715 commit dbad7a86b5f5e850e11f897364d876c01ec8ae47
Showing with 18 additions and 3 deletions.
  1. +18 −3 csharp/BrainmessShort/Main.cs
@@ -20,12 +20,27 @@ public static void Main(string[] args)
new Brainmess(reader.ReadToEnd()).Run();
reader.Close();
}
char Fetch()
{
return program[pc];
}
int JumpForward()
{
return program.FindMatch(pc - 1) + 1;
}
int JumpBackward()
{
return program.FindMatch(pc - 1);
}
public void Run()
{
while(pc < program.Length)
{
char instruction = program[pc];
char instruction = Fetch ();
pc++;
switch(instruction)
{
@@ -50,13 +65,13 @@ public void Run()
case '[':
if (tape[tc] == 0)
{
pc = program.FindMatch(pc - 1) + 1;
pc = JumpForward ();
}
break;
case ']':
if (tape[tc] != 0)
{
pc = program.FindMatch(pc - 1);
pc = JumpBackward ();
}
break;
}

0 comments on commit dbad7a8

Please sign in to comment.