Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Extract out program related methods in prep for extract class
  • Loading branch information
michaelgwelch committed Mar 22, 2012
1 parent 74ad715 commit dbad7a8
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions csharp/BrainmessShort/Main.cs
Expand Up @@ -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)
{
Expand All @@ -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;
}
Expand Down

0 comments on commit dbad7a8

Please sign in to comment.