- Timestamp:
- Nov 9, 2009, 9:47:57 AM (15 years ago)
- Location:
- branches/Void
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Void/UCompilator.pas
r7 r8 62 62 VariableName: string; 63 63 begin 64 with Model do begin64 with Model, BeginEnd do begin 65 65 Command := Parse(Line); 66 66 if Command = 'Write' then 67 67 with TCommand(Commands[Commands.Add(TCommand.Create)]) do begin 68 Text := 'WriteLn(''' + Line + ''');'; 68 Name := 'WriteLn'; 69 Parameters.Add(Parse(Line)); 69 70 end else if Command = 'Define' then begin 70 71 VariableName := Parse(Line); … … 84 85 if not Assigned(Variable) then DoError('Undefined variable ' + VariableName) 85 86 else begin 86 Text := VariableName + ' := ''' + Parse(Line) + ''';'; 87 Name := 'Assignment'; 88 Parameters.Add(VariableName); 89 Parameters.Add(Parse(Line)); 87 90 end; 88 91 end else if Command = 'Pause' then with TCommand(Commands[Commands.Add(TCommand.Create)]) do begin 89 Text := 'ReadLn;';92 Name := 'ReadLn'; 90 93 end else if Command = 'Exit' then with TCommand(Commands[Commands.Add(TCommand.Create)]) do begin 91 Text := 'Exit;';94 Name := 'Exit'; 92 95 end else DoError('Unknown command ' + Command); 93 96 -
branches/Void/UMainForm.lfm
r6 r8 20 20 end 21 21 object Memo2: TMemo 22 Left = 29 523 Height = 40022 Left = 296 23 Height = 376 24 24 Top = 24 25 25 Width = 260 … … 66 66 TabOrder = 3 67 67 end 68 object ComboBox1: TComboBox 69 Left = 295 70 Height = 21 71 Top = 404 72 Width = 262 73 ItemHeight = 13 74 ItemIndex = 0 75 Items.Strings = ( 76 'Pascal' 77 'C' 78 ) 79 Style = csDropDownList 80 TabOrder = 4 81 Text = 'Pascal' 82 end 68 83 end -
branches/Void/UMainForm.pas
r7 r8 13 13 14 14 type 15 16 { TMainForm } 17 15 18 TMainForm = class(TForm) 16 19 ButtonCompile: TButton; 20 ComboBox1: TComboBox; 17 21 Label1: TLabel; 18 22 Label2: TLabel; … … 66 70 with Compilator do begin 67 71 SourceCode.Assign(Memo1.Lines); 68 Generator := TPascalGenerator.Create; 72 73 if Assigned(Generator) then Generator.Destroy; 74 if ComboBox1.ItemIndex = 0 then 75 Generator := TPascalGenerator.Create 76 else Generator := TCGenerator.Create; 69 77 Compile; 70 78 Memo2.Lines.Assign(Generator.Output); -
branches/Void/UModel.pas
r7 r8 15 15 16 16 TCommand = class 17 Text: string; 17 Name: string; 18 Parameters: TStringList; 19 constructor Create; 20 destructor Destroy; override; 21 end; 22 23 { TBeginEnd } 24 25 TBeginEnd = class 26 Commands: TList; 27 constructor Create; 28 destructor Destroy; override; 29 procedure Clear; 18 30 end; 19 31 … … 24 36 public 25 37 Variables: TList; 26 Commands: TList;38 BeginEnd: TBeginEnd; 27 39 function FindVariableByName(AName: string): TVariable; 28 40 procedure Clear; … … 38 50 begin 39 51 Variables := TList.Create; 40 Commands := TList.Create;52 BeginEnd := TBeginEnd.Create; 41 53 end; 42 54 … … 48 60 TVariable(Variables[I]).Destroy; 49 61 Variables.Destroy; 50 for I := 0 to Commands.Count - 1 do 51 TCommand(Commands[I]).Destroy; 52 Commands.Destroy; 62 BeginEnd.Destroy; 53 63 inherited Destroy; 54 64 end; … … 71 81 TVariable(Variables[I]).Destroy; 72 82 Variables.Clear; 83 BeginEnd.Clear; 84 end; 85 86 87 { TBeginEnd } 88 89 constructor TBeginEnd.Create; 90 begin 91 Commands := TList.Create; 92 end; 93 94 destructor TBeginEnd.Destroy; 95 var 96 I: Integer; 97 begin 98 for I := 0 to Commands.Count - 1 do 99 TCommand(Commands[I]).Destroy; 100 Commands.Destroy; 101 inherited Destroy; 102 end; 103 104 procedure TBeginEnd.Clear; 105 var 106 I: Integer; 107 begin 73 108 for I := 0 to Commands.Count - 1 do 74 109 TCommand(Commands[I]).Destroy; … … 76 111 end; 77 112 113 { TCommand } 114 115 constructor TCommand.Create; 116 begin 117 Parameters := TStringList.Create; 118 end; 119 120 destructor TCommand.Destroy; 121 begin 122 Parameters.Destroy; 123 inherited Destroy; 124 end; 78 125 79 126 end. -
branches/Void/UOutputGenerator.pas
r7 r8 54 54 procedure TPascalGenerator.Generate(Model: TModel); 55 55 var 56 I: Integer; 56 I, P: Integer; 57 ParameterText: string; 58 Row: string; 57 59 begin 58 60 inherited; … … 72 74 // Code block 73 75 Output.Add('begin'); 74 for I := 0 to Commands.Count - 1 do 75 with TCommand(Commands[I]) do 76 Output.Add(Text); 76 for I := 0 to BeginEnd.Commands.Count - 1 do 77 with TCommand(BeginEnd.Commands[I]) do begin 78 if Name = 'Assignment' then Output.Add(Parameters[0] + ' := ' + Parameters[1] + ';') 79 else begin 80 Row := Name; 81 if Parameters.Count > 0 then begin 82 ParameterText := ''; 83 for P := 0 to Parameters.Count - 1 do 84 ParameterText := ParameterText + Parameters[P] + ', '; 85 Row := Row + '(' + Copy(ParameterText, 1, Length(ParameterText) - 2) + ')'; 86 end; 87 Output.Add(Row + ';'); 88 end; 89 end; 77 90 Output.Add('end.'); 78 91 end; … … 82 95 83 96 procedure TCGenerator.Generate(Model: TModel); 84 begin 97 var 98 I, P: Integer; 99 Row: string; 100 ParameterText: string; 101 begin 85 102 inherited; 103 104 with Model do begin 105 // Prepare output 106 Output.Clear; 107 108 Output.Add('int main()'); 109 Output.Add('{'); 110 111 // variable section 112 for I := 0 to Variables.Count - 1 do 113 with TVariable(Variables[I]) do 114 Output.Add(' ' + VarType + ' ' + Name + ';'); 115 116 // Code block 117 for I := 0 to BeginEnd.Commands.Count - 1 do 118 with TCommand(BeginEnd.Commands[I]) do begin 119 if Name = 'Assignment' then Output.Add(Parameters[0] + ' = ' + Parameters[1] + ';') 120 else begin 121 Row := Name; 122 if Parameters.Count > 0 then begin 123 ParameterText := ''; 124 for P := 0 to Parameters.Count - 1 do 125 ParameterText := ParameterText + Parameters[P] + ', '; 126 Row := Row + '(' + Copy(ParameterText, 1, Length(ParameterText) - 2) + ')'; 127 end; 128 Output.Add(Row + ';'); 129 end; 130 end; 131 Output.Add('}'); 132 end; 86 133 end; 87 134 -
branches/Void/project1.lpi
r7 r8 46 46 <ResourceBaseClass Value="Form"/> 47 47 <UnitName Value="UMainForm"/> 48 <CursorPos X=" 11" Y="69"/>49 <TopLine Value=" 55"/>48 <CursorPos X="39" Y="70"/> 49 <TopLine Value="25"/> 50 50 <EditorIndex Value="0"/> 51 51 <UsageCount Value="20"/> … … 55 55 <Filename Value="UCompilator.pas"/> 56 56 <UnitName Value="UCompilator"/> 57 <CursorPos X=" 17" Y="53"/>58 <TopLine Value=" 43"/>57 <CursorPos X="69" Y="85"/> 58 <TopLine Value="66"/> 59 59 <EditorIndex Value="1"/> 60 60 <UsageCount Value="10"/> … … 65 65 <IsPartOfProject Value="True"/> 66 66 <UnitName Value="UOutputGenerator"/> 67 <CursorPos X=" 3" Y="38"/>68 <TopLine Value=" 27"/>67 <CursorPos X="75" Y="81"/> 68 <TopLine Value="74"/> 69 69 <EditorIndex Value="2"/> 70 70 <UsageCount Value="20"/> … … 85 85 <IsPartOfProject Value="True"/> 86 86 <UnitName Value="UModel"/> 87 <CursorPos X="1" Y=" 75"/>88 <TopLine Value=" 47"/>87 <CursorPos X="1" Y="19"/> 88 <TopLine Value="11"/> 89 89 <EditorIndex Value="3"/> 90 90 <UsageCount Value="20"/> … … 95 95 <Position1> 96 96 <Filename Value="UMainForm.pas"/> 97 <Caret Line=" 80" Column="61" TopLine="57"/>97 <Caret Line="68" Column="42" TopLine="48"/> 98 98 </Position1> 99 99 <Position2> 100 <Filename Value="U OutputGenerator.pas"/>101 <Caret Line=" 20" Column="34" TopLine="1"/>100 <Filename Value="UMainForm.pas"/> 101 <Caret Line="69" Column="11" TopLine="55"/> 102 102 </Position2> 103 103 <Position3> 104 <Filename Value="U OutputGenerator.pas"/>105 <Caret Line=" 16" Column="17" TopLine="1"/>104 <Filename Value="UCompilator.pas"/> 105 <Caret Line="56" Column="18" TopLine="44"/> 106 106 </Position3> 107 107 <Position4> 108 <Filename Value="U OutputGenerator.pas"/>109 <Caret Line=" 24" Column="40" TopLine="6"/>108 <Filename Value="UCompilator.pas"/> 109 <Caret Line="48" Column="5" TopLine="44"/> 110 110 </Position4> 111 111 <Position5> 112 <Filename Value="U OutputGenerator.pas"/>113 <Caret Line=" 32" Column="1" TopLine="20"/>112 <Filename Value="UCompilator.pas"/> 113 <Caret Line="61" Column="6" TopLine="59"/> 114 114 </Position5> 115 115 <Position6> 116 <Filename Value="U OutputGenerator.pas"/>117 <Caret Line=" 23" Column="15" TopLine="6"/>116 <Filename Value="UCompilator.pas"/> 117 <Caret Line="19" Column="15" TopLine="4"/> 118 118 </Position6> 119 119 <Position7> 120 <Filename Value="U OutputGenerator.pas"/>121 <Caret Line="2 9" Column="15" TopLine="8"/>120 <Filename Value="UModel.pas"/> 121 <Caret Line="28" Column="21" TopLine="5"/> 122 122 </Position7> 123 123 <Position8> 124 <Filename Value="U MainForm.pas"/>125 <Caret Line=" 9" Column="42" TopLine="1"/>124 <Filename Value="UCompilator.pas"/> 125 <Caret Line="23" Column="1" TopLine="4"/> 126 126 </Position8> 127 127 <Position9> 128 <Filename Value="U OutputGenerator.pas"/>129 <Caret Line=" 59" Column="5" TopLine="47"/>128 <Filename Value="UCompilator.pas"/> 129 <Caret Line="47" Column="9" TopLine="32"/> 130 130 </Position9> 131 131 <Position10> 132 <Filename Value="UM odel.pas"/>133 <Caret Line=" 19" Column="23" TopLine="8"/>132 <Filename Value="UMainForm.pas"/> 133 <Caret Line="69" Column="11" TopLine="55"/> 134 134 </Position10> 135 135 <Position11> 136 <Filename Value="UM odel.pas"/>137 <Caret Line=" 32" Column="14" TopLine="13"/>136 <Filename Value="UMainForm.pas"/> 137 <Caret Line="72" Column="8" TopLine="57"/> 138 138 </Position11> 139 139 <Position12> 140 <Filename Value="U OutputGenerator.pas"/>141 <Caret Line=" 8" Column="28" TopLine="1"/>140 <Filename Value="UMainForm.pas"/> 141 <Caret Line="73" Column="51" TopLine="57"/> 142 142 </Position12> 143 143 <Position13> 144 <Filename Value="U OutputGenerator.pas"/>145 <Caret Line="2 3" Column="15" TopLine="8"/>144 <Filename Value="UModel.pas"/> 145 <Caret Line="27" Column="1" TopLine="16"/> 146 146 </Position13> 147 147 <Position14> 148 <Filename Value="U OutputGenerator.pas"/>149 <Caret Line="5 6" Column="9" TopLine="51"/>148 <Filename Value="UModel.pas"/> 149 <Caret Line="59" Column="11" TopLine="46"/> 150 150 </Position14> 151 151 <Position15> 152 <Filename Value="U Compilator.pas"/>153 <Caret Line=" 13" Column="1" TopLine="1"/>152 <Filename Value="UModel.pas"/> 153 <Caret Line="80" Column="8" TopLine="65"/> 154 154 </Position15> 155 155 <Position16> 156 <Filename Value="U Compilator.pas"/>157 <Caret Line=" 18" Column="1" TopLine="16"/>156 <Filename Value="UModel.pas"/> 157 <Caret Line="35" Column="20" TopLine="20"/> 158 158 </Position16> 159 159 <Position17> 160 <Filename Value="U Compilator.pas"/>161 <Caret Line=" 63" Column="1" TopLine="48"/>160 <Filename Value="UModel.pas"/> 161 <Caret Line="27" Column="1" TopLine="8"/> 162 162 </Position17> 163 163 <Position18> 164 <Filename Value="U Compilator.pas"/>165 <Caret Line=" 22" Column="23" TopLine="11"/>164 <Filename Value="UModel.pas"/> 165 <Caret Line="107" Column="1" TopLine="78"/> 166 166 </Position18> 167 167 <Position19> 168 <Filename Value="U Compilator.pas"/>169 <Caret Line=" 21" Column="1" TopLine="11"/>168 <Filename Value="UOutputGenerator.pas"/> 169 <Caret Line="81" Column="69" TopLine="79"/> 170 170 </Position19> 171 171 <Position20> 172 <Filename Value="U Compilator.pas"/>173 <Caret Line=" 59" Column="1" TopLine="47"/>172 <Filename Value="UOutputGenerator.pas"/> 173 <Caret Line="74" Column="36" TopLine="59"/> 174 174 </Position20> 175 175 <Position21> 176 <Filename Value="U Compilator.pas"/>177 <Caret Line=" 104" Column="1" TopLine="89"/>176 <Filename Value="UOutputGenerator.pas"/> 177 <Caret Line="75" Column="30" TopLine="60"/> 178 178 </Position21> 179 179 <Position22> 180 <Filename Value="U MainForm.pas"/>181 <Caret Line=" 68" Column="42" TopLine="48"/>180 <Filename Value="UOutputGenerator.pas"/> 181 <Caret Line="79" Column="29" TopLine="58"/> 182 182 </Position22> 183 183 <Position23> 184 <Filename Value="UM ainForm.pas"/>185 <Caret Line=" 69" Column="11" TopLine="55"/>184 <Filename Value="UModel.pas"/> 185 <Caret Line="21" Column="1" TopLine="3"/> 186 186 </Position23> 187 187 <Position24> 188 <Filename Value="U Compilator.pas"/>189 <Caret Line=" 56" Column="18" TopLine="44"/>188 <Filename Value="UOutputGenerator.pas"/> 189 <Caret Line="79" Column="12" TopLine="68"/> 190 190 </Position24> 191 191 <Position25> 192 <Filename Value="U Compilator.pas"/>193 <Caret Line=" 48" Column="5" TopLine="44"/>192 <Filename Value="UOutputGenerator.pas"/> 193 <Caret Line="85" Column="29" TopLine="64"/> 194 194 </Position25> 195 195 <Position26> 196 <Filename Value="U Compilator.pas"/>197 <Caret Line=" 61" Column="6" TopLine="59"/>196 <Filename Value="UOutputGenerator.pas"/> 197 <Caret Line="97" Column="1" TopLine="84"/> 198 198 </Position26> 199 199 <Position27> 200 200 <Filename Value="UCompilator.pas"/> 201 <Caret Line=" 19" Column="15" TopLine="4"/>201 <Caret Line="53" Column="17" TopLine="52"/> 202 202 </Position27> 203 203 <Position28> 204 <Filename Value="U Model.pas"/>205 <Caret Line=" 28" Column="21" TopLine="5"/>204 <Filename Value="UCompilator.pas"/> 205 <Caret Line="64" Column="23" TopLine="52"/> 206 206 </Position28> 207 207 <Position29> 208 208 <Filename Value="UCompilator.pas"/> 209 <Caret Line=" 23" Column="1" TopLine="4"/>209 <Caret Line="69" Column="1" TopLine="53"/> 210 210 </Position29> 211 211 <Position30> 212 212 <Filename Value="UCompilator.pas"/> 213 <Caret Line=" 47" Column="9" TopLine="32"/>213 <Caret Line="87" Column="41" TopLine="1"/> 214 214 </Position30> 215 215 </JumpHistory>
Note:
See TracChangeset
for help on using the changeset viewer.