Changeset 30
- Timestamp:
- Nov 11, 2009, 12:56:32 PM (15 years ago)
- Location:
- branches/Analyzátor gramatiky
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Analyzátor gramatiky/PascalCompiler.lpi
r29 r30 9 9 <Icon Value="0"/> 10 10 <UseXPManifest Value="True"/> 11 <ActiveEditorIndexAtStart Value=" 2"/>11 <ActiveEditorIndexAtStart Value="0"/> 12 12 </General> 13 13 <VersionInfo> … … 31 31 </Item1> 32 32 </RequiredPackages> 33 <Units Count=" 4">33 <Units Count="6"> 34 34 <Unit0> 35 35 <Filename Value="PascalCompiler.lpr"/> 36 36 <IsPartOfProject Value="True"/> 37 <CursorPos X="1 " Y="13"/>37 <CursorPos X="11" Y="12"/> 38 38 <TopLine Value="1"/> 39 39 <EditorIndex Value="1"/> 40 <UsageCount Value="2 1"/>40 <UsageCount Value="25"/> 41 41 <Loaded Value="True"/> 42 42 </Unit0> … … 48 48 <ResourceBaseClass Value="Form"/> 49 49 <UnitName Value="UMainForm"/> 50 <CursorPos X=" 33" Y="582"/>51 <TopLine Value="5 72"/>50 <CursorPos X="23" Y="58"/> 51 <TopLine Value="54"/> 52 52 <EditorIndex Value="2"/> 53 <UsageCount Value="2 1"/>53 <UsageCount Value="25"/> 54 54 <Loaded Value="True"/> 55 55 </Unit1> … … 58 58 <IsPartOfProject Value="True"/> 59 59 <UnitName Value="UGrammer"/> 60 <CursorPos X=" 62" Y="57"/>61 <TopLine Value="3 7"/>60 <CursorPos X="1" Y="322"/> 61 <TopLine Value="307"/> 62 62 <EditorIndex Value="0"/> 63 <UsageCount Value="2 1"/>63 <UsageCount Value="25"/> 64 64 <Loaded Value="True"/> 65 65 </Unit2> … … 68 68 <IsPartOfProject Value="True"/> 69 69 <UnitName Value="UProgram"/> 70 <CursorPos X=" 5" Y="18"/>71 <TopLine Value=" 3"/>70 <CursorPos X="1" Y="101"/> 71 <TopLine Value="86"/> 72 72 <EditorIndex Value="3"/> 73 <UsageCount Value="2 1"/>73 <UsageCount Value="25"/> 74 74 <Loaded Value="True"/> 75 75 </Unit3> 76 <Unit4> 77 <Filename Value="..\..\..\..\..\Programy\Lazarus_0.9.29\lcl\include\control.inc"/> 78 <CursorPos X="1" Y="2775"/> 79 <TopLine Value="2760"/> 80 <UsageCount Value="12"/> 81 </Unit4> 82 <Unit5> 83 <Filename Value="..\..\..\..\..\Programy\Lazarus_0.9.29\fpc\2.3.1\source\rtl\objpas\fgl.pp"/> 84 <UnitName Value="fgl"/> 85 <CursorPos X="3" Y="707"/> 86 <TopLine Value="705"/> 87 <UsageCount Value="11"/> 88 </Unit5> 76 89 </Units> 77 90 <JumpHistory Count="30" HistoryIndex="29"> 78 91 <Position1> 79 <Filename Value="U MainForm.pas"/>80 <Caret Line=" 344" Column="1" TopLine="329"/>92 <Filename Value="UProgram.pas"/> 93 <Caret Line="105" Column="1" TopLine="90"/> 81 94 </Position1> 82 95 <Position2> 83 <Filename Value="U MainForm.pas"/>84 <Caret Line=" 21" Column="50" TopLine="1"/>96 <Filename Value="UProgram.pas"/> 97 <Caret Line="106" Column="1" TopLine="91"/> 85 98 </Position2> 86 99 <Position3> 87 <Filename Value="U MainForm.pas"/>88 <Caret Line="1 1" Column="52" TopLine="1"/>100 <Filename Value="UProgram.pas"/> 101 <Caret Line="107" Column="1" TopLine="92"/> 89 102 </Position3> 90 103 <Position4> 91 <Filename Value="U Grammer.pas"/>92 <Caret Line=" 63" Column="1" TopLine="60"/>104 <Filename Value="UProgram.pas"/> 105 <Caret Line="108" Column="1" TopLine="93"/> 93 106 </Position4> 94 107 <Position5> 95 <Filename Value="U MainForm.pas"/>96 <Caret Line="1 95" Column="31" TopLine="48"/>108 <Filename Value="UProgram.pas"/> 109 <Caret Line="111" Column="1" TopLine="96"/> 97 110 </Position5> 98 111 <Position6> 99 <Filename Value="U MainForm.pas"/>100 <Caret Line=" 398" Column="29" TopLine="383"/>112 <Filename Value="UProgram.pas"/> 113 <Caret Line="113" Column="1" TopLine="98"/> 101 114 </Position6> 102 115 <Position7> 103 <Filename Value="U MainForm.pas"/>104 <Caret Line=" 410" Column="27" TopLine="395"/>116 <Filename Value="UProgram.pas"/> 117 <Caret Line="115" Column="1" TopLine="100"/> 105 118 </Position7> 106 119 <Position8> 107 <Filename Value="U MainForm.pas"/>108 <Caret Line=" 419" Column="23" TopLine="404"/>120 <Filename Value="UProgram.pas"/> 121 <Caret Line="116" Column="1" TopLine="101"/> 109 122 </Position8> 110 123 <Position9> 111 <Filename Value="U MainForm.pas"/>112 <Caret Line=" 428" Column="23" TopLine="413"/>124 <Filename Value="UProgram.pas"/> 125 <Caret Line="117" Column="1" TopLine="102"/> 113 126 </Position9> 114 127 <Position10> 115 <Filename Value="U MainForm.pas"/>116 <Caret Line=" 438" Column="23" TopLine="360"/>128 <Filename Value="UGrammer.pas"/> 129 <Caret Line="322" Column="1" TopLine="307"/> 117 130 </Position10> 118 131 <Position11> 119 <Filename Value="U MainForm.pas"/>120 <Caret Line=" 564" Column="26" TopLine="549"/>132 <Filename Value="UGrammer.pas"/> 133 <Caret Line="323" Column="22" TopLine="309"/> 121 134 </Position11> 122 135 <Position12> 123 <Filename Value="U MainForm.pas"/>124 <Caret Line=" 645" Column="49" TopLine="629"/>136 <Filename Value="UGrammer.pas"/> 137 <Caret Line="324" Column="6" TopLine="311"/> 125 138 </Position12> 126 139 <Position13> 127 <Filename Value="U MainForm.pas"/>128 <Caret Line=" 656" Column="1" TopLine="628"/>140 <Filename Value="UGrammer.pas"/> 141 <Caret Line="25" Column="12" TopLine="10"/> 129 142 </Position13> 130 143 <Position14> 131 <Filename Value="U MainForm.pas"/>132 <Caret Line=" 601" Column="29" TopLine="586"/>144 <Filename Value="UGrammer.pas"/> 145 <Caret Line="328" Column="32" TopLine="311"/> 133 146 </Position14> 134 147 <Position15> 135 <Filename Value="U MainForm.pas"/>136 <Caret Line=" 620" Column="30" TopLine="605"/>148 <Filename Value="UProgram.pas"/> 149 <Caret Line="101" Column="1" TopLine="86"/> 137 150 </Position15> 138 151 <Position16> 139 <Filename Value="U MainForm.pas"/>140 <Caret Line=" 111" Column="1" TopLine="96"/>152 <Filename Value="UGrammer.pas"/> 153 <Caret Line="322" Column="1" TopLine="307"/> 141 154 </Position16> 142 155 <Position17> 143 <Filename Value="U MainForm.pas"/>144 <Caret Line="3 68" Column="20" TopLine="353"/>156 <Filename Value="UGrammer.pas"/> 157 <Caret Line="324" Column="1" TopLine="309"/> 145 158 </Position17> 146 159 <Position18> 147 <Filename Value="U MainForm.pas"/>148 <Caret Line="3 70" Column="3" TopLine="355"/>160 <Filename Value="UGrammer.pas"/> 161 <Caret Line="325" Column="1" TopLine="310"/> 149 162 </Position18> 150 163 <Position19> 151 <Filename Value="U MainForm.pas"/>152 <Caret Line="3 72" Column="1" TopLine="357"/>164 <Filename Value="UGrammer.pas"/> 165 <Caret Line="326" Column="1" TopLine="311"/> 153 166 </Position19> 154 167 <Position20> 155 <Filename Value="U MainForm.pas"/>156 <Caret Line="3 49" Column="1" TopLine="334"/>168 <Filename Value="UGrammer.pas"/> 169 <Caret Line="327" Column="1" TopLine="312"/> 157 170 </Position20> 158 171 <Position21> 159 <Filename Value="U MainForm.pas"/>160 <Caret Line="3 72" Column="1" TopLine="358"/>172 <Filename Value="UGrammer.pas"/> 173 <Caret Line="329" Column="1" TopLine="314"/> 161 174 </Position21> 162 175 <Position22> 163 <Filename Value="U Program.pas"/>164 <Caret Line=" 11" Column="27" TopLine="1"/>176 <Filename Value="UGrammer.pas"/> 177 <Caret Line="203" Column="1" TopLine="188"/> 165 178 </Position22> 166 179 <Position23> 167 <Filename Value="U Program.pas"/>168 <Caret Line=" 12" Column="3" TopLine="2"/>180 <Filename Value="UGrammer.pas"/> 181 <Caret Line="214" Column="1" TopLine="199"/> 169 182 </Position23> 170 183 <Position24> 171 <Filename Value="U Program.pas"/>172 <Caret Line=" 8" Column="51" TopLine="1"/>184 <Filename Value="UGrammer.pas"/> 185 <Caret Line="215" Column="1" TopLine="200"/> 173 186 </Position24> 174 187 <Position25> 175 <Filename Value="U Program.pas"/>176 <Caret Line="3 14" Column="49" TopLine="290"/>188 <Filename Value="UGrammer.pas"/> 189 <Caret Line="322" Column="1" TopLine="307"/> 177 190 </Position25> 178 191 <Position26> 179 <Filename Value="U Program.pas"/>180 <Caret Line=" 102" Column="1" TopLine="89"/>192 <Filename Value="UGrammer.pas"/> 193 <Caret Line="324" Column="1" TopLine="309"/> 181 194 </Position26> 182 195 <Position27> 183 <Filename Value="U Program.pas"/>184 <Caret Line=" 98" Column="1" TopLine="86"/>196 <Filename Value="UGrammer.pas"/> 197 <Caret Line="325" Column="1" TopLine="310"/> 185 198 </Position27> 186 199 <Position28> 187 <Filename Value="U Program.pas"/>188 <Caret Line="3 1" Column="22" TopLine="16"/>200 <Filename Value="UGrammer.pas"/> 201 <Caret Line="326" Column="1" TopLine="311"/> 189 202 </Position28> 190 203 <Position29> 191 <Filename Value="U Program.pas"/>192 <Caret Line=" 93" Column="3" TopLine="78"/>204 <Filename Value="UGrammer.pas"/> 205 <Caret Line="327" Column="1" TopLine="312"/> 193 206 </Position29> 194 207 <Position30> 195 <Filename Value="U MainForm.pas"/>196 <Caret Line=" 415" Column="43" TopLine="398"/>208 <Filename Value="UGrammer.pas"/> 209 <Caret Line="326" Column="1" TopLine="311"/> 197 210 </Position30> 198 211 </JumpHistory> … … 218 231 </CompilerOptions> 219 232 <Debugging> 233 <BreakPoints Count="2"> 234 <Item1> 235 <Source Value="UMainForm.pas"/> 236 <Line Value="70"/> 237 </Item1> 238 <Item2> 239 <Source Value="UProgram.pas"/> 240 <Line Value="101"/> 241 </Item2> 242 </BreakPoints> 220 243 <Exceptions Count="3"> 221 244 <Item1> -
branches/Analyzátor gramatiky/UGrammer.pas
r29 r30 20 20 end; 21 21 22 TPathItemList = specialize TFPGObjectList<TPathItem>; 23 22 24 TGrammerPath = class 23 Items: array of TPathItem;25 Items: TPathItemList; 24 26 procedure Assign(Source: TGrammerPath); 25 27 procedure Next; 28 constructor Create; 29 destructor Destroy; override; 26 30 end; 27 31 … … 32 36 end; 33 37 38 TPossibleCharacterList = specialize TFPGObjectList<TPossibleCharacter>; 39 40 { TPossibleCharacters } 41 34 42 TPossibleCharacters = class 35 Items: array of TPossibleCharacter;43 Items: TPossibleCharacterList; 36 44 procedure Assign(Source: TPossibleCharacters); 45 constructor Create; 46 destructor Destroy; override; 37 47 end; 38 48 … … 135 145 I: Integer; 136 146 begin 137 for I := 0 to Items.Count - 1 do with TGrammerItem(Items[I]) do begin 147 for I := 0 to Items.Count - 1 do 148 with Items[I] do begin 138 149 Processed := False; 139 150 end; … … 160 171 TempPath: TGrammerPath; 161 172 begin 162 SetLength(Path.Items, Length(Path.Items) + 1);163 with Path.Items[ High(Path.Items)] do begin173 TempPath := TGrammerPath.Create; 174 with Path.Items[Path.Items.Add(TPathItem.Create)] do begin 164 175 Rule := Self; 165 176 ItemIndex := UseIndex; … … 172 183 if UseIndex > 0 then begin 173 184 // Forward generation to upper item 174 SetLength(Path.Items, Length(Path.Items) - 1); 175 with Path.Items[High(Path.Items)] do begin 185 with Path.Items[Path.Items.Add(TPathItem.Create)] do begin 176 186 NextItemIndex := ItemIndex; 177 187 NextCharIndex := CharIndex; 178 188 NextRule := Rule; 179 189 end; 180 SetLength(Path.Items, Length(Path.Items)- 1);190 Path.Items.Delete(Path.Items.Count - 1); 181 191 NextRule.GetPossibleCharacters(Path, Characters, NextItemIndex + 1, NextCharIndex); 182 192 end else begin 183 193 // Generate alternatives 184 194 for I := 0 to Items.Count - 1 do begin 185 Path.Items[ High(Path.Items)].ItemIndex := I;195 Path.Items[Path.Items.Count - 1].ItemIndex := I; 186 196 //Inc(Path.Items[High(Path.Items)].CharIndex); 187 197 Items[I].GetPossibleCharacters(Path, Characters); … … 193 203 if UseIndex >= Items.Count then begin 194 204 // Forward generation to upper item 195 SetLength(Path.Items, Length(Path.Items)- 1);196 with Path.Items[ High(Path.Items)] do begin205 Path.Items.Delete(Path.Items.Count - 1); 206 with Path.Items[Path.Items.Count - 1] do begin 197 207 NextItemIndex := ItemIndex; 198 208 NextCharIndex := CharIndex; 199 209 NextRule := Rule; 200 210 end; 201 SetLength(Path.Items, Length(Path.Items)- 1);211 Path.Items.Delete(Path.Items.Count - 1); 202 212 NextRule.GetPossibleCharacters(Path, Characters, NextItemIndex + 1, NextCharIndex); 203 213 end else begin 204 Path.Items[ High(Path.Items)].ItemIndex := UseIndex;214 Path.Items[Path.Items.Count - 1].ItemIndex := UseIndex; 205 215 Items[UseIndex].GetPossibleCharacters(Path, Characters); 206 216 end; … … 208 218 if (UseIndex > 0) and not Items[UseIndex - 1].Processed then 209 219 if Items[UseIndex - 1].Repetition then begin 210 TempPath.Items[ High(TempPath.Items)].ItemIndex := UseIndex - 1;220 TempPath.Items[TempPath.Items.Count - 1].ItemIndex := UseIndex - 1; 211 221 Items[UseIndex - 1].GetPossibleCharacters(TempPath, Characters); 212 222 end; 213 223 end; 214 224 end; 225 TempPath.Destroy; 215 226 end; 216 227 … … 225 236 I: Integer; 226 237 begin 227 for I := 0 to Rules.Count - 1 do with Rules[I] do begin 238 for I := 0 to Rules.Count - 1 do 239 with Rules[I] do begin 228 240 ClearProcessed; 229 241 end; … … 278 290 case ItemType of 279 291 itTerminal: begin 280 SetLength(Characters.Items, Length(Characters.Items) + 1);281 Characters.Items[ High(Characters.Items)].Character := Character;282 Characters.Items[ High(Characters.Items)].RulePath.Assign(Path);283 with Characters.Items[ High(Characters.Items)].RulePath do begin284 Inc(Items[ High(Items)].ItemIndex);292 Characters.Items.Add(TPossibleCharacter.Create); 293 Characters.Items[Characters.Items.Count - 1].Character := Character; 294 Characters.Items[Characters.Items.Count - 1].RulePath.Assign(Path); 295 with Characters.Items[Characters.Items.Count - 1].RulePath do begin 296 Inc(Items[Items.Count - 1].ItemIndex); 285 297 end; 286 298 end; … … 292 304 // Forward generation to upper item 293 305 //SetLength(Path.Items, Length(Path.Items) - 1); 294 with Path.Items[ High(Path.Items)] do begin306 with Path.Items[Path.Items.Count - 1] do begin 295 307 NextItemIndex := ItemIndex; 296 308 NextCharIndex := CharIndex; 297 309 NextRule := Rule; 298 310 end; 299 SetLength(Path.Items, Length(Path.Items) - 1);311 Path.Items.Count := Path.Items.Count - 1; 300 312 NextRule.GetPossibleCharacters(Path, Characters, NextItemIndex + 1, NextCharIndex); 301 313 end; … … 308 320 I: Integer; 309 321 begin 310 SetLength(Items, Length(Source.Items)); 311 for I := 0 to High(Items) do Items[I].Assign(Source.Items[I]); 322 for I := 0 to Items.Count - 1 do 323 Items[I].Destroy; 324 Items.Count := Source.Items.Count; 325 for I := 0 to Items.Count - 1 do begin 326 Items[I] := TPathItem.Create; 327 Items[I].Assign(Source.Items[I]); 328 end; 312 329 end; 313 330 … … 318 335 begin 319 336 Success := False; 320 Index := High(Items);337 Index := Items.Count - 1; 321 338 while not Success and (Index >= 0) do begin 322 339 with Items[Index] do if Rule.Items[ItemIndex].Repetition then begin … … 331 348 end; 332 349 end; 333 SetLength(Items, Index + 1); 350 Items.Count := Index + 1; 351 end; 352 353 constructor TGrammerPath.Create; 354 begin 355 Items := TPathItemList.Create; 356 end; 357 358 destructor TGrammerPath.Destroy; 359 begin 360 Items.Destroy; 361 inherited Destroy; 334 362 end; 335 363 … … 358 386 I: Integer; 359 387 begin 360 SetLength(Items, Length(Source.Items)); 361 for I := 0 to High(Items) do Items[I].Assign(Source.Items[I]); 388 Items.Count := Source.Items.Count; 389 for I := 0 to Items.Count - 1 do 390 Items[I].Assign(Source.Items[I]); 391 end; 392 393 constructor TPossibleCharacters.Create; 394 begin 395 Items := TPossibleCharacterList.Create; 396 end; 397 398 destructor TPossibleCharacters.Destroy; 399 begin 400 Items.Destroy; 401 inherited Destroy; 362 402 end; 363 403 -
branches/Analyzátor gramatiky/UProgram.pas
r29 r30 6 6 7 7 uses 8 Classes, ComCtrls, SysUtils, Math,UGrammer, fgl;8 Classes, ComCtrls, SysUtils, UGrammer, fgl; 9 9 10 10 type … … 62 62 begin 63 63 SelectedProgramItem := TopItem; 64 for I := 0 to High(Path.Items) do with Path.Items[I] do begin 64 for I := 0 to Path.Items.Count - 1 do 65 with Path.Items[I] do begin 65 66 SelectedProgramItem.ItemType := itNonterminal; 66 67 if not Assigned(SelectedProgramItem.Rule) then SelectedProgramItem.Rule := Rule; … … 99 100 Level: array of Integer; 100 101 begin 101 SetLength(Path.Items, Length(Path.Items) + 1); 102 with Path.Items[High(Path.Items)] do begin 102 Path := TGrammerPath.Create; 103 Scope := TPossibleCharacters.Create; 104 105 with Path.Items[Path.Items.Add(TPathItem.Create)] do begin 103 106 Rule := Grammer.TopRule; 104 107 ItemIndex := 0; … … 110 113 if (Text[I] <> #13) and (Text[I] <> #10) then 111 114 begin 112 UseIndex := Path.Items[ High(Path.Items)].ItemIndex;113 UseCharIndex := Path.Items[ High(Path.Items)].CharIndex;114 UseRule := Path.Items[ High(Path.Items)].Rule;115 SetLength(Path.Items, Length(Path.Items)- 1);116 S etLength(Scope.Items, 0);115 UseIndex := Path.Items[Path.Items.Count - 1].ItemIndex; 116 UseCharIndex := Path.Items[Path.Items.Count - 1].CharIndex; 117 UseRule := Path.Items[Path.Items.Count - 1].Rule; 118 Path.Items.Delete(Path.Items.Count - 1); 119 Scope.Items.Clear; 117 120 Grammer.ClearProcessed; 118 121 UseRule.GetPossibleCharacters(Path, Scope, UseIndex, UseCharIndex); 119 C := Length(Scope.Items);122 C := Scope.Items.Count; 120 123 121 124 // Possible character selection 122 125 SetLength(Level, 0); 123 for II := 0 to High(Scope.Items) do with Scope.Items[II] do 126 for II := 0 to Scope.Items.Count - 1 do 127 with Scope.Items[II] do 124 128 begin 125 129 if (Character = Text[I]) then … … 174 178 end; 175 179 176 if C < Length(Scope.Items)then begin180 if C < Scope.Items.Count then begin 177 181 Path.Assign(Scope.Items[C].RulePath); 178 for II := 0 to Length(Path.Items) - 1 do with Path.Items[II] do begin 182 for II := 0 to Path.Items.Count - 1 do 183 with Path.Items[II] do begin 179 184 if Affected then Inc(CharIndex); 180 185 end; 181 186 Insert(Path, Scope.Items[C].Character); 182 for II := 0 to Length(Path.Items) - 1 do with Path.Items[II] do begin 187 for II := 0 to Path.Items.Count - 1 do 188 with Path.Items[II] do begin 183 189 Affected := False; 184 190 end; … … 186 192 end else begin 187 193 ExpectedCharacters := ''; 188 for II := 0 to Length(Scope.Items)- 1 do194 for II := 0 to Scope.Items.Count - 1 do 189 195 ExpectedCharacters := ExpectedCharacters + Scope.Items[II].Character; 190 196 //raise Exception.Create('Parse error. Expected "' + ExpectedCharacters + '" but found "' + Text[I] + '".'); … … 194 200 end; 195 201 end; 202 Path.Destroy; 203 Scope.Destroy; 196 204 end; 197 205
Note:
See TracChangeset
for help on using the changeset viewer.