Changeset 6 for branches/Void/UCompilator.pas
- Timestamp:
- Nov 9, 2009, 8:59:48 AM (15 years ago)
- Location:
- branches/Void
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Void
- Property svn:ignore
-
old new 6 6 project1.exe 7 7 *.dsk 8 *.~dsk
-
- Property svn:ignore
-
branches/Void/UCompilator.pas
r5 r6 9 9 10 10 type 11 TOnErrorEvent = procedure (Text: string; var Terminate: Boolean ) of object;11 TOnErrorEvent = procedure (Text: string; var Terminate: Boolean; Position: TPoint) of object; 12 12 13 13 TVariable = class … … 25 25 Variables: TList; 26 26 Commands: TList; 27 ParsePosition: TPoint; 27 28 procedure DoError(Text: string); 28 29 function FindVariableByName(AName: string): TVariable; 29 30 public 31 SourceCode: TStringList; 30 32 Output: TStringList; 31 procedure Compile(FileName: string); 33 procedure Compile; 34 procedure Clear; 32 35 procedure ProcessLine(Line: string); 33 36 constructor Create; … … 46 49 begin 47 50 Terminate := False; 48 if Assigned(FOnError) then FOnError(Text, Terminate );51 if Assigned(FOnError) then FOnError(Text, Terminate, ParsePosition); 49 52 if Terminate then raise Exception.Create('Compilation terminated'); 50 53 end; … … 60 63 end; 61 64 62 procedure TCompilator.Compile (FileName: string);65 procedure TCompilator.Compile; 63 66 var 64 SourceCode: TStringList;65 67 I: Integer; 66 68 begin 67 SourceCode := TStringList.Create; 68 SourceCode.LoadFromFile(FileName); 69 Clear; 69 70 70 71 // Process source lines 71 72 for I := 0 to SourceCode.Count - 1 do begin 73 ParsePosition.Y := I; 72 74 ProcessLine(SourceCode[I]); 73 75 end; … … 75 77 // Prepare output 76 78 Output.Clear; 77 Output.Add('program ' + ExtractFileName(FileName) + ';');79 Output.Add('program Test;'); 78 80 Output.Add('{$APPTYPE CONSOLE}'); 79 81 … … 90 92 Output.Add(Text); 91 93 Output.Add('end.'); 92 Output.SaveToFile(ExtractFileName(FileName) + '.dpr'); 93 SourceCode.Destroy; 94 end; 95 96 procedure TCompilator.Clear; 97 var 98 I: Integer; 99 begin 100 for I := 0 to Variables.Count - 1 do 101 TVariable(Variables[I]).Destroy; 102 Variables.Clear; 103 for I := 0 to Commands.Count - 1 do 104 TCommand(Commands[I]).Destroy; 105 Commands.Clear; 106 Output.Clear; 94 107 end; 95 108 … … 99 112 Variable: TVariable; 100 113 VariableName: string; 101 114 begin 102 115 Command := Parse(Line); 103 WriteLn(Command);104 116 if Command = 'Write' then 105 117 with TCommand(Commands[Commands.Add(TCommand.Create)]) do begin … … 128 140 end else if Command = 'Exit' then with TCommand(Commands[Commands.Add(TCommand.Create)]) do begin 129 141 Text := 'Exit;'; 130 end else DoError('Unknown command :' + Command);142 end else DoError('Unknown command ' + Command); 131 143 end; 132 144 133 145 constructor TCompilator.Create; 134 146 begin 147 SourceCode := TStringList.Create; 135 148 Output := TStringList.Create; 136 149 Variables := TList.Create; … … 149 162 TCommand(Commands[I]).Destroy; 150 163 Commands.Destroy; 164 SourceCode.Destroy; 151 165 inherited Destroy; 152 166 end;
Note:
See TracChangeset
for help on using the changeset viewer.