Changeset 8 for UMainForm.pas


Ignore:
Timestamp:
Oct 15, 2007, 8:28:00 AM (17 years ago)
Author:
george
Message:

Opraveno: Vytváření nové gramatiky z jiné. Zobrazení výsledku a další fáze parsování pascalu.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • UMainForm.pas

    r7 r8  
    99const
    1010  DefaultGrammerFileName: string = 'grammer/test.grm';
     11  DefaultPascalFileName: string = 'pascal/test.pas';
    1112
    1213type
     
    1819    Label1: TLabel;
    1920    Button2: TButton;
     21    Memo2: TMemo;
     22    Button3: TButton;
    2023    procedure FormCreate(Sender: TObject);
    2124    procedure FormDestroy(Sender: TObject);
    2225    procedure Button1Click(Sender: TObject);
    2326    procedure Button2Click(Sender: TObject);
     27    procedure Button3Click(Sender: TObject);
    2428  private
    2529    procedure ShowProgramNode(Node: TTreeNode; SourceProgram: TProgramItem);
     
    2933    PascalGrammer: TGrammer;
    3034    SourceProgram: TProgram;
     35    PascalProgram: TProgram;
    3136    procedure ShowProgramTree(SourceProgram: TProgram);
    3237    procedure ShowGrammerTree(Grammer: TGrammer);
     
    6974end;
    7075
     76procedure TMainForm.Button3Click(Sender: TObject);
     77begin
     78  PascalProgram.Free;
     79  PascalProgram := TProgram.Create;
     80  PascalGrammer.Parse(Memo2.Text, PascalProgram);
     81  with PascalProgram.TopItem, PascalGrammer do begin
     82//    MergeNonterminal(TGrammerRule(Rules[7]));
     83//    MergeNonterminal(TGrammerRule(Rules[9]));
     84//    DeleteNonterminal(TGrammerRule(Rules[0]));
     85//    DeleteEmpty;
     86//    Join(TGrammerRule(Rules[17]), 1);
     87//    Join(TGrammerRule(Rules[15]), 0);
     88//    Join(TGrammerRule(Rules[14]), 0);
     89  end;
     90  ShowProgramTree(PascalProgram);
     91end;
     92
    7193procedure TMainForm.FormCreate(Sender: TObject);
    7294var
     
    311333  SourceProgram := TProgram.Create;
    312334  Memo1.Lines.LoadFromFile(DefaultGrammerFileName);
     335  Memo2.Lines.LoadFromFile(DefaultPascalFileName);
    313336  SourceCode := '';
    314337//  with Memo1.Lines do
     
    317340//  end;
    318341
    319   Grammer.Parse(Memo1.Text, SourceProgram);
    320   ShowProgramTree(SourceProgram);
     342  //Grammer.Parse(Memo1.Text, SourceProgram);
     343  //ShowProgramTree(SourceProgram);
    321344end;
    322345
     
    324347begin
    325348  Memo1.Lines.SaveToFile(DefaultGrammerFileName);
     349  Memo2.Lines.SaveToFile(DefaultPascalFileName);
    326350  PascalGrammer.Free;
    327351  Grammer.Free;
     
    386410        PascalGrammer.Rules.Add(NewRule);
    387411        RuleItem.Repetition := True;
     412        RuleItem.Optional := True;
    388413        RuleItem.ItemType := itNonterminal;
    389414        RuleItem.Rule := NewRule;
     
    454479      end;
    455480      NewTreeNode := AddChild(TreeNode, ARule.Name + Attributs);
    456       for II := 0 to Length(Items) - 1 do
    457       with Items[II] do begin
     481      for II := 0 to Items.Count - 1 do
     482      with TGrammerItem(Items[II]) do begin
    458483        if Optional then Attributs := '(Opt)' else Attributs := '';
    459484        if Repetition then Attributs := Attributs + '(Rep)';
Note: See TracChangeset for help on using the changeset viewer.