Changeset 29 for branches/Analyzátor gramatiky/UGrammer.pas
- Timestamp:
- Nov 11, 2009, 11:11:13 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Analyzátor gramatiky/UGrammer.pas
r28 r29 6 6 7 7 uses 8 Classes, ComCtrls, SysUtils, Math, UGrammerRules ;8 Classes, ComCtrls, SysUtils, Math, UGrammerRules, fgl; 9 9 10 10 type … … 55 55 end; 56 56 57 TGrammerItemList = specialize TFPGObjectList<TGrammerItem>; 58 57 59 TGrammerRule = class 58 60 private 59 61 public 60 Ownership: TGrammerRule; 62 Token: Boolean; 63 Parent: TGrammerRule; 61 64 Name: string; 62 65 RuleType: TRuleType; 63 Items: T List; // of TGrammerItem;66 Items: TGrammerItemList; 64 67 procedure ClearProcessed; 65 68 function Add: TGrammerItem; … … 74 77 end; 75 78 79 TGrammerRuleList = specialize TFPGObjectList<TGrammerRule>; 80 76 81 TGrammer = class 77 82 public 78 Rules: T List; // of TGrammerRule;83 Rules: TGrammerRuleList; 79 84 TopRule: TGrammerRule; 80 85 constructor Create; … … 137 142 constructor TGrammerRule.Create; 138 143 begin 139 Ownership:= nil;140 Items := T List.Create;144 Parent := nil; 145 Items := TGrammerItemList.Create; 141 146 end; 142 147 143 148 destructor TGrammerRule.Destroy; 144 var 145 I: Integer; 146 begin 147 for I := 0 to Items.Count - 1 do 148 TGrammerItem(Items[I]).Free; 149 Items.Free; 149 begin 150 Items.Destroy; 150 151 inherited; 151 152 end; … … 184 185 Path.Items[High(Path.Items)].ItemIndex := I; 185 186 //Inc(Path.Items[High(Path.Items)].CharIndex); 186 TGrammerItem(Items[I]).GetPossibleCharacters(Path, Characters);187 Items[I].GetPossibleCharacters(Path, Characters); 187 188 end; 188 189 end; … … 202 203 end else begin 203 204 Path.Items[High(Path.Items)].ItemIndex := UseIndex; 204 TGrammerItem(Items[UseIndex]).GetPossibleCharacters(Path, Characters);205 Items[UseIndex].GetPossibleCharacters(Path, Characters); 205 206 end; 206 207 // Check repetition 207 if (UseIndex > 0) and not TGrammerItem(Items[UseIndex - 1]).Processed then208 if TGrammerItem(Items[UseIndex - 1]).Repetition then begin208 if (UseIndex > 0) and not Items[UseIndex - 1].Processed then 209 if Items[UseIndex - 1].Repetition then begin 209 210 TempPath.Items[High(TempPath.Items)].ItemIndex := UseIndex - 1; 210 TGrammerItem(Items[UseIndex - 1]).GetPossibleCharacters(TempPath, Characters);211 Items[UseIndex - 1].GetPossibleCharacters(TempPath, Characters); 211 212 end; 212 213 end; … … 224 225 I: Integer; 225 226 begin 226 for I := 0 to Rules.Count - 1 do with TGrammerRule(Rules[I])do begin227 for I := 0 to Rules.Count - 1 do with Rules[I] do begin 227 228 ClearProcessed; 228 229 end; … … 235 236 J: Integer; 236 237 begin 237 for I := 0 to Rules.Count - 1 do with TGrammerRule(Rules[I])do begin238 for II := 0 to Items.Count - 1 do with TGrammerItem(Items[II])do begin238 for I := 0 to Rules.Count - 1 do with Rules[I] do begin 239 for II := 0 to Items.Count - 1 do with Items[II] do begin 239 240 if (ItemType = itNonterminal) and (Rule = nil) then begin 240 241 J := 0; 241 while (J < Rules.Count) and ( TGrammerRule(Rules[J]).Name <> RuleName) do Inc(J);242 while (J < Rules.Count) and (Rules[J].Name <> RuleName) do Inc(J); 242 243 if J < Rules.Count then Rule := Rules[J] else 243 244 raise Exception.Create('Rule link correction failed on rule ' + … … 250 251 constructor TGrammer.Create; 251 252 begin 252 Rules := T List.Create;253 Rules := TGrammerRuleList.Create; 253 254 end; 254 255 255 256 destructor TGrammer.Destroy; 256 var 257 I: Integer; 258 begin 259 for I := 0 to Rules.Count - 1 do TGrammerRule(Rules[I]).Free; 260 Rules.Free; 257 begin 258 Rules.Destroy; 261 259 inherited; 262 260 end; … … 322 320 Index := High(Items); 323 321 while not Success and (Index >= 0) do begin 324 with Items[Index] do if TGrammerItem(Rule.Items[ItemIndex]).Repetition then begin322 with Items[Index] do if Rule.Items[ItemIndex].Repetition then begin 325 323 Success := True; 326 324 //Inc(CharIndex);
Note:
See TracChangeset
for help on using the changeset viewer.