Changeset 9 for UMainForm.pas
- Timestamp:
- Oct 16, 2007, 9:16:28 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
UMainForm.pas
r8 r9 17 17 TreeView1: TTreeView; 18 18 TreeView2: TTreeView; 19 Label1: TLabel;20 19 Button2: TButton; 21 20 Memo2: TMemo; 22 21 Button3: TButton; 22 StatusBar1: TStatusBar; 23 Button4: TButton; 23 24 procedure FormCreate(Sender: TObject); 24 25 procedure FormDestroy(Sender: TObject); … … 26 27 procedure Button2Click(Sender: TObject); 27 28 procedure Button3Click(Sender: TObject); 29 procedure Button4Click(Sender: TObject); 28 30 private 29 31 procedure ShowProgramNode(Node: TTreeNode; SourceProgram: TProgramItem); … … 55 57 SourceProgram := TProgram.Create; 56 58 Grammer.Parse(Memo1.Text, SourceProgram); 57 with SourceProgram.TopItem do begin58 MergeNonterminal(TGrammerRule(Grammer.Rules[7]));59 MergeNonterminal(TGrammerRule(Grammer.Rules[9]));60 DeleteNonterminal(TGrammerRule(Grammer.Rules[0]));61 DeleteEmpty;62 Join(TGrammerRule(Grammer.Rules[17]), 1);63 Join(TGrammerRule(Grammer.Rules[15]), 0);64 Join(TGrammerRule(Grammer.Rules[14]), 0);65 end;66 59 ShowProgramTree(SourceProgram); 67 60 end; … … 91 84 end; 92 85 86 procedure TMainForm.Button4Click(Sender: TObject); 87 begin 88 with SourceProgram.TopItem do begin 89 MergeNonterminal(TGrammerRule(Grammer.Rules[7])); 90 MergeNonterminal(TGrammerRule(Grammer.Rules[9])); 91 DeleteNonterminal(TGrammerRule(Grammer.Rules[0])); 92 DeleteEmpty; 93 Join(TGrammerRule(Grammer.Rules[17]), 1); 94 Join(TGrammerRule(Grammer.Rules[15]), 0); 95 Join(TGrammerRule(Grammer.Rules[14]), 0); 96 end; 97 ShowProgramTree(SourceProgram); 98 end; 99 93 100 procedure TMainForm.FormCreate(Sender: TObject); 94 101 var … … 260 267 Name := 'ConcatenationBlock'; 261 268 RuleType := rtSequence; 262 AddRule(WhiteSpace, False, True);269 AddRule(WhiteSpace, True, True); 263 270 AddRule(Expression, True, False); 264 271 end; … … 269 276 RuleType := rtSequence; 270 277 AddRule(Expression, False, False); 278 AddRule(WhiteSpace, True, True); 271 279 AddRule(ConcatenationBlock, True, True); 272 280 end; … … 288 296 RuleType := rtSequence; 289 297 AddRule(Concatenation, False, False); 298 AddRule(WhiteSpace, True, True); 290 299 AddRule(SeparationBlock, True, True); 291 300 end; … … 374 383 RuleItem.RuleName := Value; 375 384 RuleItem.Rule := nil; 385 end else if Value = 'NAME' then begin 386 RuleItem.Rule := TGrammerRule(PascalGrammer.Rules[7]); 387 end else if Value = 'NUMBER' then begin 388 RuleItem.Rule := TGrammerRule(PascalGrammer.Rules[5]); 389 end else if (Length(Value) > 1) and (Value[1] = '''') and 390 (Value[Length(Value)] = '''') then begin 391 if Length(Value) > 3 then begin 392 NewRule := TGrammerRule.Create; 393 NewRule.Ownership := ARule; 394 NewRule.Name := 'Term'; 395 NewRule.AddTerminalText(Copy(Value, 2, Length(Value) - 2)); 396 PascalGrammer.Rules.Add(NewRule); 397 RuleItem.Rule := NewRule; 398 RuleItem.ItemType := itNonterminal; 399 end else if Length(Value) = 3 then begin 400 RuleItem.ItemType := itTerminal; 401 RuleItem.Character := Value[2] 402 end; 376 403 end else begin 377 404 NewRule := TGrammerRule.Create; … … 422 449 I: Integer; 423 450 NewRule: TGrammerRule; 451 WhiteSpace, LowerCaseAlphabeticCharacter, UpperCaseAlphabeticCharacter, 452 AlphabeticCharacter, Digit, Number, AlphaNumericCharacter, 453 Identifier: TGrammerRule; 454 C: Char; 424 455 begin 425 456 for I := 0 to PascalGrammer.Rules.Count - 1 do 426 457 TGrammerRule(PascalGrammer.Rules[I]).Free; 427 458 PascalGrammer.Rules.Clear; 459 with PascalGrammer do begin 460 WhiteSpace := TGrammerRule.Create; 461 with WhiteSpace do begin 462 Name := 'WhiteSpace'; 463 RuleType := rtAlternative; 464 AddTerminal(' ', False, False); 465 AddTerminal(#10, False, False); 466 AddTerminal(#13, False, False); 467 end; 468 Rules.Add(WhiteSpace); 469 470 LowerCaseAlphabeticCharacter := TGrammerRule.Create; 471 with LowerCaseAlphabeticCharacter do begin 472 Name := 'LowerCaseAlphabeticCharacter'; 473 RuleType := rtAlternative; 474 for C := 'a' to 'z' do AddTerminal(C, False, False); 475 end; 476 Rules.Add(LowerCaseAlphabeticCharacter); 477 478 UpperCaseAlphabeticCharacter := TGrammerRule.Create; 479 with UpperCaseAlphabeticCharacter do begin 480 Name := 'UpperCaseAlphabeticCharacter'; 481 RuleType := rtAlternative; 482 for C := 'A' to 'Z' do AddTerminal(C, False, False); 483 end; 484 Rules.Add(UpperCaseAlphabeticCharacter); 485 486 AlphabeticCharacter := TGrammerRule.Create; 487 with AlphabeticCharacter do begin 488 Name := 'AlphabeticCharacter'; 489 RuleType := rtAlternative; 490 AddRule(LowerCaseAlphabeticCharacter, False, False); 491 AddRule(UpperCaseAlphabeticCharacter, False, False); 492 end; 493 Rules.Add(AlphabeticCharacter); 494 495 Digit := TGrammerRule.Create; 496 with Digit do begin 497 Name := 'Digit'; 498 RuleType := rtAlternative; 499 for C := '0' to '9' do AddTerminal(C, False, False); 500 end; 501 Rules.Add(Digit); 502 503 Number := TGrammerRule.Create; 504 with Number do begin 505 Name := 'Number'; 506 RuleType := rtSequence; 507 AddTerminal('-', True, False); 508 AddRule(Digit, False, True); 509 end; 510 Rules.Add(Number); 511 512 AlphaNumericCharacter := TGrammerRule.Create; 513 with AlphaNumericCharacter do begin 514 Name := 'AlphaNumericCharacter'; 515 RuleType := rtAlternative; 516 AddRule(Digit, False, False); 517 AddRule(AlphabeticCharacter, False, False); 518 AddTerminal('_', False, False); 519 end; 520 Rules.Add(AlphaNumericCharacter); 521 522 Identifier := TGrammerRule.Create; 523 with Identifier do begin 524 Name := 'Identifier'; 525 RuleType := rtSequence; 526 AddRule(AlphabeticCharacter, False, False); 527 AddRule(AlphaNumericCharacter, True, True); 528 end; 529 Rules.Add(Identifier); 530 end; 531 428 532 PascalGrammer.TopRule := nil; 429 533 with SourceProgram.TopItem do begin
Note:
See TracChangeset
for help on using the changeset viewer.