Skip to content

Commit

Permalink
Extract out program related methods in prep for extract class
Browse files Browse the repository at this point in the history
  • 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
Original file line number Diff line number Diff line change
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.