Ignore:
Timestamp:
Nov 11, 2009, 12:56:32 PM (15 years ago)
Author:
george
Message:
  • Opraveno: Inicializace a uvolnění třídy, které byly přepsány ze struktury record.
Location:
branches/Analyzátor gramatiky
Files:
3 edited

Legend:

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

    r29 r30  
    99      <Icon Value="0"/>
    1010      <UseXPManifest Value="True"/>
    11       <ActiveEditorIndexAtStart Value="2"/>
     11      <ActiveEditorIndexAtStart Value="0"/>
    1212    </General>
    1313    <VersionInfo>
     
    3131      </Item1>
    3232    </RequiredPackages>
    33     <Units Count="4">
     33    <Units Count="6">
    3434      <Unit0>
    3535        <Filename Value="PascalCompiler.lpr"/>
    3636        <IsPartOfProject Value="True"/>
    37         <CursorPos X="1" Y="13"/>
     37        <CursorPos X="11" Y="12"/>
    3838        <TopLine Value="1"/>
    3939        <EditorIndex Value="1"/>
    40         <UsageCount Value="21"/>
     40        <UsageCount Value="25"/>
    4141        <Loaded Value="True"/>
    4242      </Unit0>
     
    4848        <ResourceBaseClass Value="Form"/>
    4949        <UnitName Value="UMainForm"/>
    50         <CursorPos X="33" Y="582"/>
    51         <TopLine Value="572"/>
     50        <CursorPos X="23" Y="58"/>
     51        <TopLine Value="54"/>
    5252        <EditorIndex Value="2"/>
    53         <UsageCount Value="21"/>
     53        <UsageCount Value="25"/>
    5454        <Loaded Value="True"/>
    5555      </Unit1>
     
    5858        <IsPartOfProject Value="True"/>
    5959        <UnitName Value="UGrammer"/>
    60         <CursorPos X="62" Y="57"/>
    61         <TopLine Value="37"/>
     60        <CursorPos X="1" Y="322"/>
     61        <TopLine Value="307"/>
    6262        <EditorIndex Value="0"/>
    63         <UsageCount Value="21"/>
     63        <UsageCount Value="25"/>
    6464        <Loaded Value="True"/>
    6565      </Unit2>
     
    6868        <IsPartOfProject Value="True"/>
    6969        <UnitName Value="UProgram"/>
    70         <CursorPos X="5" Y="18"/>
    71         <TopLine Value="3"/>
     70        <CursorPos X="1" Y="101"/>
     71        <TopLine Value="86"/>
    7272        <EditorIndex Value="3"/>
    73         <UsageCount Value="21"/>
     73        <UsageCount Value="25"/>
    7474        <Loaded Value="True"/>
    7575      </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>
    7689    </Units>
    7790    <JumpHistory Count="30" HistoryIndex="29">
    7891      <Position1>
    79         <Filename Value="UMainForm.pas"/>
    80         <Caret Line="344" Column="1" TopLine="329"/>
     92        <Filename Value="UProgram.pas"/>
     93        <Caret Line="105" Column="1" TopLine="90"/>
    8194      </Position1>
    8295      <Position2>
    83         <Filename Value="UMainForm.pas"/>
    84         <Caret Line="21" Column="50" TopLine="1"/>
     96        <Filename Value="UProgram.pas"/>
     97        <Caret Line="106" Column="1" TopLine="91"/>
    8598      </Position2>
    8699      <Position3>
    87         <Filename Value="UMainForm.pas"/>
    88         <Caret Line="11" Column="52" TopLine="1"/>
     100        <Filename Value="UProgram.pas"/>
     101        <Caret Line="107" Column="1" TopLine="92"/>
    89102      </Position3>
    90103      <Position4>
    91         <Filename Value="UGrammer.pas"/>
    92         <Caret Line="63" Column="1" TopLine="60"/>
     104        <Filename Value="UProgram.pas"/>
     105        <Caret Line="108" Column="1" TopLine="93"/>
    93106      </Position4>
    94107      <Position5>
    95         <Filename Value="UMainForm.pas"/>
    96         <Caret Line="195" Column="31" TopLine="48"/>
     108        <Filename Value="UProgram.pas"/>
     109        <Caret Line="111" Column="1" TopLine="96"/>
    97110      </Position5>
    98111      <Position6>
    99         <Filename Value="UMainForm.pas"/>
    100         <Caret Line="398" Column="29" TopLine="383"/>
     112        <Filename Value="UProgram.pas"/>
     113        <Caret Line="113" Column="1" TopLine="98"/>
    101114      </Position6>
    102115      <Position7>
    103         <Filename Value="UMainForm.pas"/>
    104         <Caret Line="410" Column="27" TopLine="395"/>
     116        <Filename Value="UProgram.pas"/>
     117        <Caret Line="115" Column="1" TopLine="100"/>
    105118      </Position7>
    106119      <Position8>
    107         <Filename Value="UMainForm.pas"/>
    108         <Caret Line="419" Column="23" TopLine="404"/>
     120        <Filename Value="UProgram.pas"/>
     121        <Caret Line="116" Column="1" TopLine="101"/>
    109122      </Position8>
    110123      <Position9>
    111         <Filename Value="UMainForm.pas"/>
    112         <Caret Line="428" Column="23" TopLine="413"/>
     124        <Filename Value="UProgram.pas"/>
     125        <Caret Line="117" Column="1" TopLine="102"/>
    113126      </Position9>
    114127      <Position10>
    115         <Filename Value="UMainForm.pas"/>
    116         <Caret Line="438" Column="23" TopLine="360"/>
     128        <Filename Value="UGrammer.pas"/>
     129        <Caret Line="322" Column="1" TopLine="307"/>
    117130      </Position10>
    118131      <Position11>
    119         <Filename Value="UMainForm.pas"/>
    120         <Caret Line="564" Column="26" TopLine="549"/>
     132        <Filename Value="UGrammer.pas"/>
     133        <Caret Line="323" Column="22" TopLine="309"/>
    121134      </Position11>
    122135      <Position12>
    123         <Filename Value="UMainForm.pas"/>
    124         <Caret Line="645" Column="49" TopLine="629"/>
     136        <Filename Value="UGrammer.pas"/>
     137        <Caret Line="324" Column="6" TopLine="311"/>
    125138      </Position12>
    126139      <Position13>
    127         <Filename Value="UMainForm.pas"/>
    128         <Caret Line="656" Column="1" TopLine="628"/>
     140        <Filename Value="UGrammer.pas"/>
     141        <Caret Line="25" Column="12" TopLine="10"/>
    129142      </Position13>
    130143      <Position14>
    131         <Filename Value="UMainForm.pas"/>
    132         <Caret Line="601" Column="29" TopLine="586"/>
     144        <Filename Value="UGrammer.pas"/>
     145        <Caret Line="328" Column="32" TopLine="311"/>
    133146      </Position14>
    134147      <Position15>
    135         <Filename Value="UMainForm.pas"/>
    136         <Caret Line="620" Column="30" TopLine="605"/>
     148        <Filename Value="UProgram.pas"/>
     149        <Caret Line="101" Column="1" TopLine="86"/>
    137150      </Position15>
    138151      <Position16>
    139         <Filename Value="UMainForm.pas"/>
    140         <Caret Line="111" Column="1" TopLine="96"/>
     152        <Filename Value="UGrammer.pas"/>
     153        <Caret Line="322" Column="1" TopLine="307"/>
    141154      </Position16>
    142155      <Position17>
    143         <Filename Value="UMainForm.pas"/>
    144         <Caret Line="368" Column="20" TopLine="353"/>
     156        <Filename Value="UGrammer.pas"/>
     157        <Caret Line="324" Column="1" TopLine="309"/>
    145158      </Position17>
    146159      <Position18>
    147         <Filename Value="UMainForm.pas"/>
    148         <Caret Line="370" Column="3" TopLine="355"/>
     160        <Filename Value="UGrammer.pas"/>
     161        <Caret Line="325" Column="1" TopLine="310"/>
    149162      </Position18>
    150163      <Position19>
    151         <Filename Value="UMainForm.pas"/>
    152         <Caret Line="372" Column="1" TopLine="357"/>
     164        <Filename Value="UGrammer.pas"/>
     165        <Caret Line="326" Column="1" TopLine="311"/>
    153166      </Position19>
    154167      <Position20>
    155         <Filename Value="UMainForm.pas"/>
    156         <Caret Line="349" Column="1" TopLine="334"/>
     168        <Filename Value="UGrammer.pas"/>
     169        <Caret Line="327" Column="1" TopLine="312"/>
    157170      </Position20>
    158171      <Position21>
    159         <Filename Value="UMainForm.pas"/>
    160         <Caret Line="372" Column="1" TopLine="358"/>
     172        <Filename Value="UGrammer.pas"/>
     173        <Caret Line="329" Column="1" TopLine="314"/>
    161174      </Position21>
    162175      <Position22>
    163         <Filename Value="UProgram.pas"/>
    164         <Caret Line="11" Column="27" TopLine="1"/>
     176        <Filename Value="UGrammer.pas"/>
     177        <Caret Line="203" Column="1" TopLine="188"/>
    165178      </Position22>
    166179      <Position23>
    167         <Filename Value="UProgram.pas"/>
    168         <Caret Line="12" Column="3" TopLine="2"/>
     180        <Filename Value="UGrammer.pas"/>
     181        <Caret Line="214" Column="1" TopLine="199"/>
    169182      </Position23>
    170183      <Position24>
    171         <Filename Value="UProgram.pas"/>
    172         <Caret Line="8" Column="51" TopLine="1"/>
     184        <Filename Value="UGrammer.pas"/>
     185        <Caret Line="215" Column="1" TopLine="200"/>
    173186      </Position24>
    174187      <Position25>
    175         <Filename Value="UProgram.pas"/>
    176         <Caret Line="314" Column="49" TopLine="290"/>
     188        <Filename Value="UGrammer.pas"/>
     189        <Caret Line="322" Column="1" TopLine="307"/>
    177190      </Position25>
    178191      <Position26>
    179         <Filename Value="UProgram.pas"/>
    180         <Caret Line="102" Column="1" TopLine="89"/>
     192        <Filename Value="UGrammer.pas"/>
     193        <Caret Line="324" Column="1" TopLine="309"/>
    181194      </Position26>
    182195      <Position27>
    183         <Filename Value="UProgram.pas"/>
    184         <Caret Line="98" Column="1" TopLine="86"/>
     196        <Filename Value="UGrammer.pas"/>
     197        <Caret Line="325" Column="1" TopLine="310"/>
    185198      </Position27>
    186199      <Position28>
    187         <Filename Value="UProgram.pas"/>
    188         <Caret Line="31" Column="22" TopLine="16"/>
     200        <Filename Value="UGrammer.pas"/>
     201        <Caret Line="326" Column="1" TopLine="311"/>
    189202      </Position28>
    190203      <Position29>
    191         <Filename Value="UProgram.pas"/>
    192         <Caret Line="93" Column="3" TopLine="78"/>
     204        <Filename Value="UGrammer.pas"/>
     205        <Caret Line="327" Column="1" TopLine="312"/>
    193206      </Position29>
    194207      <Position30>
    195         <Filename Value="UMainForm.pas"/>
    196         <Caret Line="415" Column="43" TopLine="398"/>
     208        <Filename Value="UGrammer.pas"/>
     209        <Caret Line="326" Column="1" TopLine="311"/>
    197210      </Position30>
    198211    </JumpHistory>
     
    218231  </CompilerOptions>
    219232  <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>
    220243    <Exceptions Count="3">
    221244      <Item1>
  • branches/Analyzátor gramatiky/UGrammer.pas

    r29 r30  
    2020  end;
    2121
     22  TPathItemList = specialize TFPGObjectList<TPathItem>;
     23
    2224  TGrammerPath = class
    23     Items: array of TPathItem;
     25    Items: TPathItemList;
    2426    procedure Assign(Source: TGrammerPath);
    2527    procedure Next;
     28    constructor Create;
     29    destructor Destroy; override;
    2630  end;
    2731
     
    3236  end;
    3337
     38  TPossibleCharacterList = specialize TFPGObjectList<TPossibleCharacter>;
     39
     40  { TPossibleCharacters }
     41
    3442  TPossibleCharacters = class
    35     Items: array of TPossibleCharacter;
     43    Items: TPossibleCharacterList;
    3644    procedure Assign(Source: TPossibleCharacters);
     45    constructor Create;
     46    destructor Destroy; override;
    3747  end;
    3848
     
    135145  I: Integer;
    136146begin
    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
    138149    Processed := False;
    139150  end;
     
    160171  TempPath: TGrammerPath;
    161172begin
    162   SetLength(Path.Items, Length(Path.Items) + 1);
    163   with Path.Items[High(Path.Items)] do begin
     173  TempPath := TGrammerPath.Create;
     174  with Path.Items[Path.Items.Add(TPathItem.Create)] do begin
    164175    Rule := Self;
    165176    ItemIndex := UseIndex;
     
    172183      if UseIndex > 0 then begin
    173184        // 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
    176186          NextItemIndex := ItemIndex;
    177187          NextCharIndex := CharIndex;
    178188          NextRule := Rule;
    179189        end;
    180         SetLength(Path.Items, Length(Path.Items) - 1);
     190        Path.Items.Delete(Path.Items.Count - 1);
    181191        NextRule.GetPossibleCharacters(Path, Characters, NextItemIndex + 1, NextCharIndex);
    182192      end else begin
    183193        // Generate alternatives
    184194        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;
    186196          //Inc(Path.Items[High(Path.Items)].CharIndex);
    187197          Items[I].GetPossibleCharacters(Path, Characters);
     
    193203      if UseIndex >= Items.Count then begin
    194204        // Forward generation to upper item
    195         SetLength(Path.Items, Length(Path.Items) - 1);
    196         with Path.Items[High(Path.Items)] do begin
     205        Path.Items.Delete(Path.Items.Count - 1);
     206        with Path.Items[Path.Items.Count - 1] do begin
    197207          NextItemIndex := ItemIndex;
    198208          NextCharIndex := CharIndex;
    199209          NextRule := Rule;
    200210        end;
    201         SetLength(Path.Items, Length(Path.Items) - 1);
     211        Path.Items.Delete(Path.Items.Count - 1);
    202212        NextRule.GetPossibleCharacters(Path, Characters, NextItemIndex + 1, NextCharIndex);
    203213      end else begin
    204         Path.Items[High(Path.Items)].ItemIndex := UseIndex;
     214        Path.Items[Path.Items.Count - 1].ItemIndex := UseIndex;
    205215        Items[UseIndex].GetPossibleCharacters(Path, Characters);
    206216      end;
     
    208218      if (UseIndex > 0) and not Items[UseIndex - 1].Processed then
    209219        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;
    211221          Items[UseIndex - 1].GetPossibleCharacters(TempPath, Characters);
    212222        end;
    213223    end;
    214224  end;
     225  TempPath.Destroy;
    215226end;
    216227
     
    225236  I: Integer;
    226237begin
    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
    228240    ClearProcessed;
    229241  end;
     
    278290  case ItemType of
    279291    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 begin
    284         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);
    285297      end;
    286298    end;
     
    292304        // Forward generation to upper item
    293305        //SetLength(Path.Items, Length(Path.Items) - 1);
    294         with Path.Items[High(Path.Items)] do begin
     306        with Path.Items[Path.Items.Count - 1] do begin
    295307          NextItemIndex := ItemIndex;
    296308          NextCharIndex := CharIndex;
    297309          NextRule := Rule;
    298310        end;
    299         SetLength(Path.Items, Length(Path.Items) - 1);
     311        Path.Items.Count := Path.Items.Count - 1;
    300312        NextRule.GetPossibleCharacters(Path, Characters, NextItemIndex + 1, NextCharIndex);
    301313  end;
     
    308320  I: Integer;
    309321begin
    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;
    312329end;
    313330
     
    318335begin
    319336  Success := False;
    320   Index := High(Items);
     337  Index := Items.Count - 1;
    321338  while not Success and (Index >= 0) do begin
    322339    with Items[Index] do if Rule.Items[ItemIndex].Repetition then begin
     
    331348    end;
    332349  end;
    333   SetLength(Items, Index + 1);
     350  Items.Count := Index + 1;
     351end;
     352
     353constructor TGrammerPath.Create;
     354begin
     355  Items := TPathItemList.Create;
     356end;
     357
     358destructor TGrammerPath.Destroy;
     359begin
     360  Items.Destroy;
     361  inherited Destroy;
    334362end;
    335363
     
    358386  I: Integer;
    359387begin
    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]);
     391end;
     392
     393constructor TPossibleCharacters.Create;
     394begin
     395  Items := TPossibleCharacterList.Create;
     396end;
     397
     398destructor TPossibleCharacters.Destroy;
     399begin
     400  Items.Destroy;
     401  inherited Destroy;
    362402end;
    363403
  • branches/Analyzátor gramatiky/UProgram.pas

    r29 r30  
    66
    77uses
    8   Classes, ComCtrls, SysUtils, Math, UGrammer, fgl;
     8  Classes, ComCtrls, SysUtils, UGrammer, fgl;
    99
    1010type
     
    6262begin
    6363  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
    6566    SelectedProgramItem.ItemType := itNonterminal;
    6667    if not Assigned(SelectedProgramItem.Rule) then SelectedProgramItem.Rule := Rule;
     
    99100  Level: array of Integer;
    100101begin
    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
    103106    Rule := Grammer.TopRule;
    104107    ItemIndex := 0;
     
    110113    if (Text[I] <> #13) and (Text[I] <> #10) then
    111114    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       SetLength(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;
    117120      Grammer.ClearProcessed;
    118121      UseRule.GetPossibleCharacters(Path, Scope, UseIndex, UseCharIndex);
    119       C := Length(Scope.Items);
     122      C := Scope.Items.Count;
    120123
    121124      // Possible character selection
    122125      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
    124128      begin
    125129        if (Character = Text[I]) then
     
    174178      end;
    175179
    176       if C < Length(Scope.Items) then begin
     180      if C < Scope.Items.Count then begin
    177181        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
    179184          if Affected then Inc(CharIndex);
    180185        end;
    181186        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
    183189          Affected := False;
    184190        end;
     
    186192      end else begin
    187193        ExpectedCharacters := '';
    188         for II := 0 to Length(Scope.Items) - 1 do
     194        for II := 0 to Scope.Items.Count - 1 do
    189195          ExpectedCharacters := ExpectedCharacters + Scope.Items[II].Character;
    190196        //raise Exception.Create('Parse error. Expected "' + ExpectedCharacters + '" but found "' + Text[I] + '".');
     
    194200    end;
    195201  end;
     202  Path.Destroy;
     203  Scope.Destroy;
    196204end;
    197205
Note: See TracChangeset for help on using the changeset viewer.