Changeset 10


Ignore:
Timestamp:
Feb 9, 2012, 8:39:34 PM (13 years ago)
Author:
chronos
Message:
  • Modified: Minor changes to compilation.
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        22LazFuckIDE.exe
        33LazFuckIDE.lps
         4backup
  • trunk/UBrainFuck.pas

    r9 r10  
    1919    procedure AddLine(Text: string);
    2020  public
     21    ProgramName: string;
    2122    Source: string;
    2223    Output: string;
     
    228229procedure TBrainFuckCompiler.AddLine(Text: string);
    229230begin
    230   Output := Output + DupeString(' ', Indent) + Text + LineEnding;
     231  Output := Output + DupeString('  ', Indent) + Text + LineEnding;
    231232end;
    232233
     
    238239  Output := '';
    239240
    240   AddLine('program Brainfuck;');
     241  AddLine('program ' + ProgramName + ';');
    241242  AddLine('');
    242243  AddLine('{$APPTYPE CONSOLE}');
    243244  AddLine('');
    244   AddLine('uses');
    245   AddLine('  Classes;');
    246   AddLine('  ');
    247245  AddLine('var');
    248246  AddLine('  Memory: array[0..30000] of Char;');
    249247  AddLine('  Position: Integer;');
    250248  AddLine('begin');
     249  Inc(Indent);
    251250  for I := 1 to Length(Source) do begin
    252251    case Source[I] of
    253252      '>': AddLine('Inc(Position);');
    254253      '<': AddLine('Dec(Position);');
    255       '+': AddLine('Memory[Position] := Memory[Position] + 1');
    256       '-': AddLine('Memory[Position] := Memory[Position] - 1');
     254      '+': AddLine('Memory[Position] := Succ(Memory[Position]);');
     255      '-': AddLine('Memory[Position] := Pred(Memory[Position]);');
    257256      '.': AddLine('Write(Memory[Position]);');
    258257      ',': AddLine('Read(Memory[Position]);');
    259258      '[': begin
    260         AddLine('while Memory[Position] <> 0 do begin');
    261         Inc(Indent, 2);
     259        AddLine('while Memory[Position] <> #0 do begin');
     260        Inc(Indent);
    262261      end;
    263262      ']': begin
    264         Dec(Indent, 2);
     263        Dec(Indent);
    265264        AddLine('end;');
    266265      end;
    267266    end;
    268267  end;
     268  Dec(Indent);
    269269  AddLine('end.');
    270270end;
  • trunk/UMainForm.pas

    r9 r10  
    182182begin
    183183  BrainFuckCompiler.Source := MemoSource.Text;
     184  BrainFuckCompiler.ProgramName := ExtractFileNameOnly(ProjectFileName);
    184185  BrainFuckCompiler.Compile;
    185186  CompiledForm.MemoCompiled.Text := BrainFuckCompiler.Output;
     
    207208procedure TMainForm.AProjectNewExecute(Sender: TObject);
    208209begin
    209   ProjectFileName := 'Project.bf';
     210  ProjectFileName := 'Project.b';
    210211  MemoSource.Clear;
    211212  UpdateInterface;
Note: See TracChangeset for help on using the changeset viewer.