Changeset 9 for branches/Void
- Timestamp:
- Nov 9, 2009, 10:15:36 AM (15 years ago)
- Location:
- branches/Void
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Void/Example.void
r6 r9 1 1 Define Text 2 Define Text 3 Write Leave me 4 Write Heal the world 2 WriteLn Leave me 3 WriteLn Heal the world 5 4 Assign Text Hell 6 Assign Texts Hell 7 Pause 5 ReadLn -
branches/Void/UCompilator.pas
r8 r9 10 10 type 11 11 TOnErrorEvent = procedure (Text: string; var Terminate: Boolean; Position: TPoint) of object; 12 13 { TCompilator } 12 14 13 15 TCompilator = class … … 58 60 procedure TCompilator.ProcessLine(Line: string); 59 61 var 60 Command: string; 62 CommandName: string; 63 Command: TProcedure; 61 64 Variable: TVariable; 62 65 VariableName: string; 63 66 begin 64 67 with Model, BeginEnd do begin 65 Command := Parse(Line); 66 if Command = 'Write' then 67 with TCommand(Commands[Commands.Add(TCommand.Create)]) do begin 68 Name := 'WriteLn'; 69 Parameters.Add(Parse(Line)); 70 end else if Command = 'Define' then begin 71 VariableName := Parse(Line); 72 Variable := FindVariableByName(VariableName); 73 if Assigned(Variable) then DoError('Variable ' + VariableName + ' redefined') 74 else begin 75 Variable := TVariable.Create; 76 with Variable do begin 77 Name := VariableName; 78 VarType := 'string'; 68 CommandName := Parse(Line); 69 if CommandName = 'Define' then begin 70 VariableName := Parse(Line); 71 Variable := FindVariableByName(VariableName); 72 if Assigned(Variable) then DoError('Variable ' + VariableName + ' redefined') 73 else begin 74 Variable := TVariable.Create; 75 with Variable do begin 76 Name := VariableName; 77 VarType := 'string'; 78 end; 79 Variables.Add(Variable); 79 80 end; 80 Variables.Add(Variable); 81 end else if CommandName = 'Assign' then with TCommand(Commands[Commands.Add(TCommand.Create)]) do begin 82 VariableName := Parse(Line); 83 Variable := FindVariableByName(VariableName); 84 if not Assigned(Variable) then DoError('Undefined variable ' + VariableName) 85 else begin 86 Name := 'Assignment'; 87 Parameters.Add(VariableName); 88 Parameters.Add(Parse(Line)); 89 end; 90 end else begin 91 Command := FindProcedureByName(CommandName); 92 if Assigned(Command) then begin 93 with TCommand(Commands[Commands.Add(TCommand.Create)]) do begin 94 Name := CommandName; 95 96 end; 97 end else DoError('Unknown command ' + CommandName); 81 98 end; 82 end else if Command = 'Assign' then with TCommand(Commands[Commands.Add(TCommand.Create)]) do begin83 VariableName := Parse(Line);84 Variable := FindVariableByName(VariableName);85 if not Assigned(Variable) then DoError('Undefined variable ' + VariableName)86 else begin87 Name := 'Assignment';88 Parameters.Add(VariableName);89 Parameters.Add(Parse(Line));90 end;91 end else if Command = 'Pause' then with TCommand(Commands[Commands.Add(TCommand.Create)]) do begin92 Name := 'ReadLn';93 end else if Command = 'Exit' then with TCommand(Commands[Commands.Add(TCommand.Create)]) do begin94 Name := 'Exit';95 end else DoError('Unknown command ' + Command);96 97 99 end; 98 100 end; -
branches/Void/UMainForm.lfm
r8 r9 1 1 object MainForm: TMainForm 2 Left = 2592 Left = 457 3 3 Height = 525 4 Top = 1 244 Top = 112 5 5 Width = 660 6 6 Caption = 'Překladač Void' … … 17 17 Top = 22 18 18 Width = 279 19 ScrollBars = ssAutoBoth 19 20 TabOrder = 0 20 21 end … … 24 25 Top = 24 25 26 Width = 260 27 ScrollBars = ssAutoBoth 26 28 TabOrder = 1 27 29 end … … 44 46 object Memo3: TMemo 45 47 Left = 9 46 Height = 5348 Height = 77 47 49 Top = 443 48 Width = 548 50 Width = 549 51 ScrollBars = ssAutoBoth 49 52 TabOrder = 2 50 53 end -
branches/Void/UMainForm.pas
r8 r9 69 69 begin 70 70 with Compilator do begin 71 Memo3.Lines.Clear; 71 72 SourceCode.Assign(Memo1.Lines); 72 73 -
branches/Void/UModel.pas
r8 r9 21 21 end; 22 22 23 { TBeginEnd }24 25 23 TBeginEnd = class 26 24 Commands: TList; … … 28 26 destructor Destroy; override; 29 27 procedure Clear; 28 end; 29 30 TProcedure = class 31 Name: string; 32 Parameters: TStringList; 33 BeginEnd: TBeginEnd; 34 constructor Create; 35 destructor Destroy; override; 30 36 end; 31 37 … … 36 42 public 37 43 Variables: TList; 44 Procedures: TList; 38 45 BeginEnd: TBeginEnd; 39 46 function FindVariableByName(AName: string): TVariable; 47 function FindProcedureByName(AName: string): TProcedure; 48 procedure Init; 40 49 procedure Clear; 41 50 constructor Create; … … 51 60 Variables := TList.Create; 52 61 BeginEnd := TBeginEnd.Create; 62 Procedures := TList.Create; 53 63 end; 54 64 … … 60 70 TVariable(Variables[I]).Destroy; 61 71 Variables.Destroy; 72 for I := 0 to Procedures.Count - 1 do 73 TProcedure(Procedures[I]).Destroy; 74 Procedures.Destroy; 62 75 BeginEnd.Destroy; 63 76 inherited Destroy; … … 74 87 end; 75 88 89 function TModel.FindProcedureByName(AName: string): TProcedure; 90 var 91 I: Integer; 92 begin 93 I := 0; 94 while (I < Procedures.Count) and (TProcedure(Procedures[I]).Name <> AName) do 95 Inc(I); 96 if I < Procedures.Count then Result := Procedures[I] else Result := nil; 97 end; 98 99 procedure TModel.Init; 100 begin 101 with TProcedure(Procedures[Procedures.Add(TProcedure.Create)]) do begin 102 Name := 'WriteLn'; 103 end; 104 with TProcedure(Procedures[Procedures.Add(TProcedure.Create)]) do begin 105 Name := 'Exit'; 106 end; 107 with TProcedure(Procedures[Procedures.Add(TProcedure.Create)]) do begin 108 Name := 'ReadLn'; 109 end; 110 end; 111 76 112 procedure TModel.Clear; 77 113 var … … 82 118 Variables.Clear; 83 119 BeginEnd.Clear; 120 Init; 84 121 end; 85 122 … … 124 161 end; 125 162 163 constructor TProcedure.Create; 164 begin 165 BeginEnd := TBeginEnd.Create; 166 Parameters := TStringList.Create; 167 end; 168 169 destructor TProcedure.Destroy; 170 begin 171 Parameters.Destroy; 172 BeginEnd.Destroy; 173 inherited Destroy; 174 end; 175 126 176 end. 127 177 -
branches/Void/UOutputGenerator.pas
r8 r9 9 9 10 10 type 11 12 { TOutputGenerator } 13 11 14 TOutputGenerator = class 12 15 private … … 119 122 if Name = 'Assignment' then Output.Add(Parameters[0] + ' = ' + Parameters[1] + ';') 120 123 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 + ';'); 124 if Name = 'WriteLn' then Row := 'printf' 125 else if Name = 'ReadLn' then Row := 'scanf' 126 else if Name = 'Exit' then Row := 'exit'; 127 Row := Row + '('; 128 if Parameters.Count > 0 then begin 129 ParameterText := ''; 130 for P := 0 to Parameters.Count - 1 do 131 ParameterText := ParameterText + Parameters[P] + ', '; 132 Row := Row + Copy(ParameterText, 1, Length(ParameterText) - 2); 133 end; 134 Output.Add(Row + ');'); 129 135 end; 130 136 end; -
branches/Void/project1.lpi
r8 r9 9 9 <Icon Value="0"/> 10 10 <UseXPManifest Value="True"/> 11 <ActiveEditorIndexAtStart Value=" 1"/>11 <ActiveEditorIndexAtStart Value="2"/> 12 12 </General> 13 13 <VersionInfo> … … 46 46 <ResourceBaseClass Value="Form"/> 47 47 <UnitName Value="UMainForm"/> 48 <CursorPos X=" 39" Y="70"/>49 <TopLine Value=" 25"/>48 <CursorPos X="20" Y="71"/> 49 <TopLine Value="58"/> 50 50 <EditorIndex Value="0"/> 51 51 <UsageCount Value="20"/> … … 55 55 <Filename Value="UCompilator.pas"/> 56 56 <UnitName Value="UCompilator"/> 57 <CursorPos X=" 69" Y="85"/>58 <TopLine Value=" 66"/>57 <CursorPos X="20" Y="39"/> 58 <TopLine Value="35"/> 59 59 <EditorIndex Value="1"/> 60 60 <UsageCount Value="10"/> … … 65 65 <IsPartOfProject Value="True"/> 66 66 <UnitName Value="UOutputGenerator"/> 67 <CursorPos X=" 75" Y="81"/>68 <TopLine Value=" 74"/>67 <CursorPos X="15" Y="118"/> 68 <TopLine Value="110"/> 69 69 <EditorIndex Value="2"/> 70 70 <UsageCount Value="20"/> … … 73 73 <Unit4> 74 74 <Filename Value="Example.void"/> 75 <IsPartOfProject Value="True"/>76 75 <CursorPos X="1" Y="1"/> 77 76 <TopLine Value="1"/> … … 85 84 <IsPartOfProject Value="True"/> 86 85 <UnitName Value="UModel"/> 87 <CursorPos X="1" Y="1 9"/>88 <TopLine Value=" 11"/>86 <CursorPos X="1" Y="110"/> 87 <TopLine Value="83"/> 89 88 <EditorIndex Value="3"/> 90 89 <UsageCount Value="20"/> … … 94 93 <JumpHistory Count="30" HistoryIndex="29"> 95 94 <Position1> 96 <Filename Value="U MainForm.pas"/>97 <Caret Line=" 68" Column="42" TopLine="48"/>95 <Filename Value="UOutputGenerator.pas"/> 96 <Caret Line="97" Column="1" TopLine="84"/> 98 97 </Position1> 99 98 <Position2> 100 <Filename Value="U MainForm.pas"/>101 <Caret Line=" 69" Column="11" TopLine="55"/>99 <Filename Value="UCompilator.pas"/> 100 <Caret Line="53" Column="17" TopLine="52"/> 102 101 </Position2> 103 102 <Position3> 104 103 <Filename Value="UCompilator.pas"/> 105 <Caret Line=" 56" Column="18" TopLine="44"/>104 <Caret Line="64" Column="23" TopLine="52"/> 106 105 </Position3> 107 106 <Position4> 108 107 <Filename Value="UCompilator.pas"/> 109 <Caret Line=" 48" Column="5" TopLine="44"/>108 <Caret Line="69" Column="1" TopLine="53"/> 110 109 </Position4> 111 110 <Position5> 112 111 <Filename Value="UCompilator.pas"/> 113 <Caret Line=" 61" Column="6" TopLine="59"/>112 <Caret Line="87" Column="41" TopLine="1"/> 114 113 </Position5> 115 114 <Position6> 116 <Filename Value="U Compilator.pas"/>117 <Caret Line=" 19" Column="15" TopLine="4"/>115 <Filename Value="UModel.pas"/> 116 <Caret Line="30" Column="1" TopLine="2"/> 118 117 </Position6> 119 118 <Position7> 120 119 <Filename Value="UModel.pas"/> 121 <Caret Line=" 28" Column="21" TopLine="5"/>120 <Caret Line="138" Column="7" TopLine="118"/> 122 121 </Position7> 123 122 <Position8> 124 <Filename Value="U Compilator.pas"/>125 <Caret Line="2 3" Column="1" TopLine="4"/>123 <Filename Value="UModel.pas"/> 124 <Caret Line="28" Column="24" TopLine="13"/> 126 125 </Position8> 127 126 <Position9> 128 <Filename Value="U Compilator.pas"/>129 <Caret Line=" 47" Column="9" TopLine="32"/>127 <Filename Value="UModel.pas"/> 128 <Caret Line="29" Column="1" TopLine="13"/> 130 129 </Position9> 131 130 <Position10> 132 <Filename Value="UM ainForm.pas"/>133 <Caret Line=" 69" Column="11" TopLine="55"/>131 <Filename Value="UModel.pas"/> 132 <Caret Line="34" Column="5" TopLine="19"/> 134 133 </Position10> 135 134 <Position11> 136 <Filename Value="UM ainForm.pas"/>137 <Caret Line="7 2" Column="8" TopLine="57"/>135 <Filename Value="UModel.pas"/> 136 <Caret Line="70" Column="13" TopLine="54"/> 138 137 </Position11> 139 138 <Position12> 140 <Filename Value="U MainForm.pas"/>141 <Caret Line=" 73" Column="51" TopLine="57"/>139 <Filename Value="UCompilator.pas"/> 140 <Caret Line="20" Column="1" TopLine="13"/> 142 141 </Position12> 143 142 <Position13> 144 <Filename Value="U Model.pas"/>145 <Caret Line=" 27" Column="1" TopLine="16"/>143 <Filename Value="UCompilator.pas"/> 144 <Caret Line="66" Column="20" TopLine="46"/> 146 145 </Position13> 147 146 <Position14> 148 <Filename Value="U Model.pas"/>149 <Caret Line=" 59" Column="11" TopLine="46"/>147 <Filename Value="UCompilator.pas"/> 148 <Caret Line="49" Column="18" TopLine="34"/> 150 149 </Position14> 151 150 <Position15> 152 <Filename Value="U Model.pas"/>153 <Caret Line=" 80" Column="8" TopLine="65"/>151 <Filename Value="UCompilator.pas"/> 152 <Caret Line="67" Column="64" TopLine="47"/> 154 153 </Position15> 155 154 <Position16> 156 <Filename Value="U Model.pas"/>157 <Caret Line=" 35" Column="20" TopLine="20"/>155 <Filename Value="UOutputGenerator.pas"/> 156 <Caret Line="19" Column="19" TopLine="1"/> 158 157 </Position16> 159 158 <Position17> 160 <Filename Value="U Model.pas"/>161 <Caret Line="2 7" Column="1" TopLine="8"/>159 <Filename Value="UOutputGenerator.pas"/> 160 <Caret Line="28" Column="3" TopLine="6"/> 162 161 </Position17> 163 162 <Position18> 164 <Filename Value="U Model.pas"/>165 <Caret Line=" 107" Column="1" TopLine="78"/>163 <Filename Value="UOutputGenerator.pas"/> 164 <Caret Line="35" Column="18" TopLine="13"/> 166 165 </Position18> 167 166 <Position19> 168 167 <Filename Value="UOutputGenerator.pas"/> 169 <Caret Line=" 81" Column="69" TopLine="79"/>168 <Caret Line="176" Column="1" TopLine="146"/> 170 169 </Position19> 171 170 <Position20> 172 <Filename Value="U OutputGenerator.pas"/>173 <Caret Line=" 74" Column="36" TopLine="59"/>171 <Filename Value="UCompilator.pas"/> 172 <Caret Line="43" Column="1" TopLine="43"/> 174 173 </Position20> 175 174 <Position21> 176 <Filename Value="U OutputGenerator.pas"/>177 <Caret Line=" 75" Column="30" TopLine="60"/>175 <Filename Value="UCompilator.pas"/> 176 <Caret Line="20" Column="1" TopLine="5"/> 178 177 </Position21> 179 178 <Position22> 180 <Filename Value="U OutputGenerator.pas"/>181 <Caret Line=" 79" Column="29" TopLine="58"/>179 <Filename Value="UCompilator.pas"/> 180 <Caret Line="51" Column="3" TopLine="35"/> 182 181 </Position22> 183 182 <Position23> 184 183 <Filename Value="UModel.pas"/> 185 <Caret Line=" 21" Column="1" TopLine="3"/>184 <Caret Line="47" Column="27" TopLine="21"/> 186 185 </Position23> 187 186 <Position24> 188 <Filename Value="U OutputGenerator.pas"/>189 <Caret Line=" 79" Column="12" TopLine="68"/>187 <Filename Value="UModel.pas"/> 188 <Caret Line="93" Column="14" TopLine="88"/> 190 189 </Position24> 191 190 <Position25> 192 <Filename Value="U OutputGenerator.pas"/>193 <Caret Line="8 5" Column="29" TopLine="64"/>191 <Filename Value="UModel.pas"/> 192 <Caret Line="88" Column="53" TopLine="78"/> 194 193 </Position25> 195 194 <Position26> 196 <Filename Value="U OutputGenerator.pas"/>197 <Caret Line=" 97" Column="1" TopLine="84"/>195 <Filename Value="UModel.pas"/> 196 <Caret Line="49" Column="5" TopLine="28"/> 198 197 </Position26> 199 198 <Position27> 200 <Filename Value="U Compilator.pas"/>201 <Caret Line=" 53" Column="17" TopLine="52"/>199 <Filename Value="UOutputGenerator.pas"/> 200 <Caret Line="19" Column="1" TopLine="13"/> 202 201 </Position27> 203 202 <Position28> 204 <Filename Value="U Compilator.pas"/>205 <Caret Line=" 64" Column="23" TopLine="52"/>203 <Filename Value="UOutputGenerator.pas"/> 204 <Caret Line="44" Column="1" TopLine="29"/> 206 205 </Position28> 207 206 <Position29> 208 <Filename Value="U Compilator.pas"/>209 <Caret Line=" 69" Column="1" TopLine="53"/>207 <Filename Value="UOutputGenerator.pas"/> 208 <Caret Line="97" Column="1" TopLine="83"/> 210 209 </Position29> 211 210 <Position30> 212 211 <Filename Value="UCompilator.pas"/> 213 <Caret Line="87" Column="41" TopLine=" 1"/>212 <Caret Line="87" Column="41" TopLine="79"/> 214 213 </Position30> 215 214 </JumpHistory>
Note:
See TracChangeset
for help on using the changeset viewer.