Changeset 29


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ů.
Location:
branches/Analyzátor gramatiky
Files:
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • branches/Analyzátor gramatiky/PascalCompiler.lpi

    r28 r29  
    99      <Icon Value="0"/>
    1010      <UseXPManifest Value="True"/>
    11       <ActiveEditorIndexAtStart Value="1"/>
     11      <ActiveEditorIndexAtStart Value="2"/>
    1212    </General>
    1313    <VersionInfo>
    1414      <ProjectVersion Value=""/>
    15       <Language Value=""/>
    16       <CharSet Value=""/>
    1715    </VersionInfo>
    1816    <PublishOptions>
     
    3735        <Filename Value="PascalCompiler.lpr"/>
    3836        <IsPartOfProject Value="True"/>
    39         <CursorPos X="43" Y="17"/>
     37        <CursorPos X="1" Y="13"/>
    4038        <TopLine Value="1"/>
    4139        <EditorIndex Value="1"/>
    42         <UsageCount Value="20"/>
     40        <UsageCount Value="21"/>
    4341        <Loaded Value="True"/>
    4442      </Unit0>
     
    5048        <ResourceBaseClass Value="Form"/>
    5149        <UnitName Value="UMainForm"/>
    52         <CursorPos X="54" Y="14"/>
    53         <TopLine Value="1"/>
     50        <CursorPos X="33" Y="582"/>
     51        <TopLine Value="572"/>
    5452        <EditorIndex Value="2"/>
    55         <UsageCount Value="20"/>
     53        <UsageCount Value="21"/>
    5654        <Loaded Value="True"/>
    5755      </Unit1>
     
    6058        <IsPartOfProject Value="True"/>
    6159        <UnitName Value="UGrammer"/>
    62         <CursorPos X="30" Y="34"/>
    63         <TopLine Value="21"/>
     60        <CursorPos X="62" Y="57"/>
     61        <TopLine Value="37"/>
    6462        <EditorIndex Value="0"/>
    65         <UsageCount Value="20"/>
     63        <UsageCount Value="21"/>
    6664        <Loaded Value="True"/>
    6765      </Unit2>
     
    7068        <IsPartOfProject Value="True"/>
    7169        <UnitName Value="UProgram"/>
    72         <CursorPos X="14" Y="4"/>
    73         <TopLine Value="1"/>
     70        <CursorPos X="5" Y="18"/>
     71        <TopLine Value="3"/>
    7472        <EditorIndex Value="3"/>
    75         <UsageCount Value="20"/>
     73        <UsageCount Value="21"/>
    7674        <Loaded Value="True"/>
    7775      </Unit3>
    7876    </Units>
    79     <JumpHistory Count="6" HistoryIndex="5">
     77    <JumpHistory Count="30" HistoryIndex="29">
    8078      <Position1>
    81         <Filename Value="UGrammer.pas"/>
    82         <Caret Line="13" Column="5" TopLine="1"/>
     79        <Filename Value="UMainForm.pas"/>
     80        <Caret Line="344" Column="1" TopLine="329"/>
    8381      </Position1>
    8482      <Position2>
    85         <Filename Value="UGrammer.pas"/>
    86         <Caret Line="4" Column="1" TopLine="1"/>
     83        <Filename Value="UMainForm.pas"/>
     84        <Caret Line="21" Column="50" TopLine="1"/>
    8785      </Position2>
    8886      <Position3>
    89         <Filename Value="UGrammer.pas"/>
    90         <Caret Line="13" Column="20" TopLine="1"/>
     87        <Filename Value="UMainForm.pas"/>
     88        <Caret Line="11" Column="52" TopLine="1"/>
    9189      </Position3>
    9290      <Position4>
    9391        <Filename Value="UGrammer.pas"/>
    94         <Caret Line="22" Column="23" TopLine="9"/>
     92        <Caret Line="63" Column="1" TopLine="60"/>
    9593      </Position4>
    9694      <Position5>
    97         <Filename Value="UGrammer.pas"/>
    98         <Caret Line="28" Column="29" TopLine="16"/>
     95        <Filename Value="UMainForm.pas"/>
     96        <Caret Line="195" Column="31" TopLine="48"/>
    9997      </Position5>
    10098      <Position6>
    101         <Filename Value="PascalCompiler.lpr"/>
    102         <Caret Line="3" Column="1" TopLine="1"/>
     99        <Filename Value="UMainForm.pas"/>
     100        <Caret Line="398" Column="29" TopLine="383"/>
    103101      </Position6>
     102      <Position7>
     103        <Filename Value="UMainForm.pas"/>
     104        <Caret Line="410" Column="27" TopLine="395"/>
     105      </Position7>
     106      <Position8>
     107        <Filename Value="UMainForm.pas"/>
     108        <Caret Line="419" Column="23" TopLine="404"/>
     109      </Position8>
     110      <Position9>
     111        <Filename Value="UMainForm.pas"/>
     112        <Caret Line="428" Column="23" TopLine="413"/>
     113      </Position9>
     114      <Position10>
     115        <Filename Value="UMainForm.pas"/>
     116        <Caret Line="438" Column="23" TopLine="360"/>
     117      </Position10>
     118      <Position11>
     119        <Filename Value="UMainForm.pas"/>
     120        <Caret Line="564" Column="26" TopLine="549"/>
     121      </Position11>
     122      <Position12>
     123        <Filename Value="UMainForm.pas"/>
     124        <Caret Line="645" Column="49" TopLine="629"/>
     125      </Position12>
     126      <Position13>
     127        <Filename Value="UMainForm.pas"/>
     128        <Caret Line="656" Column="1" TopLine="628"/>
     129      </Position13>
     130      <Position14>
     131        <Filename Value="UMainForm.pas"/>
     132        <Caret Line="601" Column="29" TopLine="586"/>
     133      </Position14>
     134      <Position15>
     135        <Filename Value="UMainForm.pas"/>
     136        <Caret Line="620" Column="30" TopLine="605"/>
     137      </Position15>
     138      <Position16>
     139        <Filename Value="UMainForm.pas"/>
     140        <Caret Line="111" Column="1" TopLine="96"/>
     141      </Position16>
     142      <Position17>
     143        <Filename Value="UMainForm.pas"/>
     144        <Caret Line="368" Column="20" TopLine="353"/>
     145      </Position17>
     146      <Position18>
     147        <Filename Value="UMainForm.pas"/>
     148        <Caret Line="370" Column="3" TopLine="355"/>
     149      </Position18>
     150      <Position19>
     151        <Filename Value="UMainForm.pas"/>
     152        <Caret Line="372" Column="1" TopLine="357"/>
     153      </Position19>
     154      <Position20>
     155        <Filename Value="UMainForm.pas"/>
     156        <Caret Line="349" Column="1" TopLine="334"/>
     157      </Position20>
     158      <Position21>
     159        <Filename Value="UMainForm.pas"/>
     160        <Caret Line="372" Column="1" TopLine="358"/>
     161      </Position21>
     162      <Position22>
     163        <Filename Value="UProgram.pas"/>
     164        <Caret Line="11" Column="27" TopLine="1"/>
     165      </Position22>
     166      <Position23>
     167        <Filename Value="UProgram.pas"/>
     168        <Caret Line="12" Column="3" TopLine="2"/>
     169      </Position23>
     170      <Position24>
     171        <Filename Value="UProgram.pas"/>
     172        <Caret Line="8" Column="51" TopLine="1"/>
     173      </Position24>
     174      <Position25>
     175        <Filename Value="UProgram.pas"/>
     176        <Caret Line="314" Column="49" TopLine="290"/>
     177      </Position25>
     178      <Position26>
     179        <Filename Value="UProgram.pas"/>
     180        <Caret Line="102" Column="1" TopLine="89"/>
     181      </Position26>
     182      <Position27>
     183        <Filename Value="UProgram.pas"/>
     184        <Caret Line="98" Column="1" TopLine="86"/>
     185      </Position27>
     186      <Position28>
     187        <Filename Value="UProgram.pas"/>
     188        <Caret Line="31" Column="22" TopLine="16"/>
     189      </Position28>
     190      <Position29>
     191        <Filename Value="UProgram.pas"/>
     192        <Caret Line="93" Column="3" TopLine="78"/>
     193      </Position29>
     194      <Position30>
     195        <Filename Value="UMainForm.pas"/>
     196        <Caret Line="415" Column="43" TopLine="398"/>
     197      </Position30>
    104198    </JumpHistory>
    105199  </ProjectOptions>
     
    108202    <PathDelim Value="\"/>
    109203    <SearchPaths>
     204      <IncludeFiles Value="$(ProjOutDir)\"/>
    110205      <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
    111206    </SearchPaths>
     207    <CodeGeneration>
     208      <Checks>
     209        <IOChecks Value="True"/>
     210        <RangeChecks Value="True"/>
     211        <OverflowChecks Value="True"/>
     212        <StackChecks Value="True"/>
     213      </Checks>
     214    </CodeGeneration>
    112215    <Other>
    113216      <CompilerPath Value="$(CompPath)"/>
  • branches/Analyzátor gramatiky/PascalCompiler.lpr

    r28 r29  
    44
    55uses
    6   Forms, Interfaces,
     6  Forms, LResources, Interfaces,
    77  UMainForm in 'UMainForm.pas' {MainForm},
    88  UGrammer in 'UGrammer.pas',
    99  UProgram in 'UProgram.pas';
    1010
    11 {$R *.res}
     11{$IFDEF WINDOWS}{$R PascalCompiler.rc}{$ENDIF}
    1212
    1313begin
     14  {$I PascalCompiler.lrs}
    1415  Application.Initialize;
    1516  Application.CreateForm(TMainForm, MainForm);
  • 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);
  • branches/Analyzátor gramatiky/UMainForm.lrs

    r28 r29  
    1 { Toto je automaticky generovanÃœ zdrojovÃœ soubor lazarusu }
    2 
    31LazarusResources.Add('TMainForm','FORMDATA',[
    42  'TPF0'#9'TMainForm'#8'MainForm'#4'Left'#3#1#1#6'Height'#3#141#2#3'Top'#2#0#5
  • branches/Analyzátor gramatiky/UMainForm.pas

    r28 r29  
    66
    77uses
    8   LCLIntf, Messages, SysUtils, Classes, Graphics, Controls, Forms,
     8  LCLIntf, SysUtils, Classes, Graphics, Controls, Forms,
    99  Dialogs, StdCtrls, ComCtrls, LResources, UGrammer, UProgram;
    1010
    1111const
    12   DefaultGrammerFileName: string = 'grammer/test.grm';
    13   DefaultPascalFileName: string = 'pascal/test.pas';
     12  DefaultGrammerFileName: string = '../../grammer/test.grm';
     13  DefaultPascalFileName: string = '../../pascal/test.pas';
    1414
    1515type
     
    3232  private
    3333    procedure ShowProgramNode(Node: TTreeNode; SourceProgram: TProgramItem);
    34     { Private declarations }
    3534  public
    3635    Grammer: TGrammer;
     
    5049  MainForm: TMainForm;
    5150
     51
    5252implementation
    53 
    5453
    5554procedure TMainForm.Button1Click(Sender: TObject);
     
    8887begin
    8988  with SourceProgram.TopItem do begin
    90     MergeNonterminal(TGrammerRule(Grammer.Rules[7]));
    91     MergeNonterminal(TGrammerRule(Grammer.Rules[9]));
    92     DeleteNonterminal(TGrammerRule(Grammer.Rules[0]));
     89    MergeNonterminal(Grammer.Rules[7]);
     90    MergeNonterminal(Grammer.Rules[9]);
     91    DeleteNonterminal(Grammer.Rules[0]);
    9392    DeleteEmpty;
    94     Join(TGrammerRule(Grammer.Rules[17]), 1);
    95     Join(TGrammerRule(Grammer.Rules[15]), 0);
    96     Join(TGrammerRule(Grammer.Rules[14]), 0);
     93    Join(Grammer.Rules[17], 1);
     94    Join(Grammer.Rules[15], 0);
     95    Join(Grammer.Rules[14], 0);
    9796  end;
    9897  ShowProgramTree(SourceProgram);
     
    109108  C: Char;
    110109  I: Integer;
    111   SourceCode: string;
    112110begin
    113111  PascalGrammer := TGrammer.Create;
     
    118116    with WhiteSpace do begin
    119117      Name := 'WhiteSpace';
     118      Token := True;
    120119      RuleType := rtAlternative;
    121120      AddTerminal(' ', False, False);
     
    161160    with Number do begin
    162161      Name := 'Number';
     162      Token := True;
    163163      RuleType := rtSequence;
    164164      AddTerminal('-', True, False);
     
    180180    with Identifier do begin
    181181      Name := 'Identifier';
     182      Token := True;
    182183      RuleType := rtSequence;
    183184      AddRule(AlphabeticCharacter, False, False);
     
    198199    with RuleString do begin
    199200      Name := 'String';
     201      Token := True;
    200202      RuleType := rtSequence;
    201203      AddTerminal('''', False, False);
     
    344346  Memo1.Lines.LoadFromFile(DefaultGrammerFileName);
    345347  Memo2.Lines.LoadFromFile(DefaultPascalFileName);
    346   SourceCode := '';
    347348//  with Memo1.Lines do
    348349//  for I := 1 to Length(Text) do begin
     
    365366function TMainForm.ProcessConcatenationItem(ARule: TGrammerRule; ProgramItem: TProgramItem): TGrammerItem;
    366367var
    367   I: Integer;
    368368  II: Integer;
    369369  NewRule: TGrammerRule;
    370   NewSubRule: TGrammerRule;
    371370  RuleItem: TGrammerItem;
    372 type
    373   LowerChars = 'a'..'z';
    374371begin
    375372  with ProgramItem do begin
     
    392389            if Length(Value) > 3 then begin
    393390              NewRule := TGrammerRule.Create;
    394               NewRule.Ownership := ARule;
     391              NewRule.Parent := ARule;
    395392              NewRule.Name := 'Term';
    396393              NewRule.AddTerminalText(Copy(Value, 2, Length(Value) - 2));
     
    404401          end else begin
    405402            NewRule := TGrammerRule.Create;
    406             NewRule.Ownership := ARule;
     403            NewRule.PArent := ARule;
    407404            NewRule.Name := 'Term';
    408405            NewRule.AddTerminalText(Value);
     
    413410      end else if TProgramItem(Items[II]).Rule.Name = 'GroupingBlock' then begin
    414411        NewRule := TGrammerRule.Create;
    415         NewRule.Ownership := ARule;
     412        NewRule.Parent := ARule;
    416413        NewRule.RuleType := rtSequence;
    417414        NewRule.Name := 'Group';
    418         ProcessSeparationItem(NewRule, TProgramItem(Items[II]).Items[1]);
     415        ProcessSeparationItem(NewRule, Items[II].Items[1]);
    419416        PascalGrammer.Rules.Add(NewRule);
    420417        RuleItem.ItemType := itNonterminal;
     
    422419      end else if TProgramItem(Items[II]).Rule.Name = 'OptionBlock' then begin
    423420        NewRule := TGrammerRule.Create;
    424         NewRule.Ownership := ARule;
     421        NewRule.Parent := ARule;
    425422        NewRule.RuleType := rtSequence;
    426423        NewRule.Name := 'Option';
    427         ProcessSeparationItem(NewRule, TProgramItem(Items[II]).Items[1]);
     424        ProcessSeparationItem(NewRule, Items[II].Items[1]);
    428425        PascalGrammer.Rules.Add(NewRule);
    429426        RuleItem.ItemType := itNonterminal;
    430427        RuleItem.Optional := True;
    431428        RuleItem.Rule := NewRule;
    432       end else if TProgramItem(Items[II]).Rule.Name = 'RepetitionBlock' then begin
     429      end else if Items[II].Rule.Name = 'RepetitionBlock' then begin
    433430        NewRule := TGrammerRule.Create;
    434         NewRule.Ownership := ARule;
     431        NewRule.Parent := ARule;
    435432        NewRule.RuleType := rtSequence;
    436433        NewRule.Name := 'Repetition';
    437         ProcessSeparationItem(NewRule, TProgramItem(Items[II]).Items[1]);
     434        ProcessSeparationItem(NewRule, Items[II].Items[1]);
    438435        PascalGrammer.Rules.Add(NewRule);
    439436        RuleItem.Repetition := True;
     
    456453begin
    457454  for I := 0 to PascalGrammer.Rules.Count - 1 do
    458     TGrammerRule(PascalGrammer.Rules[I]).Free;
     455    PascalGrammer.Rules[I].Free;
    459456  PascalGrammer.Rules.Clear;
    460457  with PascalGrammer do begin
     
    533530  PascalGrammer.TopRule := nil;
    534531  with SourceProgram.TopItem do begin
    535     with TProgramItem(Items[0]) do begin
    536       for I := 0 to Items.Count - 1 do with TProgramItem(Items[I]) do begin
     532    with Items[0] do begin
     533      for I := 0 to Items.Count - 1 do with Items[I] do begin
    537534        NewRule := TGrammerRule.Create;
    538535        with PascalGrammer do
    539536          if TopRule = nil then TopRule := NewRule;
    540         NewRule.Name := TProgramItem(Items[0]).Value;
    541         ProcessSeparationItem(NewRule, TProgramItem(Items[2]));
     537        NewRule.Name := Items[0].Value;
     538        ProcessSeparationItem(NewRule, Items[2]);
    542539        PascalGrammer.Rules.Add(NewRule);
    543540      end;
     
    558555      for II := 0 to Items.Count - 1 do begin
    559556        NewSubRule := TGrammerRule.Create;
    560         NewSubRule.Ownership := ARule;
     557        NewSubRule.Parent := ARule;
    561558        NewSubRule.Name := ARule.Name;
    562559        RuleItem := ARule.Add;
    563560        RuleItem.ItemType := itNonterminal;
    564561        RuleItem.Rule := NewSubRule;
    565         ProcessConcatenationItem(NewSubRule, TProgramItem(Items[II]));
     562        ProcessConcatenationItem(NewSubRule, Items[II]);
    566563        PascalGrammer.Rules.Add(NewSubRule);
    567564      end;
    568565    end else begin
    569       ProcessConcatenationItem(ARule, TProgramItem(Items[0]));
     566      ProcessConcatenationItem(ARule, Items[0]);
    570567    end;
    571568end;
     
    585582      NewTreeNode := AddChild(TreeNode, ARule.Name + Attributs);
    586583      for II := 0 to Items.Count - 1 do
    587       with TGrammerItem(Items[II]) do begin
     584      with Items[II] do begin
    588585        if Optional then Attributs := '(Opt)' else Attributs := '';
    589586        if Repetition then Attributs := Attributs + '(Rep)';
     
    595592          itNonterminal: begin
    596593            if Assigned(Rule) then begin
    597               if Rule.Ownership = ARule then
     594              if Rule.Parent = ARule then
    598595                ShowGrammerRule(NewTreeNode, Rule, Attributs)
    599596                else AddChild(NewTreeNode, '<' + Rule.Name + '>' + Attributs);
     
    614611    TopItem := AddChild(nil, 'Gramatika');
    615612    for I := 0 to Rules.Count - 1 do with TGrammerRule(Rules[I]) do
    616       if Ownership = nil then ShowGrammerRule(TopItem, TGrammerRule(Rules[I]));
     613      if not Assigned(Parent) then ShowGrammerRule(TopItem, TGrammerRule(Rules[I]));
    617614    TopItem.Expand(False);
    618615    EndUpdate;
     
    651648initialization
    652649  {$i UMainForm.lrs}
    653   {$i UMainForm.lrs}
    654650
    655651end.
  • branches/Analyzátor gramatiky/UProgram.pas

    r28 r29  
    66
    77uses
    8   Classes, ComCtrls, SysUtils, Math, UGrammer;
     8  Classes, ComCtrls, SysUtils, Math, UGrammer, fgl;
    99
    1010type
     11  TProgramItem = class;
     12
     13  TProgramItemList = specialize TFPGObjectList<TProgramItem>;
     14
    1115  TProgramItem = class
    1216  public
    1317    RuleBefore: TGrammerRule;
    14     Items: TList; // of TProgramItem;
     18    Items: TProgramItemList;
    1519    ItemType: TRuleItemType;
    1620    Rule: TGrammerRule;
     
    8791  Path: TGrammerPath;
    8892  I, II: Integer;
    89   Q: Integer;
    9093  C: Integer;
    9194  Scope: TPossibleCharacters;
     
    9598  ExpectedCharacters: string;
    9699  Level: array of Integer;
    97   LevelLength: Integer;
    98   LevelIsLeft: Boolean;
    99   MaxLevel: Integer;
    100   Different: Boolean;
    101100begin
    102101  SetLength(Path.Items, Length(Path.Items) + 1);
     
    122121      // Possible character selection
    123122      SetLength(Level, 0);
    124       LevelLength := 0;
    125123      for II := 0 to High(Scope.Items) do with Scope.Items[II] do
    126124      begin
     
    202200  I: Integer;
    203201begin
    204   for I := 0 to Items.Count - 1 do with TProgramItem(Items[I]) do begin
     202  for I := 0 to Items.Count - 1 do with Items[I] do begin
    205203    if ItemType = itNonterminal then begin
    206204      if Rule.Name = ARule.Name then begin
     
    221219constructor TProgramItem.Create;
    222220begin
    223   Items := TList.Create;
     221  Items := TProgramItemList.Create;
    224222end;
    225223
     
    228226  I: Integer;
    229227begin
    230   for I := 0 to Items.Count - 1 do with TProgramItem(Items[I]) do begin
     228  for I := 0 to Items.Count - 1 do
     229  with TProgramItem(Items[I]) do begin
    231230    if ItemType = itNonterminal then Delete;
    232231  end;
     
    238237begin
    239238  I := 0;
    240   while I < Items.Count do with TProgramItem(Items[I]) do begin
     239  while I < Items.Count do
     240  with TProgramItem(Items[I]) do begin
    241241    if ItemType = itNonterminal then begin
    242242      if Items.Count = 0 then begin
     
    262262begin
    263263  I := 0;
    264   while I < Items.Count do with TProgramItem(Items[I]) do begin
     264  while I < Items.Count do
     265  with Items[I] do begin
    265266    if ItemType = itNonterminal then begin
    266267      if Rule.Name = ARule.Name then begin
     
    275276
    276277destructor TProgramItem.Destroy;
    277 var
    278   I: Integer;
    279 begin
    280   for I := 0 to Items.Count - 1 do TProgramItem(Items[I]).Free;
    281   Items.Free;
     278begin
     279  Items.Destroy;
    282280  inherited;
    283281end;
     
    289287begin
    290288  if (ItemType = itNonterminal) and (Rule = ARule) then begin
    291     SubProgramItem := TProgramItem(Items[ItemIndex]);
     289    SubProgramItem := Items[ItemIndex];
    292290    RuleBefore := SubProgramItem.RuleBefore;
    293291    Rule := SubProgramItem.Rule;
     
    296294    Items[ItemIndex] := nil;
    297295    for I := 0 to Items.Count - 1 do
    298       if Assigned(Items[I]) then TProgramItem(Items[I]).Free;
     296      if Assigned(Items[I]) then Items[I].Free;
    299297    Items := SubProgramItem.Items;
    300298  end;
    301299  for I := 0 to Items.Count - 1 do
    302     TProgramItem(Items[I]).Join(ARule, ItemIndex);
     300    Items[I].Join(ARule, ItemIndex);
    303301end;
    304302
     
    308306begin
    309307  Result := '';
    310   for I := 0 to Items.Count - 1 do with TProgramItem(Items[I]) do begin
     308  for I := 0 to Items.Count - 1 do with Items[I] do begin
    311309    if ItemType = itTerminal then Result := Result + Value
    312310      else Result := Result + MergeToTerminal;
Note: See TracChangeset for help on using the changeset viewer.