- Timestamp:
- Feb 9, 2012, 4:10:10 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LazFuckIDE.lpi
r8 r9 39 39 </Item2> 40 40 </RequiredPackages> 41 <Units Count=" 5">41 <Units Count="6"> 42 42 <Unit0> 43 43 <Filename Value="LazFuckIDE.lpr"/> … … 69 69 <UnitName Value="UApplicationInfo"/> 70 70 </Unit4> 71 <Unit5> 72 <Filename Value="UCompiledForm.pas"/> 73 <IsPartOfProject Value="True"/> 74 <ComponentName Value="CompiledForm"/> 75 <ResourceBaseClass Value="Form"/> 76 <UnitName Value="UCompiledForm"/> 77 </Unit5> 71 78 </Units> 72 79 </ProjectOptions> -
trunk/LazFuckIDE.lpr
r8 r9 8 8 {$ENDIF}{$ENDIF} 9 9 Interfaces, // this includes the LCL widgetset 10 Forms, UMainForm, UBrainFuck, UInterpreterForm, UApplicationInfo 10 Forms, UMainForm, UBrainFuck, UInterpreterForm, UApplicationInfo, 11 UCompiledForm 11 12 { you can add units after this }; 12 13 … … 19 20 Application.CreateForm(TMainForm, MainForm); 20 21 Application.CreateForm(TInterpreterForm, InterpreterForm); 22 Application.CreateForm(TCompiledForm, CompiledForm); 21 23 Application.Run; 22 24 end. -
trunk/UBrainFuck.pas
r8 r9 6 6 7 7 uses 8 Classes, SysUtils, Dialogs, Forms ;8 Classes, SysUtils, Dialogs, Forms, StrUtils; 9 9 10 10 type 11 11 TBrainFuckInterpretter = class; 12 12 13 { TBrainFuck } 14 15 TBrainFuck = class 16 Source: TStringList; 17 Output: TStringList; 13 TCompilerTarget = (ctDelphi); 14 { TBrainFuckCompiler } 15 16 TBrainFuckCompiler = class 17 private 18 Indent: Integer; 19 procedure AddLine(Text: string); 20 public 21 Source: string; 22 Output: string; 23 Target: TCompilerTarget; 18 24 procedure Compile; 19 25 end; … … 218 224 end; 219 225 220 { TBrainFuck } 221 222 procedure TBrainFuck.Compile; 223 begin 224 226 { TBrainFuckCompiler } 227 228 procedure TBrainFuckCompiler.AddLine(Text: string); 229 begin 230 Output := Output + DupeString(' ', Indent) + Text + LineEnding; 231 end; 232 233 procedure TBrainFuckCompiler.Compile; 234 var 235 I: Integer; 236 begin 237 Indent := 0; 238 Output := ''; 239 240 AddLine('program Brainfuck;'); 241 AddLine(''); 242 AddLine('{$APPTYPE CONSOLE}'); 243 AddLine(''); 244 AddLine('uses'); 245 AddLine(' Classes;'); 246 AddLine(' '); 247 AddLine('var'); 248 AddLine(' Memory: array[0..30000] of Char;'); 249 AddLine(' Position: Integer;'); 250 AddLine('begin'); 251 for I := 1 to Length(Source) do begin 252 case Source[I] of 253 '>': AddLine('Inc(Position);'); 254 '<': AddLine('Dec(Position);'); 255 '+': AddLine('Memory[Position] := Memory[Position] + 1'); 256 '-': AddLine('Memory[Position] := Memory[Position] - 1'); 257 '.': AddLine('Write(Memory[Position]);'); 258 ',': AddLine('Read(Memory[Position]);'); 259 '[': begin 260 AddLine('while Memory[Position] <> 0 do begin'); 261 Inc(Indent, 2); 262 end; 263 ']': begin 264 Dec(Indent, 2); 265 AddLine('end;'); 266 end; 267 end; 268 end; 269 AddLine('end.'); 225 270 end; 226 271 -
trunk/UMainForm.lfm
r6 r9 1 1 object MainForm: TMainForm 2 Left = 2 702 Left = 258 3 3 Height = 465 4 Top = 12 04 Top = 121 5 5 Width = 643 6 6 Caption = 'LazFuck' … … 369 369 } 370 370 end 371 object MenuItem40: TMenuItem 372 Caption = 'Target' 373 object MenuItem21: TMenuItem 374 Caption = 'New Item21' 375 end 376 end 371 377 object MenuItem17: TMenuItem 372 378 Caption = '-' … … 416 422 object MenuItem16: TMenuItem 417 423 Action = AProgramStop 424 end 425 end 426 object MenuItem18: TMenuItem 427 Caption = 'View' 428 object MenuItem19: TMenuItem 429 Action = AViewInterpretter 430 end 431 object MenuItem20: TMenuItem 432 Action = AViewCompiled 418 433 end 419 434 end … … 507 522 Caption = 'Compile' 508 523 ImageIndex = 8 524 OnExecute = ACompileExecute 509 525 end 510 526 object AProgramRun: TAction … … 529 545 ImageIndex = 10 530 546 OnExecute = AProgramStopExecute 547 end 548 object AViewInterpretter: TAction 549 Caption = 'Interpretter' 550 OnExecute = AViewInterpretterExecute 551 end 552 object AViewCompiled: TAction 553 Caption = 'Compiled' 554 OnExecute = AViewCompiledExecute 531 555 end 532 556 end -
trunk/UMainForm.pas
r7 r9 16 16 ACompile: TAction; 17 17 AAbout: TAction; 18 AViewCompiled: TAction; 19 AViewInterpretter: TAction; 18 20 AProgramPause: TAction; 19 21 AProgramStop: TAction; … … 39 41 MenuItem16: TMenuItem; 40 42 MenuItem17: TMenuItem; 43 MenuItem18: TMenuItem; 44 MenuItem19: TMenuItem; 41 45 MenuItem2: TMenuItem; 46 MenuItem20: TMenuItem; 47 MenuItem40: TMenuItem; 48 MenuItem21: TMenuItem; 42 49 MenuItem3: TMenuItem; 43 50 MenuItem4: TMenuItem; … … 59 66 ToolButton6: TToolButton; 60 67 ToolButton7: TToolButton; 68 procedure ACompileExecute(Sender: TObject); 61 69 procedure AExitExecute(Sender: TObject); 62 70 procedure AProgramPauseExecute(Sender: TObject); … … 68 76 procedure AProjectSaveExecute(Sender: TObject); 69 77 procedure AProgramRunExecute(Sender: TObject); 78 procedure AViewCompiledExecute(Sender: TObject); 79 procedure AViewInterpretterExecute(Sender: TObject); 70 80 procedure FormCloseQuery(Sender: TObject; var CanClose: boolean); 71 81 procedure FormCreate(Sender: TObject); … … 78 88 Modified: Boolean; 79 89 ProjectFileName: string; 90 BrainFuckCompiler: TBrainFuckCompiler; 80 91 BrainFuckInterpreter: TBrainFuckInterpretter; 81 92 procedure UpdateInterface; … … 90 101 91 102 uses 92 UInterpreterForm, UApplicationInfo ;103 UInterpreterForm, UApplicationInfo, UCompiledForm; 93 104 94 105 { TMainForm } … … 131 142 BrainFuckInterpreter := TBrainFuckInterpretter.Create; 132 143 BrainFuckInterpreter.OnChangeState := BrainFuckInterpreterChangeState; 144 BrainFuckCompiler := TBrainFuckCompiler.Create; 133 145 end; 134 146 135 147 procedure TMainForm.FormDestroy(Sender: TObject); 136 148 begin 149 BrainFuckCompiler.Free; 137 150 BrainFuckInterpreter.Free; 138 151 end; … … 146 159 end; 147 160 161 procedure TMainForm.AViewCompiledExecute(Sender: TObject); 162 begin 163 CompiledForm.Show; 164 end; 165 166 procedure TMainForm.AViewInterpretterExecute(Sender: TObject); 167 begin 168 InterpreterForm.Show; 169 end; 170 148 171 procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: boolean); 149 172 begin 173 if Modified then AProjectSaveAs.Execute; 150 174 end; 151 175 … … 153 177 begin 154 178 Close; 179 end; 180 181 procedure TMainForm.ACompileExecute(Sender: TObject); 182 begin 183 BrainFuckCompiler.Source := MemoSource.Text; 184 BrainFuckCompiler.Compile; 185 CompiledForm.MemoCompiled.Text := BrainFuckCompiler.Output; 186 CompiledForm.Show; 155 187 end; 156 188
Note:
See TracChangeset
for help on using the changeset viewer.