Changeset 5 for trunk/UBrainFuck.pas


Ignore:
Timestamp:
Feb 9, 2012, 2:51:41 PM (13 years ago)
Author:
chronos
Message:
  • Added: BrainFuck code examples.
  • Added: View of data memory in interpretter.
  • Added: Show execution information in interpretter form.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UBrainFuck.pas

    r3 r5  
    66
    77uses
    8   Classes, SysUtils, Dialogs;
     8  Classes, SysUtils, Dialogs, Forms;
    99
    1010type
     
    3535    Input: string;
    3636    InputPosition: Integer;
     37    StepCount: Integer;
    3738    procedure Reset;
    3839    procedure SingleStep;
     
    4849  SProgramLowerLimit = 'Program run over lower limit';
    4950  SProgramUpperLimit = 'Program run over upper limit';
     51  SReadInputError = 'Read input error';
    5052
    5153{ TBrainFuckInterpreter }
     
    6062  Character: string;
    6163begin
    62   Character := Copy(Input, InputPosition, 1);
    63   Result := Ord(Character[1]);
    64   Inc(InputPosition);
     64  if InputPosition < Length(Input) then begin
     65    Character := Copy(Input, InputPosition, 1);
     66    Result := Ord(Character[1]);
     67    Inc(InputPosition);
     68  end else
     69    raise Exception.Create(SReadInputError);
    6570end;
    6671
     
    8489    Memory[I] := 0;
    8590  SetLength(Loop, 0);
     91  StepCount := 0;
    8692end;
    8793
     
    129135  end;
    130136  Inc(SourcePosition);
     137  Inc(StepCount);
    131138end;
    132139
     
    134141begin
    135142  Reset;
    136   while SourcePosition < Length(Source) do
     143  while SourcePosition < Length(Source) do begin
    137144    SingleStep;
     145    Application.ProcessMessages;
     146  end;
    138147end;
    139148
Note: See TracChangeset for help on using the changeset viewer.