Changeset 10
- Timestamp:
- Feb 9, 2012, 8:39:34 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
old new 2 2 LazFuckIDE.exe 3 3 LazFuckIDE.lps 4 backup
-
- Property svn:ignore
-
trunk/UBrainFuck.pas
r9 r10 19 19 procedure AddLine(Text: string); 20 20 public 21 ProgramName: string; 21 22 Source: string; 22 23 Output: string; … … 228 229 procedure TBrainFuckCompiler.AddLine(Text: string); 229 230 begin 230 Output := Output + DupeString(' ', Indent) + Text + LineEnding;231 Output := Output + DupeString(' ', Indent) + Text + LineEnding; 231 232 end; 232 233 … … 238 239 Output := ''; 239 240 240 AddLine('program Brainfuck;');241 AddLine('program ' + ProgramName + ';'); 241 242 AddLine(''); 242 243 AddLine('{$APPTYPE CONSOLE}'); 243 244 AddLine(''); 244 AddLine('uses');245 AddLine(' Classes;');246 AddLine(' ');247 245 AddLine('var'); 248 246 AddLine(' Memory: array[0..30000] of Char;'); 249 247 AddLine(' Position: Integer;'); 250 248 AddLine('begin'); 249 Inc(Indent); 251 250 for I := 1 to Length(Source) do begin 252 251 case Source[I] of 253 252 '>': AddLine('Inc(Position);'); 254 253 '<': 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]);'); 257 256 '.': AddLine('Write(Memory[Position]);'); 258 257 ',': AddLine('Read(Memory[Position]);'); 259 258 '[': begin 260 AddLine('while Memory[Position] <> 0 do begin');261 Inc(Indent , 2);259 AddLine('while Memory[Position] <> #0 do begin'); 260 Inc(Indent); 262 261 end; 263 262 ']': begin 264 Dec(Indent , 2);263 Dec(Indent); 265 264 AddLine('end;'); 266 265 end; 267 266 end; 268 267 end; 268 Dec(Indent); 269 269 AddLine('end.'); 270 270 end; -
trunk/UMainForm.pas
r9 r10 182 182 begin 183 183 BrainFuckCompiler.Source := MemoSource.Text; 184 BrainFuckCompiler.ProgramName := ExtractFileNameOnly(ProjectFileName); 184 185 BrainFuckCompiler.Compile; 185 186 CompiledForm.MemoCompiled.Text := BrainFuckCompiler.Output; … … 207 208 procedure TMainForm.AProjectNewExecute(Sender: TObject); 208 209 begin 209 ProjectFileName := 'Project.b f';210 ProjectFileName := 'Project.b'; 210 211 MemoSource.Clear; 211 212 UpdateInterface;
Note:
See TracChangeset
for help on using the changeset viewer.