Changeset 20
- Timestamp:
- Feb 11, 2012, 10:56:03 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Compiler/UCompiler.pas
r19 r20 40 40 constructor TBrainFuckCompiler.Create; 41 41 begin 42 42 Optimization := coNormal; 43 43 end; 44 44 -
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); -
trunk/Compiler/UCompilerPHP.pas
r19 r20 31 31 var 32 32 I: Integer; 33 Sum: Integer; 34 35 function CheckOccurence(C: Char): Integer; 36 begin 37 Result := 1; 38 if Optimization = coNormal then 39 while ((I + 1) <= Length(Source)) and (Source[I + 1] = C) do begin 40 Inc(Result); 41 Inc(I) 42 end; 43 end; 44 33 45 begin 34 46 Indent := 0; … … 41 53 for I := 1 to Length(Source) do begin 42 54 case Source[I] of 43 '>': AddLine('$Position++;'); 44 '<': AddLine('$Position--;'); 45 '+': AddLine('$Memory[$Position] = chr(ord($Memory[$Position]) + 1);'); 46 '-': AddLine('$Memory[$Position] = chr(ord($Memory[$Position]) - 1);'); 55 '>': begin 56 Sum := CheckOccurence('>'); 57 AddLine('$Position = $Position + ' + IntToStr(Sum) + ';'); 58 end; 59 '<': begin 60 Sum := CheckOccurence('<'); 61 AddLine('$Position = $Position - ' + IntToStr(Sum) + ';'); 62 end; 63 '+': begin 64 Sum := CheckOccurence('+'); 65 AddLine('$Memory[$Position] = chr(ord($Memory[$Position]) + ' + IntToStr(Sum) + ');'); 66 end; 67 '-': begin 68 Sum := CheckOccurence('-'); 69 AddLine('$Memory[$Position] = chr(ord($Memory[$Position]) - ' + IntToStr(Sum) + ');'); 70 end; 47 71 '.': AddLine('echo($Memory[$Position]);'); 48 72 ',': AddLine('$Memory[$Position] = fgetc(STDIN);'); -
trunk/Languages/LazFuckIDE.cs.po
r19 r20 150 150 msgstr "UloÅŸit jako..." 151 151 152 #: tmainform.ashrinksource.caption 153 msgid "Shrink source" 154 msgstr "" 155 152 156 #: tmainform.aviewcompiled.caption 153 157 msgid "Compiled" … … 181 185 msgstr "ZobrazenÃ" 182 186 183 #: tmainform.menuitem21.caption184 msgid "New Item21"185 msgstr ""186 187 187 #: tmainform.menuitem24.caption 188 188 msgid "Tools" -
trunk/Languages/LazFuckIDE.po
r19 r20 141 141 msgstr "" 142 142 143 #: tmainform.ashrinksource.caption 144 msgid "Shrink source" 145 msgstr "" 146 143 147 #: tmainform.aviewcompiled.caption 144 148 msgid "Compiled" … … 172 176 msgstr "" 173 177 174 #: tmainform.menuitem21.caption175 msgid "New Item21"176 msgstr ""177 178 178 #: tmainform.menuitem24.caption 179 179 msgid "Tools" -
trunk/UMainForm.lfm
r19 r20 79 79 end 80 80 object ToolButton5: TToolButton 81 Left = 9381 Left = 116 82 82 Top = 2 83 83 Width = 10 … … 86 86 end 87 87 object ToolButton6: TToolButton 88 Left = 1 0388 Left = 149 89 89 Top = 2 90 90 Action = AProgramRun … … 96 96 end 97 97 object ToolButton8: TToolButton 98 Left = 14998 Left = 93 99 99 Top = 2 100 100 Action = AOptions 101 101 end 102 102 object ToolButton9: TToolButton 103 Left = 218 104 Top = 2 105 Action = ABreakpointToggle 106 end 107 object ToolButton10: TToolButton 103 108 Left = 172 104 109 Top = 2 105 Action = ABreakpointToggle 110 Action = AProgramPause 111 end 112 object ToolButton11: TToolButton 113 Left = 195 114 Top = 2 115 Action = AProgramStop 106 116 end 107 117 end … … 402 412 object MenuItemTarget: TMenuItem 403 413 Caption = 'Target' 404 object MenuItem21: TMenuItem405 Caption = 'New Item21'406 end407 414 end 408 415 object MenuItem17: TMenuItem … … 531 538 object MenuItem25: TMenuItem 532 539 Action = AFormatSource 540 end 541 object MenuItem27: TMenuItem 542 Action = AShrinkSource 533 543 end 534 544 end … … 727 737 Caption = 'Format source' 728 738 OnExecute = AFormatSourceExecute 739 end 740 object AShrinkSource: TAction 741 Caption = 'Shrink source' 742 OnExecute = AShrinkSourceExecute 729 743 end 730 744 end … … 1215 1229 Action = AFormatSource 1216 1230 end 1231 object MenuItem21: TMenuItem 1232 Action = AShrinkSource 1233 end 1217 1234 end 1218 1235 end -
trunk/UMainForm.lrt
r19 r20 5 5 TMAINFORM.MENUITEM9.CAPTION=Program 6 6 TMAINFORM.MENUITEMTARGET.CAPTION=Target 7 TMAINFORM.MENUITEM21.CAPTION=New Item218 7 TMAINFORM.MENUITEM17.CAPTION=- 9 8 TMAINFORM.MENUITEM24.CAPTION=Tools … … 31 30 TMAINFORM.AOPTIONS.CAPTION=Options 32 31 TMAINFORM.AFORMATSOURCE.CAPTION=Format source 32 TMAINFORM.ASHRINKSOURCE.CAPTION=Shrink source -
trunk/UMainForm.pas
r19 r20 18 18 AAbout: TAction; 19 19 ABreakpointToggle: TAction; 20 AShrinkSource: TAction; 20 21 AFormatSource: TAction; 21 22 AOptions: TAction; … … 54 55 MenuItem2: TMenuItem; 55 56 MenuItem20: TMenuItem; 57 MenuItem21: TMenuItem; 56 58 MenuItem22: TMenuItem; 57 59 MenuItem23: TMenuItem; … … 59 61 MenuItem25: TMenuItem; 60 62 MenuItem26: TMenuItem; 63 MenuItem27: TMenuItem; 61 64 MenuItemTarget: TMenuItem; 62 MenuItem21: TMenuItem;63 65 MenuItem3: TMenuItem; 64 66 MenuItem4: TMenuItem; … … 75 77 ToolBar1: TToolBar; 76 78 ToolButton1: TToolButton; 79 ToolButton10: TToolButton; 80 ToolButton11: TToolButton; 77 81 ToolButton2: TToolButton; 78 82 ToolButton3: TToolButton; … … 96 100 procedure AProjectSaveExecute(Sender: TObject); 97 101 procedure AProgramRunExecute(Sender: TObject); 102 procedure AShrinkSourceExecute(Sender: TObject); 98 103 procedure AViewCompiledExecute(Sender: TObject); 99 104 procedure AViewInterpretterExecute(Sender: TObject); … … 115 120 public 116 121 Modified: Boolean; 122 CompilerIndex: Integer; 117 123 ProjectFileName: string; 118 124 BrainFuckCompiler: TBrainFuckCompiler; … … 180 186 begin 181 187 with TMenuItem(Sender) do begin 188 CompilerIndex := MenuIndex; 182 189 Checked := True; 183 190 for I := 0 to Parent.Count - 1 do … … 219 226 NewMenuItem.Caption := TBrainFuckCompiler(Compilers[I]).Name; 220 227 NewMenuItem.OnClick := MenuItemTargetClick; 221 if I = 0then NewMenuItem.Checked := True;228 if I = CompilerIndex then NewMenuItem.Checked := True; 222 229 MenuItemTarget.Add(NewMenuItem); 223 230 end; … … 251 258 BrainFuckInterpreter.Source := MemoSource.Text; 252 259 BrainFuckInterpreter.Run; 260 end; 261 262 procedure TMainForm.AShrinkSourceExecute(Sender: TObject); 263 var 264 Source: string; 265 Pos: Integer; 266 I: Integer; 267 begin 268 Source := MemoSource.Text; 269 Pos := 1; 270 for I := 1 to Length(Source) do begin 271 if Source[I] > ' ' then begin 272 Source[Pos] := Source[I]; 273 Inc(Pos); 274 end; 275 end; 276 SetLength(Source, Pos - 1); 277 MemoSource.Text := Source; 253 278 end; 254 279 … … 310 335 311 336 procedure TMainForm.ACompileExecute(Sender: TObject); 312 var 313 I: Integer; 314 begin 315 I := 0; 316 while (I < MenuItemTarget.Count) and (not MenuItemTarget.Items[I].Checked) do Inc(I); 317 with TBrainFuckCompiler(Compilers[I]) do begin 337 begin 338 with TBrainFuckCompiler(Compilers[CompilerIndex]) do begin 339 Optimization := coNormal; 318 340 Source := MemoSource.Text; 319 341 ProgramName := ExtractFileNameOnly(ProjectFileName);
Note:
See TracChangeset
for help on using the changeset viewer.