Changeset 5


Ignore:
Timestamp:
Oct 4, 2007, 3:53:57 PM (17 years ago)
Author:
george
Message:

Doladění gramatiky pro načítání EBNF.

Files:
6 added
3 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • UMainForm.pas

    r3 r5  
    66  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    77  Dialogs, StdCtrls, ComCtrls;
     8
     9const
     10  DefaultGrammerFileName: string = 'grammer/test.grm';
    811
    912type
     
    203206      AddRule(Digit, False, False);
    204207      AddRule(AlphabeticCharacter, False, False);
     208      AddTerminal('_', False, False);
    205209    end;
    206210    Rules.Add(AlphaNumericCharacter);
     
    235239
    236240    Concatenation := TGrammerRule.Create;
     241    Separation := TGrammerRule.Create;
    237242
    238243    OptionBlock := TGrammerRule.Create;
     
    242247      AddTerminal('[', False, False);
    243248      AddRule(WhiteSpace, True, True);
    244       AddRule(Concatenation, False, False);
     249      AddRule(Separation, False, False);
    245250      AddRule(WhiteSpace, True, True);
    246251      AddTerminal(']', False, False);
     
    254259      AddTerminal('{', False, False);
    255260      AddRule(WhiteSpace, True, True);
    256       AddRule(Concatenation, False, False);
     261      AddRule(Separation, False, False);
    257262      AddRule(WhiteSpace, True, True);
    258263      AddTerminal('}', False, False);
     
    266271      AddTerminal('(', False, False);
    267272      AddRule(WhiteSpace, True, True);
    268       AddRule(Concatenation, False, False);
     273      AddRule(Separation, False, False);
    269274      AddRule(WhiteSpace, True, True);
    270275      AddTerminal(')', False, False);
     
    297302      RuleType := rtSequence;
    298303      AddRule(WhiteSpace, False, True);
    299       AddRule(Expression, False, False);
     304      AddRule(Expression, True, False);
    300305    end;
    301306    Rules.Add(ConcatenationBlock);
     
    320325    Rules.Add(SeparationBlock);
    321326
    322     Separation := TGrammerRule.Create;
    323327    with Separation do begin
    324328      Name := 'Separation';
     
    359363
    360364  SourceProgram := TProgram.Create;
    361   Memo1.Lines.LoadFromFile('P0.grm');
     365  Memo1.Lines.LoadFromFile(DefaultGrammerFileName);
    362366  SourceCode := '';;
    363367//  with Memo1.Lines do
     
    483487procedure TMainForm.FormDestroy(Sender: TObject);
    484488begin
    485   Memo1.Lines.SaveToFile('Program.pas');
     489  Memo1.Lines.SaveToFile(DefaultGrammerFileName);
    486490
    487491  Grammer.Free;
     
    588592  UseRule: TGrammerRule;
    589593  ExpectedCharacters: string;
     594  Level: Integer;
    590595begin
    591596  SetLength(Path.Items, Length(Path.Items) + 1);
     
    605610      ClearProcessed;
    606611      UseRule.GetPossibleCharacters(Path, Scope, UseIndex, UseCharIndex);
    607       C := 0;
    608       while (C < Length(Scope.Items)) and
    609         (Scope.Items[C].Character <> Text[I]) do Inc(C);
     612      C := Length(Scope.Items);
     613      Level := 0; //High(Integer);
     614      for II := High(Scope.Items) downto 0 do begin
     615        if (Scope.Items[II].Character = Text[I]) and (Level < Length(Scope.Items[II].RulePath.Items))
     616        then begin
     617          C := II;
     618          Level := Length(Scope.Items[II].RulePath.Items);
     619        end;
     620      end;
    610621      if C < Length(Scope.Items) then begin
    611622        Path.Assign(Scope.Items[C].RulePath);
Note: See TracChangeset for help on using the changeset viewer.