Ignore:
Timestamp:
Nov 11, 2009, 11:11:13 AM (15 years ago)
Author:
george
Message:
  • Upraveno: Seznamy objektů přepsány na TFPGObjectList a použití generických typů.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Analyzátor gramatiky/UGrammer.pas

    r28 r29  
    66
    77uses
    8   Classes, ComCtrls, SysUtils, Math, UGrammerRules;
     8  Classes, ComCtrls, SysUtils, Math, UGrammerRules, fgl;
    99
    1010type
     
    5555  end;
    5656
     57  TGrammerItemList = specialize TFPGObjectList<TGrammerItem>;
     58
    5759  TGrammerRule = class
    5860  private
    5961  public
    60     Ownership: TGrammerRule;
     62    Token: Boolean;
     63    Parent: TGrammerRule;
    6164    Name: string;
    6265    RuleType: TRuleType;
    63     Items: TList; // of TGrammerItem;
     66    Items: TGrammerItemList;
    6467    procedure ClearProcessed;
    6568    function Add: TGrammerItem;
     
    7477  end;
    7578
     79  TGrammerRuleList = specialize TFPGObjectList<TGrammerRule>;
     80
    7681  TGrammer = class
    7782  public
    78     Rules: TList; // of TGrammerRule;
     83    Rules: TGrammerRuleList;
    7984    TopRule: TGrammerRule;
    8085    constructor Create;
     
    137142constructor TGrammerRule.Create;
    138143begin
    139   Ownership := nil;
    140   Items := TList.Create;
     144  Parent := nil;
     145  Items := TGrammerItemList.Create;
    141146end;
    142147
    143148destructor 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;   
     149begin
     150  Items.Destroy;
    150151  inherited;
    151152end;
     
    184185          Path.Items[High(Path.Items)].ItemIndex := I;
    185186          //Inc(Path.Items[High(Path.Items)].CharIndex);
    186           TGrammerItem(Items[I]).GetPossibleCharacters(Path, Characters);
     187          Items[I].GetPossibleCharacters(Path, Characters);
    187188        end;
    188189      end;
     
    202203      end else begin
    203204        Path.Items[High(Path.Items)].ItemIndex := UseIndex;
    204         TGrammerItem(Items[UseIndex]).GetPossibleCharacters(Path, Characters);
     205        Items[UseIndex].GetPossibleCharacters(Path, Characters);
    205206      end;
    206207      // Check repetition
    207       if (UseIndex > 0) and not TGrammerItem(Items[UseIndex - 1]).Processed then
    208         if TGrammerItem(Items[UseIndex - 1]).Repetition then begin
     208      if (UseIndex > 0) and not Items[UseIndex - 1].Processed then
     209        if Items[UseIndex - 1].Repetition then begin
    209210          TempPath.Items[High(TempPath.Items)].ItemIndex := UseIndex - 1;
    210           TGrammerItem(Items[UseIndex - 1]).GetPossibleCharacters(TempPath, Characters);
     211          Items[UseIndex - 1].GetPossibleCharacters(TempPath, Characters);
    211212        end;
    212213    end;
     
    224225  I: Integer;
    225226begin
    226   for I := 0 to Rules.Count - 1 do with TGrammerRule(Rules[I]) do begin
     227  for I := 0 to Rules.Count - 1 do with Rules[I] do begin
    227228    ClearProcessed;
    228229  end;
     
    235236  J: Integer;
    236237begin
    237   for I := 0 to Rules.Count - 1 do with TGrammerRule(Rules[I]) do begin
    238     for II := 0 to Items.Count - 1 do with TGrammerItem(Items[II]) do begin
     238  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
    239240      if (ItemType = itNonterminal) and (Rule = nil) then begin
    240241        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);
    242243        if J < Rules.Count then Rule := Rules[J] else
    243244          raise Exception.Create('Rule link correction failed on rule ' +
     
    250251constructor TGrammer.Create;
    251252begin
    252   Rules := TList.Create;
     253  Rules := TGrammerRuleList.Create;
    253254end;
    254255
    255256destructor 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;
     257begin
     258  Rules.Destroy;
    261259  inherited;
    262260end;
     
    322320  Index := High(Items);
    323321  while not Success and (Index >= 0) do begin
    324     with Items[Index] do if TGrammerItem(Rule.Items[ItemIndex]).Repetition then begin
     322    with Items[Index] do if Rule.Items[ItemIndex].Repetition then begin
    325323      Success := True;
    326324      //Inc(CharIndex);
Note: See TracChangeset for help on using the changeset viewer.