Changeset 7 for branches/Void
- Timestamp:
- Nov 9, 2009, 9:21:28 AM (15 years ago)
- Location:
- branches/Void
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Void/UCompilator.pas
r6 r7 6 6 7 7 uses 8 Classes, SysUtils ;8 Classes, SysUtils, UOutputGenerator, UModel; 9 9 10 10 type 11 11 TOnErrorEvent = procedure (Text: string; var Terminate: Boolean; Position: TPoint) of object; 12 12 13 TVariable = class14 Name: string;15 VarType: string;16 end;17 18 TCommand = class19 Text: string;20 end;21 22 13 TCompilator = class 23 14 private 24 15 FOnError: TOnErrorEvent; 25 Variables: TList;26 Commands: TList;27 16 ParsePosition: TPoint; 28 17 procedure DoError(Text: string); 29 function FindVariableByName(AName: string): TVariable;30 18 public 19 Model: TModel; 31 20 SourceCode: TStringList; 32 Output: TStringList;21 Generator: TOutputGenerator; 33 22 procedure Compile; 34 procedure Clear;35 23 procedure ProcessLine(Line: string); 36 24 constructor Create; … … 53 41 end; 54 42 55 function TCompilator.FindVariableByName(AName: string): TVariable;56 var57 I: Integer;58 begin59 I := 0;60 while (I < Variables.Count) and (TVariable(Variables[I]).Name <> AName) do61 Inc(I);62 if I < Variables.Count then Result := Variables[I] else Result := nil;63 end;64 65 43 procedure TCompilator.Compile; 66 44 var 67 45 I: Integer; 68 46 begin 69 Clear;47 Model.Clear; 70 48 71 49 // Process source lines … … 75 53 end; 76 54 77 // Prepare output 78 Output.Clear; 79 Output.Add('program Test;'); 80 Output.Add('{$APPTYPE CONSOLE}'); 81 82 // var section 83 if Variables.Count > 0 then Output.Add('var'); 84 for I := 0 to Variables.Count - 1 do 85 with TVariable(Variables[I]) do 86 Output.Add(' ' + Name + ': ' + VarType + ';'); 87 88 // Code block 89 Output.Add('begin'); 90 for I := 0 to Commands.Count - 1 do 91 with TCommand(Commands[I]) do 92 Output.Add(Text); 93 Output.Add('end.'); 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; 55 Generator.Generate(Model); 107 56 end; 108 57 … … 113 62 VariableName: string; 114 63 begin 64 with Model do begin 115 65 Command := Parse(Line); 116 66 if Command = 'Write' then … … 141 91 Text := 'Exit;'; 142 92 end else DoError('Unknown command ' + Command); 93 94 end; 143 95 end; 144 96 … … 146 98 begin 147 99 SourceCode := TStringList.Create; 148 Output := TStringList.Create; 149 Variables := TList.Create; 150 Commands := TList.Create; 100 Model := TModel.Create; 151 101 end; 152 102 … … 155 105 I: Integer; 156 106 begin 157 Output.Destroy;158 for I := 0 to Variables.Count - 1 do159 TVariable(Variables[I]).Destroy;160 Variables.Destroy;161 for I := 0 to Commands.Count - 1 do162 TCommand(Commands[I]).Destroy;163 Commands.Destroy;164 107 SourceCode.Destroy; 108 Model.Destroy; 165 109 inherited Destroy; 166 110 end; -
branches/Void/UMainForm.pas
r6 r7 7 7 uses 8 8 Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, 9 StdCtrls, UCompilator ;9 StdCtrls, UCompilator, UOutputGenerator; 10 10 11 11 const … … 13 13 14 14 type 15 16 { TMainForm }17 18 15 TMainForm = class(TForm) 19 16 ButtonCompile: TButton; … … 69 66 with Compilator do begin 70 67 SourceCode.Assign(Memo1.Lines); 68 Generator := TPascalGenerator.Create; 71 69 Compile; 72 Memo2.Lines.Assign( Output);70 Memo2.Lines.Assign(Generator.Output); 73 71 end; 74 72 end; -
branches/Void/project1.lpi
r6 r7 9 9 <Icon Value="0"/> 10 10 <UseXPManifest Value="True"/> 11 <ActiveEditorIndexAtStart Value=" 0"/>11 <ActiveEditorIndexAtStart Value="1"/> 12 12 </General> 13 13 <VersionInfo> … … 33 33 </Item1> 34 34 </RequiredPackages> 35 <Units Count=" 3">35 <Units Count="6"> 36 36 <Unit0> 37 37 <Filename Value="project1.lpr"/> … … 46 46 <ResourceBaseClass Value="Form"/> 47 47 <UnitName Value="UMainForm"/> 48 <CursorPos X=" 23" Y="81"/>49 <TopLine Value="5 7"/>48 <CursorPos X="11" Y="69"/> 49 <TopLine Value="55"/> 50 50 <EditorIndex Value="0"/> 51 51 <UsageCount Value="20"/> … … 55 55 <Filename Value="UCompilator.pas"/> 56 56 <UnitName Value="UCompilator"/> 57 <CursorPos X=" 26" Y="73"/>58 <TopLine Value="4 1"/>57 <CursorPos X="17" Y="53"/> 58 <TopLine Value="43"/> 59 59 <EditorIndex Value="1"/> 60 60 <UsageCount Value="10"/> 61 61 <Loaded Value="True"/> 62 62 </Unit2> 63 <Unit3> 64 <Filename Value="UOutputGenerator.pas"/> 65 <IsPartOfProject Value="True"/> 66 <UnitName Value="UOutputGenerator"/> 67 <CursorPos X="3" Y="38"/> 68 <TopLine Value="27"/> 69 <EditorIndex Value="2"/> 70 <UsageCount Value="20"/> 71 <Loaded Value="True"/> 72 </Unit3> 73 <Unit4> 74 <Filename Value="Example.void"/> 75 <IsPartOfProject Value="True"/> 76 <CursorPos X="1" Y="1"/> 77 <TopLine Value="1"/> 78 <EditorIndex Value="4"/> 79 <UsageCount Value="20"/> 80 <Loaded Value="True"/> 81 <SyntaxHighlighter Value="None"/> 82 </Unit4> 83 <Unit5> 84 <Filename Value="UModel.pas"/> 85 <IsPartOfProject Value="True"/> 86 <UnitName Value="UModel"/> 87 <CursorPos X="1" Y="75"/> 88 <TopLine Value="47"/> 89 <EditorIndex Value="3"/> 90 <UsageCount Value="20"/> 91 <Loaded Value="True"/> 92 </Unit5> 63 93 </Units> 64 94 <JumpHistory Count="30" HistoryIndex="29"> 65 95 <Position1> 66 96 <Filename Value="UMainForm.pas"/> 67 <Caret Line=" 42" Column="9" TopLine="28"/>97 <Caret Line="80" Column="61" TopLine="57"/> 68 98 </Position1> 69 99 <Position2> 70 <Filename Value="U MainForm.pas"/>71 <Caret Line=" 12" Column="1" TopLine="9"/>100 <Filename Value="UOutputGenerator.pas"/> 101 <Caret Line="20" Column="34" TopLine="1"/> 72 102 </Position2> 73 103 <Position3> 74 <Filename Value="U MainForm.pas"/>75 <Caret Line=" 3" Column="14" TopLine="1"/>104 <Filename Value="UOutputGenerator.pas"/> 105 <Caret Line="16" Column="17" TopLine="1"/> 76 106 </Position3> 77 107 <Position4> 78 <Filename Value="U MainForm.pas"/>79 <Caret Line=" 40" Column="8" TopLine="25"/>108 <Filename Value="UOutputGenerator.pas"/> 109 <Caret Line="24" Column="40" TopLine="6"/> 80 110 </Position4> 81 111 <Position5> 82 <Filename Value="U Compilator.pas"/>83 <Caret Line="3 1" Column="23" TopLine="16"/>112 <Filename Value="UOutputGenerator.pas"/> 113 <Caret Line="32" Column="1" TopLine="20"/> 84 114 </Position5> 85 115 <Position6> 86 <Filename Value="U Compilator.pas"/>87 <Caret Line=" 89" Column="1" TopLine="62"/>116 <Filename Value="UOutputGenerator.pas"/> 117 <Caret Line="23" Column="15" TopLine="6"/> 88 118 </Position6> 89 119 <Position7> 90 <Filename Value="U Compilator.pas"/>91 <Caret Line=" 32" Column="23" TopLine="9"/>120 <Filename Value="UOutputGenerator.pas"/> 121 <Caret Line="29" Column="15" TopLine="8"/> 92 122 </Position7> 93 123 <Position8> 94 <Filename Value="U Compilator.pas"/>95 <Caret Line=" 63" Column="30" TopLine="48"/>124 <Filename Value="UMainForm.pas"/> 125 <Caret Line="9" Column="42" TopLine="1"/> 96 126 </Position8> 97 127 <Position9> 98 <Filename Value="U Compilator.pas"/>99 <Caret Line=" 74" Column="24" TopLine="59"/>128 <Filename Value="UOutputGenerator.pas"/> 129 <Caret Line="59" Column="5" TopLine="47"/> 100 130 </Position9> 101 131 <Position10> 102 <Filename Value="UM ainForm.pas"/>103 <Caret Line=" 40" Column="8" TopLine="25"/>132 <Filename Value="UModel.pas"/> 133 <Caret Line="19" Column="23" TopLine="8"/> 104 134 </Position10> 105 135 <Position11> 106 <Filename Value="UM ainForm.pas"/>107 <Caret Line=" 41" Column="9" TopLine="25"/>136 <Filename Value="UModel.pas"/> 137 <Caret Line="32" Column="14" TopLine="13"/> 108 138 </Position11> 109 139 <Position12> 110 <Filename Value="U Compilator.pas"/>111 <Caret Line=" 141" Column="23" TopLine="128"/>140 <Filename Value="UOutputGenerator.pas"/> 141 <Caret Line="8" Column="28" TopLine="1"/> 112 142 </Position12> 113 143 <Position13> 114 <Filename Value="U Compilator.pas"/>115 <Caret Line=" 97" Column="11" TopLine="83"/>144 <Filename Value="UOutputGenerator.pas"/> 145 <Caret Line="23" Column="15" TopLine="8"/> 116 146 </Position13> 117 147 <Position14> 118 <Filename Value="U MainForm.pas"/>119 <Caret Line=" 46" Column="1" TopLine="28"/>148 <Filename Value="UOutputGenerator.pas"/> 149 <Caret Line="56" Column="9" TopLine="51"/> 120 150 </Position14> 121 151 <Position15> 122 <Filename Value="U MainForm.pas"/>123 <Caret Line=" 45" Column="1" TopLine="27"/>152 <Filename Value="UCompilator.pas"/> 153 <Caret Line="13" Column="1" TopLine="1"/> 124 154 </Position15> 125 155 <Position16> 126 <Filename Value="U MainForm.pas"/>127 <Caret Line=" 39" Column="10" TopLine="27"/>156 <Filename Value="UCompilator.pas"/> 157 <Caret Line="18" Column="1" TopLine="16"/> 128 158 </Position16> 129 159 <Position17> 130 <Filename Value="U MainForm.pas"/>131 <Caret Line=" 44" Column="10" TopLine="31"/>160 <Filename Value="UCompilator.pas"/> 161 <Caret Line="63" Column="1" TopLine="48"/> 132 162 </Position17> 133 163 <Position18> 134 <Filename Value="U MainForm.pas"/>135 <Caret Line=" 45" Column="42" TopLine="25"/>164 <Filename Value="UCompilator.pas"/> 165 <Caret Line="22" Column="23" TopLine="11"/> 136 166 </Position18> 137 167 <Position19> 138 <Filename Value="U MainForm.pas"/>139 <Caret Line=" 48" Column="1" TopLine="22"/>168 <Filename Value="UCompilator.pas"/> 169 <Caret Line="21" Column="1" TopLine="11"/> 140 170 </Position19> 141 171 <Position20> 142 <Filename Value="U MainForm.pas"/>143 <Caret Line="5 4" Column="1" TopLine="40"/>172 <Filename Value="UCompilator.pas"/> 173 <Caret Line="59" Column="1" TopLine="47"/> 144 174 </Position20> 145 175 <Position21> 146 <Filename Value="U MainForm.pas"/>147 <Caret Line=" 49" Column="1" TopLine="52"/>176 <Filename Value="UCompilator.pas"/> 177 <Caret Line="104" Column="1" TopLine="89"/> 148 178 </Position21> 149 179 <Position22> 150 180 <Filename Value="UMainForm.pas"/> 151 <Caret Line=" 85" Column="1" TopLine="55"/>181 <Caret Line="68" Column="42" TopLine="48"/> 152 182 </Position22> 153 183 <Position23> 154 184 <Filename Value="UMainForm.pas"/> 155 <Caret Line=" 59" Column="14" TopLine="44"/>185 <Caret Line="69" Column="11" TopLine="55"/> 156 186 </Position23> 157 187 <Position24> 158 <Filename Value="U MainForm.pas"/>159 <Caret Line=" 48" Column="24" TopLine="40"/>188 <Filename Value="UCompilator.pas"/> 189 <Caret Line="56" Column="18" TopLine="44"/> 160 190 </Position24> 161 191 <Position25> 162 192 <Filename Value="UCompilator.pas"/> 163 <Caret Line=" 35" Column="21" TopLine="17"/>193 <Caret Line="48" Column="5" TopLine="44"/> 164 194 </Position25> 165 195 <Position26> 166 196 <Filename Value="UCompilator.pas"/> 167 <Caret Line=" 72" Column="19" TopLine="59"/>197 <Caret Line="61" Column="6" TopLine="59"/> 168 198 </Position26> 169 199 <Position27> 170 200 <Filename Value="UCompilator.pas"/> 171 <Caret Line=" 27" Column="27" TopLine="15"/>201 <Caret Line="19" Column="15" TopLine="4"/> 172 202 </Position27> 173 203 <Position28> 174 <Filename Value="U Compilator.pas"/>175 <Caret Line=" 51" Column="69" TopLine="36"/>204 <Filename Value="UModel.pas"/> 205 <Caret Line="28" Column="21" TopLine="5"/> 176 206 </Position28> 177 207 <Position29> 178 <Filename Value="U MainForm.pas"/>179 <Caret Line=" 76" Column="3" TopLine="55"/>208 <Filename Value="UCompilator.pas"/> 209 <Caret Line="23" Column="1" TopLine="4"/> 180 210 </Position29> 181 211 <Position30> 182 <Filename Value="U MainForm.pas"/>183 <Caret Line=" 80" Column="61" TopLine="57"/>212 <Filename Value="UCompilator.pas"/> 213 <Caret Line="47" Column="9" TopLine="32"/> 184 214 </Position30> 185 215 </JumpHistory> -
branches/Void/project1.lpr
r6 r7 8 8 {$ENDIF}{$ENDIF} 9 9 Interfaces, // this includes the LCL widgetset 10 Forms, UMainForm, LResources10 Forms, UMainForm, UOutputGenerator, LResources, UModel 11 11 { you can add units after this }; 12 12
Note:
See TracChangeset
for help on using the changeset viewer.