- Timestamp:
- Nov 9, 2009, 8:59:48 AM (15 years ago)
- Location:
- branches/Void
- Files:
-
- 3 added
- 5 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/Example.void
r5 r6 1 Define Text 1 2 Define Text 2 3 Write Leave me 3 4 Write Heal the world 4 5 Assign Text Hell 6 Assign Texts Hell 5 7 Pause -
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; -
branches/Void/project1.lpi
r5 r6 5 5 <Version Value="7"/> 6 6 <General> 7 <Flags>8 <MainUnitHasCreateFormStatements Value="False"/>9 <MainUnitHasTitleStatement Value="False"/>10 </Flags>11 7 <MainUnit Value="0"/> 12 8 <TargetFileExt Value=".exe"/> 13 9 <Icon Value="0"/> 14 10 <UseXPManifest Value="True"/> 15 <ActiveEditorIndexAtStart Value=" 1"/>11 <ActiveEditorIndexAtStart Value="0"/> 16 12 </General> 17 13 <VersionInfo> … … 32 28 </local> 33 29 </RunParams> 34 <Units Count="4"> 30 <RequiredPackages Count="1"> 31 <Item1> 32 <PackageName Value="LCL"/> 33 </Item1> 34 </RequiredPackages> 35 <Units Count="3"> 35 36 <Unit0> 36 37 <Filename Value="project1.lpr"/> 37 38 <IsPartOfProject Value="True"/> 38 39 <UnitName Value="project1"/> 39 <CursorPos X="3" Y="45"/> 40 <TopLine Value="26"/> 41 <EditorIndex Value="0"/> 42 <UsageCount Value="25"/> 43 <Loaded Value="True"/> 40 <UsageCount Value="20"/> 44 41 </Unit0> 45 42 <Unit1> 46 <Filename Value="U Compilator.pas"/>43 <Filename Value="UMainForm.pas"/> 47 44 <IsPartOfProject Value="True"/> 48 <UnitName Value="UCompilator"/> 49 <CursorPos X="58" Y="124"/> 50 <TopLine Value="103"/> 51 <EditorIndex Value="1"/> 52 <UsageCount Value="25"/> 45 <ComponentName Value="MainForm"/> 46 <ResourceBaseClass Value="Form"/> 47 <UnitName Value="UMainForm"/> 48 <CursorPos X="23" Y="81"/> 49 <TopLine Value="57"/> 50 <EditorIndex Value="0"/> 51 <UsageCount Value="20"/> 53 52 <Loaded Value="True"/> 54 53 </Unit1> 55 54 <Unit2> 56 <Filename Value=" Example.void"/>57 < IsPartOfProject Value="True"/>58 <CursorPos X="2 4" Y="4"/>59 <TopLine Value=" 1"/>60 <EditorIndex Value=" 2"/>61 <UsageCount Value=" 25"/>55 <Filename Value="UCompilator.pas"/> 56 <UnitName Value="UCompilator"/> 57 <CursorPos X="26" Y="73"/> 58 <TopLine Value="41"/> 59 <EditorIndex Value="1"/> 60 <UsageCount Value="10"/> 62 61 <Loaded Value="True"/> 63 <SyntaxHighlighter Value="None"/>64 62 </Unit2> 65 <Unit3>66 <Filename Value="Notices.txt"/>67 <IsPartOfProject Value="True"/>68 <CursorPos X="3" Y="1"/>69 <TopLine Value="1"/>70 <EditorIndex Value="3"/>71 <UsageCount Value="24"/>72 <Loaded Value="True"/>73 <SyntaxHighlighter Value="None"/>74 </Unit3>75 63 </Units> 76 64 <JumpHistory Count="30" HistoryIndex="29"> 77 65 <Position1> 78 <Filename Value="U Compilator.pas"/>79 <Caret Line=" 51" Column="68" TopLine="36"/>66 <Filename Value="UMainForm.pas"/> 67 <Caret Line="42" Column="9" TopLine="28"/> 80 68 </Position1> 81 69 <Position2> 82 <Filename Value="U Compilator.pas"/>83 <Caret Line=" 52" Column="52" TopLine="37"/>70 <Filename Value="UMainForm.pas"/> 71 <Caret Line="12" Column="1" TopLine="9"/> 84 72 </Position2> 85 73 <Position3> 86 <Filename Value="U Compilator.pas"/>87 <Caret Line=" 20" Column="24" TopLine="9"/>74 <Filename Value="UMainForm.pas"/> 75 <Caret Line="3" Column="14" TopLine="1"/> 88 76 </Position3> 89 77 <Position4> 90 <Filename Value="U Compilator.pas"/>91 <Caret Line=" 57" Column="41" TopLine="42"/>78 <Filename Value="UMainForm.pas"/> 79 <Caret Line="40" Column="8" TopLine="25"/> 92 80 </Position4> 93 81 <Position5> 94 82 <Filename Value="UCompilator.pas"/> 95 <Caret Line=" 85" Column="1" TopLine="55"/>83 <Caret Line="31" Column="23" TopLine="16"/> 96 84 </Position5> 97 85 <Position6> 98 <Filename Value=" project1.lpr"/>99 <Caret Line=" 38" Column="5" TopLine="36"/>86 <Filename Value="UCompilator.pas"/> 87 <Caret Line="89" Column="1" TopLine="62"/> 100 88 </Position6> 101 89 <Position7> 102 90 <Filename Value="UCompilator.pas"/> 103 <Caret Line=" 28" Column="34" TopLine="10"/>91 <Caret Line="32" Column="23" TopLine="9"/> 104 92 </Position7> 105 93 <Position8> 106 94 <Filename Value="UCompilator.pas"/> 107 <Caret Line=" 86" Column="21" TopLine="70"/>95 <Caret Line="63" Column="30" TopLine="48"/> 108 96 </Position8> 109 97 <Position9> 110 98 <Filename Value="UCompilator.pas"/> 111 <Caret Line=" 11" Column="30" TopLine="3"/>99 <Caret Line="74" Column="24" TopLine="59"/> 112 100 </Position9> 113 101 <Position10> 114 <Filename Value="U Compilator.pas"/>115 <Caret Line=" 24" Column="59" TopLine="10"/>102 <Filename Value="UMainForm.pas"/> 103 <Caret Line="40" Column="8" TopLine="25"/> 116 104 </Position10> 117 105 <Position11> 118 <Filename Value="U Compilator.pas"/>119 <Caret Line="41" Column=" 35" TopLine="39"/>106 <Filename Value="UMainForm.pas"/> 107 <Caret Line="41" Column="9" TopLine="25"/> 120 108 </Position11> 121 109 <Position12> 122 110 <Filename Value="UCompilator.pas"/> 123 <Caret Line=" 81" Column="9" TopLine="52"/>111 <Caret Line="141" Column="23" TopLine="128"/> 124 112 </Position12> 125 113 <Position13> 126 114 <Filename Value="UCompilator.pas"/> 127 <Caret Line=" 24" Column="35" TopLine="9"/>115 <Caret Line="97" Column="11" TopLine="83"/> 128 116 </Position13> 129 117 <Position14> 130 <Filename Value="U Compilator.pas"/>131 <Caret Line="4 4" Column="57" TopLine="60"/>118 <Filename Value="UMainForm.pas"/> 119 <Caret Line="46" Column="1" TopLine="28"/> 132 120 </Position14> 133 121 <Position15> 134 <Filename Value="U Compilator.pas"/>135 <Caret Line=" 25" Column="1" TopLine="13"/>122 <Filename Value="UMainForm.pas"/> 123 <Caret Line="45" Column="1" TopLine="27"/> 136 124 </Position15> 137 125 <Position16> 138 <Filename Value="U Compilator.pas"/>139 <Caret Line=" 48" Column="55" TopLine="48"/>126 <Filename Value="UMainForm.pas"/> 127 <Caret Line="39" Column="10" TopLine="27"/> 140 128 </Position16> 141 129 <Position17> 142 <Filename Value="U Compilator.pas"/>143 <Caret Line=" 89" Column="22" TopLine="70"/>130 <Filename Value="UMainForm.pas"/> 131 <Caret Line="44" Column="10" TopLine="31"/> 144 132 </Position17> 145 133 <Position18> 146 <Filename Value="U Compilator.pas"/>147 <Caret Line=" 19" Column="9" TopLine="1"/>134 <Filename Value="UMainForm.pas"/> 135 <Caret Line="45" Column="42" TopLine="25"/> 148 136 </Position18> 149 137 <Position19> 150 <Filename Value="U Compilator.pas"/>151 <Caret Line=" 89" Column="22" TopLine="74"/>138 <Filename Value="UMainForm.pas"/> 139 <Caret Line="48" Column="1" TopLine="22"/> 152 140 </Position19> 153 141 <Position20> 154 <Filename Value="U Compilator.pas"/>155 <Caret Line=" 100" Column="24" TopLine="88"/>142 <Filename Value="UMainForm.pas"/> 143 <Caret Line="54" Column="1" TopLine="40"/> 156 144 </Position20> 157 145 <Position21> 158 <Filename Value="U Compilator.pas"/>159 <Caret Line=" 114" Column="23" TopLine="99"/>146 <Filename Value="UMainForm.pas"/> 147 <Caret Line="49" Column="1" TopLine="52"/> 160 148 </Position21> 161 149 <Position22> 162 <Filename Value=" project1.lpr"/>163 <Caret Line=" 18" Column="15" TopLine="1"/>150 <Filename Value="UMainForm.pas"/> 151 <Caret Line="85" Column="1" TopLine="55"/> 164 152 </Position22> 165 153 <Position23> 166 <Filename Value=" project1.lpr"/>167 <Caret Line=" 48" Column="52" TopLine="45"/>154 <Filename Value="UMainForm.pas"/> 155 <Caret Line="59" Column="14" TopLine="44"/> 168 156 </Position23> 169 157 <Position24> 170 <Filename Value=" project1.lpr"/>171 <Caret Line="4 4" Column="7" TopLine="30"/>158 <Filename Value="UMainForm.pas"/> 159 <Caret Line="48" Column="24" TopLine="40"/> 172 160 </Position24> 173 161 <Position25> 174 <Filename Value=" project1.lpr"/>175 <Caret Line=" 1" Column="5" TopLine="1"/>162 <Filename Value="UCompilator.pas"/> 163 <Caret Line="35" Column="21" TopLine="17"/> 176 164 </Position25> 177 165 <Position26> 178 <Filename Value=" project1.lpr"/>179 <Caret Line=" 40" Column="27" TopLine="26"/>166 <Filename Value="UCompilator.pas"/> 167 <Caret Line="72" Column="19" TopLine="59"/> 180 168 </Position26> 181 169 <Position27> 182 <Filename Value=" project1.lpr"/>183 <Caret Line=" 18" Column="49" TopLine="1"/>170 <Filename Value="UCompilator.pas"/> 171 <Caret Line="27" Column="27" TopLine="15"/> 184 172 </Position27> 185 173 <Position28> 186 <Filename Value=" project1.lpr"/>187 <Caret Line="51" Column=" 58" TopLine="50"/>174 <Filename Value="UCompilator.pas"/> 175 <Caret Line="51" Column="69" TopLine="36"/> 188 176 </Position28> 189 177 <Position29> 190 <Filename Value=" project1.lpr"/>191 <Caret Line=" 41" Column="16" TopLine="26"/>178 <Filename Value="UMainForm.pas"/> 179 <Caret Line="76" Column="3" TopLine="55"/> 192 180 </Position29> 193 181 <Position30> 194 <Filename Value="U Compilator.pas"/>195 <Caret Line=" 11" Column="77" TopLine="1"/>182 <Filename Value="UMainForm.pas"/> 183 <Caret Line="80" Column="61" TopLine="57"/> 196 184 </Position30> 197 185 </JumpHistory> … … 207 195 <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> 208 196 </SearchPaths> 197 <Linking> 198 <Options> 199 <Win32> 200 <GraphicApplication Value="True"/> 201 </Win32> 202 </Options> 203 </Linking> 209 204 <Other> 210 205 <CompilerPath Value="$(CompPath)"/> -
branches/Void/project1.lpr
r5 r6 1 1 program project1; 2 2 3 {$mode Delphi}{$H+}3 {$mode objfpc}{$H+} 4 4 5 5 uses … … 7 7 cthreads, 8 8 {$ENDIF}{$ENDIF} 9 Classes, SysUtils, CustApp, UCompilator; 10 11 type 12 13 { TApplication } 14 15 TApplication = class(TCustomApplication) 16 protected 17 procedure DoRun; override; 18 procedure CompilatorError(Text: string; var Terminate: Boolean); 19 public 20 Compilator: TCompilator; 21 constructor Create(TheOwner: TComponent); override; 22 destructor Destroy; override; 23 end; 24 25 { TApplication } 26 27 procedure TApplication.DoRun; 28 var 29 ErrorMsg: String; 30 begin 31 // quick check parameters 32 ErrorMsg := CheckOptions('h', 'help'); 33 if ErrorMsg <> '' then begin 34 ShowException(Exception.Create(ErrorMsg)); 35 Terminate; 36 Exit; 37 end; 38 39 Compilator := TCompilator.Create; 40 with Compilator do begin 41 OnError := CompilatorError; 42 Compile('Example.void'); 43 Destroy; 44 end; 45 ReadLn; 46 47 // stop program loop 48 Terminate; 49 end; 50 51 procedure TApplication.CompilatorError(Text: string; var Terminate: Boolean); 52 begin 53 Terminate := False; 54 WriteLn('Error: ' + Text); 55 end; 56 57 constructor TApplication.Create(TheOwner: TComponent); 58 begin 59 inherited Create(TheOwner); 60 StopOnException := True; 61 62 end; 63 64 destructor TApplication.Destroy; 65 begin 66 inherited Destroy; 67 end; 68 69 var 70 Application: TApplication; 9 Interfaces, // this includes the LCL widgetset 10 Forms, UMainForm, LResources 11 { you can add units after this }; 71 12 72 13 {$IFDEF WINDOWS}{$R project1.rc}{$ENDIF} 73 14 74 15 begin 75 Application := TApplication.Create(nil); 76 Application.Title := 'Application'; 16 {$I project1.lrs} 17 Application.Initialize; 18 Application.CreateForm(TMainForm, MainForm); 77 19 Application.Run; 78 Application.Free;79 20 end. 80 21
Note:
See TracChangeset
for help on using the changeset viewer.