Changeset 20 for trunk/Compiler/UCompilerDelphi.pas
- Timestamp:
- Feb 11, 2012, 10:56:03 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Compiler/UCompilerDelphi.pas
r19 r20 30 30 var 31 31 I: Integer; 32 Sum: Integer; 33 34 function CheckOccurence(C: Char): Integer; 35 begin 36 Result := 1; 37 if Optimization = coNormal then 38 while ((I + 1) <= Length(Source)) and (Source[I + 1] = C) do begin 39 Inc(Result); 40 Inc(I) 41 end; 42 end; 43 32 44 begin 33 45 Indent := 0; … … 39 51 AddLine(''); 40 52 AddLine('var'); 41 AddLine(' Memory: array[0..30000] of Char;');42 AddLine(' Pos ition: Integer;');53 AddLine(' Memory: array[0..30000] of Byte;'); 54 AddLine(' Pos: Integer;'); 43 55 AddLine('begin'); 44 56 Inc(Indent); 45 for I := 1 to Length(Source) do begin 57 I := 1; 58 while (I <= Length(Source)) do begin 46 59 case Source[I] of 47 '>': AddLine('Inc(Position);'); 48 '<': AddLine('Dec(Position);'); 49 '+': AddLine('Memory[Position] := Succ(Memory[Position]);'); 50 '-': AddLine('Memory[Position] := Pred(Memory[Position]);'); 51 '.': AddLine('Write(Memory[Position]);'); 52 ',': AddLine('Read(Memory[Position]);'); 60 '>': begin 61 Sum := CheckOccurence('>'); 62 AddLine('Inc(Pos, ' + IntToStr(Sum) + ');'); 63 end; 64 '<': begin 65 Sum := CheckOccurence('<'); 66 AddLine('Dec(Pos, ' + IntToStr(Sum) + ');'); 67 end; 68 '+': begin 69 Sum := CheckOccurence('+'); 70 AddLine('Memory[Pos] := Memory[Pos] + ' + IntToStr(Sum) + ';'); 71 end; 72 '-': begin 73 Sum := CheckOccurence('-'); 74 AddLine('Memory[Pos] := Memory[Pos] - ' + IntToStr(Sum) + ';'); 75 end; 76 '.': AddLine('Write(Chr(Memory[Pos]));'); 77 ',': AddLine('Read(Chr(Memory[Pos]));'); 53 78 '[': begin 54 AddLine('while Memory[Pos ition] <> #0 do begin');79 AddLine('while Memory[Pos] <> 0 do begin'); 55 80 Inc(Indent); 56 81 end; … … 60 85 end; 61 86 end; 87 Inc(I); 62 88 end; 63 89 Dec(Indent);
Note:
See TracChangeset
for help on using the changeset viewer.