Changeset 42 for branches/DelphiToC/Analyze/UPascalParser.pas
- Timestamp:
- Aug 5, 2010, 3:13:03 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DelphiToC/Analyze/UPascalParser.pas
r41 r42 104 104 resourcestring 105 105 SUnknownIdentifier = 'Unknown identificator "%s".'; 106 SIllegalExpression = 'Illegal expression "%s".'; 106 107 SExpectedButFound = 'Expected "%s" but "%s" found.'; 107 108 SRedefineIdentifier = 'Identificator "%s" redefinition.'; … … 430 431 if NextCode = 'begin' then begin 431 432 Result := TBeginEnd.Create; 432 Result.CommonBlock := SourceCode; 433 TBeginEnd(Result).CommonBlock := SourceCode; 434 //ShowMessage(IntToStr(Integer(SourceCode)) 435 // + ' ' + IntToStr(Integer(Result))); 433 436 TParserBeginEnd.Parse(Parser, TBeginEnd(Result)); 434 437 end else 435 438 if NextCode = 'if' then begin 436 439 Result := TIfThenElse.Create; 437 Result.CommonBlock := SourceCode;440 TIfThenElse(Result).CommonBlock := SourceCode; 438 441 TParserIfThenElse.Parse(Parser, TIfThenElse(Result)); 439 442 end else 440 443 if NextCode = 'while' then begin 441 444 Result := TWhileDo.Create; 442 Result.CommonBlock := SourceCode;445 TWhileDo(Result).CommonBlock := SourceCode; 443 446 TParserWhileDo.Parse(Parser, TWhileDo(Result)); 444 447 end else … … 446 449 if Assigned(SourceCode.Variables.Search(NextCode)) then begin 447 450 Result := TAssignment.Create; 448 Result.CommonBlock := SourceCode;451 TAssignment(Result).CommonBlock := SourceCode; 449 452 IdentName := ReadCode; 450 453 TAssignment(Result).Target := SourceCode.Variables.Search(IdentName); … … 456 459 if Assigned(SourceCode.Methods.Search(NextCode)) then begin 457 460 Result := TMethodCall.Create; 458 Result.CommonBlock := SourceCode; 461 TMethodCall(Result).CommonBlock := SourceCode; 462 TMethodCall(Result).Method := SourceCode.Methods.Search(NextCode); 463 ReadCode; 459 464 // ParseMetVariable(TMethodCall(Result).Target); 460 465 end else begin … … 462 467 ErrorMessage(SUnknownIdentifier, [ReadCode]); 463 468 end; 469 end else begin 470 Result := nil; 471 ErrorMessage(SIllegalExpression, [ReadCode]); 464 472 end; 465 473 end; … … 650 658 Modules.Clear; 651 659 with TModule(Modules[Modules.Add(TModule.Create)]) do begin 652 Name := ' main';660 Name := 'Main'; 653 661 with TType(Types[Types.Add(TType.Create)]) do begin 654 Name := ' void';662 Name := 'Void'; 655 663 Size := 0; 656 664 UsedType := nil; 657 665 end; 658 666 with TType(Types[Types.Add(TType.Create)]) do begin 659 Name := ' byte';667 Name := 'Byte'; 660 668 Size := 1; 661 669 UsedType := nil; 662 670 end; 663 671 with TFunction(Methods[Methods.Add(TFunction.Create)]) do begin 664 Name := 'exit'; 672 Name := 'Exit'; 673 ResultType := TType(TModule(Modules[0]).Types[0]); 674 end; 675 with TFunction(Methods[Methods.Add(TFunction.Create)]) do begin 676 Name := 'WriteLn'; 665 677 ResultType := TType(TModule(Modules[0]).Types[0]); 666 678 end; … … 699 711 NewCommand: TCommand; 700 712 begin 713 //ShowMessage(IntToStr(Integer(SourceCode)) + ' ' + IntToStr(Integer(SourceCode.CommonBlock))); 701 714 with Parser, SourceCode do begin 702 715 Expect('begin'); … … 766 779 class procedure TParserIfThenElse.Parse(Parser: TPascalParser; SourceCode: TIfThenElse); 767 780 begin 768 with Parser do begin781 with Parser, Sourcecode do begin 769 782 Expect('if'); 770 Expect('than'); 783 Condition.CommonBlock := CommonBlock; 784 TParserExpression.Parse(Parser, Condition); 785 Expect('then'); 786 Command := TParserCommonBlock.ParseCommand(Parser, CommonBlock); 771 787 if NextCode = 'else' then begin 772 788 Expect('else'); 789 ElseCommand := TParserCommonBlock.ParseCommand(Parser, CommonBlock); 773 790 end; 774 791 end; … … 790 807 Expect('var'); 791 808 while IsIdentificator(NextCode) do begin 809 Identifiers.Clear; 792 810 VariableName := ReadCode; 793 811 Variable := Search(VariableName);
Note:
See TracChangeset
for help on using the changeset viewer.