Changeset 9 for UGrammer.pas


Ignore:
Timestamp:
Oct 16, 2007, 9:16:28 AM (17 years ago)
Author:
george
Message:

Úpravy parsování a sestavování gramatity pro pasacal.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • UGrammer.pas

    r8 r9  
    295295  Path: TGrammerPath;
    296296  I, II: Integer;
     297  Q: Integer;
    297298  C: Integer;
    298299  Scope: TPossibleCharacters;
     
    301302  UseRule: TGrammerRule;
    302303  ExpectedCharacters: string;
    303   Level: Integer;
     304  Level: array of Integer;
     305  LevelLength: Integer;
     306  LevelIsLeft: Boolean;
    304307begin
    305308  SetLength(Path.Items, Length(Path.Items) + 1);
     
    320323      UseRule.GetPossibleCharacters(Path, Scope, UseIndex, UseCharIndex);
    321324      C := Length(Scope.Items);
    322       Level := 0; //High(Integer);
    323       for II := High(Scope.Items) downto 0 do begin
    324         if (Scope.Items[II].Character = Text[I]) and (Level < Length(Scope.Items[II].RulePath.Items))
    325         then begin
    326           C := II;
    327           Level := Length(Scope.Items[II].RulePath.Items);
    328         end;
    329       end;
     325
     326      SetLength(Level, 0);
     327      for II := 0 to High(Scope.Items) do with Scope.Items[II] do begin
     328        if (Character = Text[I]) then begin
     329          if Length(RulePath.Items) > Length(Level) then begin
     330            LevelLength := Length(Level);
     331            SetLength(Level, Length(RulePath.Items));
     332            for Q := LevelLength to High(Level) do
     333              Level[Q] := High(Integer);
     334          end;
     335          LevelIsLeft := True;
     336          for Q := 0 to High(Level) do begin
     337            if Level[Q] > RulePath.Items[Q].ItemIndex then begin
     338              LevelIsLeft := False;
     339              Break;
     340            end;
     341            if Level[Q] < RulePath.Items[Q].ItemIndex then Break;
     342          end;
     343          if (not LevelIsLeft) or (Length(RulePath.Items) > Length(Level)) then begin
     344            SetLength(Level, Length(RulePath.Items));
     345            for Q := 0 to High(Level) do
     346              Level[Q] := RulePath.Items[Q].ItemIndex;
     347            C := II;
     348          end;
     349        end;
     350      end;
     351
    330352      if C < Length(Scope.Items) then begin
    331353        Path.Assign(Scope.Items[C].RulePath);
     
    343365          ExpectedCharacters := ExpectedCharacters + Scope.Items[II].Character;
    344366        //raise Exception.Create('Parse error. Expected "' + ExpectedCharacters + '" but found "' + Text[I] + '".');
    345         MainForm.Label1.Caption := 'Parse error. Expected "' + ExpectedCharacters + '" but found "' + Text[I] + '".';
     367        MainForm.StatusBar1.SimpleText := 'Parse error. Expected "' + ExpectedCharacters + '" but found "' + Text[I] + '".';
    346368        break;
    347369      end;
Note: See TracChangeset for help on using the changeset viewer.