Changeset 76 for branches/Transpascal/Compiler/Analyze/UPascalParser.pas
- Timestamp:
- Oct 21, 2010, 1:20:57 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Transpascal/Compiler/Analyze/UPascalParser.pas
r75 r76 37 37 procedure ParseVariable(SourceCode: TVariable; Exported: Boolean = False); 38 38 procedure ParseConstantList(SourceCode: TConstantList; Exported: Boolean = False); 39 procedure ParseTypeList(SourceCode: TTypeList; Exported: Boolean = False); 39 procedure ParseTypeList(SourceCode: TTypeList; Exported: Boolean = False; 40 AssignSymbol: string = '='); 40 41 function ParseType(TypeList: TTypeList; ExpectName: Boolean = True; AssignSymbol: string = '='): TType; 41 42 function ParseTypeEnumeration(TypeList: TTypeList; Name: string): TType; … … 71 72 Parser := TPascalParser.Create; 72 73 Parser.SourceCodeText := TStringList.Create; 74 Parser.OnDebugLog := OnDebugLog; 73 75 Parser.ProgramCode := ProgramCode; 74 76 Parser.OnGetSource := OnGetSource; … … 224 226 // TExpression(SubItems[1]).Value[I - 1] := Byte(Identifier[I]); 225 227 end else begin 226 TExpression(SubItems[1]).Value := StrToInt(Identifier);228 TExpression(SubItems[1]).Value := Identifier; 227 229 end; 228 230 end; … … 330 332 end else 331 333 if NextToken = ';' then 334 Result := nil 332 335 else begin 333 336 Result := nil; … … 565 568 566 569 // Parse function result type 567 if HaveResult then 568 begin 570 if HaveResult then begin 569 571 Expect(':'); 570 572 TypeName := ReadCode; 571 573 NewValueType := Parent.Types.Search(TypeName); 572 574 if not Assigned(NewValueType) then 573 ErrorMessage(SUndefinedType, [TypeName], -1) 574 else575 ErrorMessage(SUndefinedType, [TypeName], -1); 576 (* else 575 577 begin 576 578 ResultType := NewValueType; … … 581 583 ValueType := NewValueType; 582 584 end; 583 end; 585 end; *) 584 586 end; 585 587 end; … … 723 725 end else 724 726 ErrorMessage(SRedefineIdentifier, [ConstantName], -1); 725 Expect(':'); 726 TypeName := ReadCode; 727 NewValueType := Parent.Types.Search(TypeName); 727 if NextToken = ':' then begin 728 Expect(':'); 729 TypeName := ReadCode; 730 NewValueType := Parent.Types.Search(TypeName); 731 end; 728 732 Expect('='); 729 733 ConstantValue := ReadCode; … … 747 751 { TParserTypeList } 748 752 749 procedure TPascalParser.ParseTypeList(SourceCode: TTypeList; Exported: Boolean = False); 753 procedure TPascalParser.ParseTypeList(SourceCode: TTypeList; 754 Exported: Boolean = False; AssignSymbol: string = '='); 750 755 var 751 756 NewType: TType; … … 754 759 begin 755 760 while IsIdentificator(NextToken) do begin 756 NewType := ParseType(SourceCode );761 NewType := ParseType(SourceCode, True, AssignSymbol); 757 762 if Assigned(NewType) then begin 758 763 NewType.Parent := SourceCode; … … 766 771 { TParserType } 767 772 768 function TPascalParser.ParseType(TypeList: TTypeList; ExpectName: Boolean = True; AssignSymbol: string = '='): TType; 773 function TPascalParser.ParseType(TypeList: TTypeList; ExpectName: Boolean = True; 774 AssignSymbol: string = '='): TType; 769 775 var 770 776 Name: string; … … 778 784 end; 779 785 if NextToken = '(' then begin 786 // Enumeration 780 787 Result := ParseTypeEnumeration(TypeList, Name); 781 788 end else … … 817 824 end else 818 825 if NextToken = '^' then begin 826 // Pointer 819 827 Expect('^'); 820 828 Result := TTypePointer.Create; … … 824 832 end else 825 833 if NextToken = 'type' then begin 834 // Buildin base type construction 826 835 Expect('type'); 827 836 Result := TTypeInherited.Create; … … 834 843 end else TTypeInherited(Result).UsedType := nil; 835 844 end else begin 845 // Use existed type 836 846 TypeName := ReadCode; 837 847 if ExpectName then begin … … 890 900 SectionType := stVar; 891 901 Visibility := tvPublic; 892 Expect('record'); 893 Result := TTypeRecord.Create; 894 TTypeRecord(Result).Parent := TypeList; 895 TTypeRecord(Result).CommonBlock.Parent := TypeList.Parent; 896 TType(Result).Name := Name; 897 while (NextToken <> 'end') and (NextTokenType <> ttEndOfFile) do 898 begin 899 if NextToken = 'public' then begin 900 Expect('public'); 901 Visibility := tvPublic; 902 end else 903 if NextToken = 'private' then begin 904 Expect('private'); 905 Visibility := tvPrivate; 906 end else 907 if NextToken = 'published' then begin 908 Expect('published'); 909 Visibility := tvPublished; 910 end else 911 if NextToken = 'protected' then begin 912 Expect('protected'); 913 Visibility := tvProtected; 914 end else 915 if NextToken = 'var' then begin 916 Expect('var'); 917 SectionType := stVar 918 end else 919 if NextToken = 'const' then begin 920 Expect('const'); 921 SectionType := stConst 922 end else 923 if NextToken = 'type' then begin 924 Expect('type'); 925 SectionType := stType; 926 end; 927 928 if SectionType = stVar then begin 929 if NextToken = 'procedure' then 930 ParseFunctionList(TTypeRecord(Result).CommonBlock.Functions, True) 931 else if NextToken = 'function' then 932 ParseFunctionList(TTypeRecord(Result).CommonBlock.Functions, True) 933 else begin 902 Expect('record'); 903 Result := TTypeRecord.Create; 904 TTypeRecord(Result).Parent := TypeList; 905 TTypeRecord(Result).CommonBlock.Parent := TypeList.Parent; 906 TType(Result).Name := Name; 907 while (NextToken <> 'end') and (NextTokenType <> ttEndOfFile) do begin 908 if NextToken = 'public' then begin 909 Expect('public'); 910 Visibility := tvPublic; 911 end else 912 if NextToken = 'private' then begin 913 Expect('private'); 914 Visibility := tvPrivate; 915 end else 916 if NextToken = 'published' then begin 917 Expect('published'); 918 Visibility := tvPublished; 919 end else 920 if NextToken = 'protected' then begin 921 Expect('protected'); 922 Visibility := tvProtected; 923 end else 924 if NextToken = 'var' then begin 925 Expect('var'); 926 SectionType := stVar 927 end else 928 if NextToken = 'const' then begin 929 Expect('const'); 930 SectionType := stConst 931 end else 932 if NextToken = 'type' then begin 933 Expect('type'); 934 SectionType := stType; 935 end else 936 if NextToken = 'procedure' then 937 ParseFunctionList(TTypeRecord(Result).CommonBlock.Functions, True) 938 else if NextToken = 'function' then 939 ParseFunctionList(TTypeRecord(Result).CommonBlock.Functions, True) 940 else begin 941 if SectionType = stVar then begin 942 if IsIdentificator(NextToken) then 934 943 ParseVariableList(TTypeRecord(Result).CommonBlock.Variables, True) 935 //TTypeRecord(Result).CommonBlock.Types.Add(ParseType(TypeList, True, ':')); 936 //TType(TTypeRecord(Result).CommonBlock.Types.Last).Visibility := Visibility; 937 end; ParseVariableList(TTypeRecord(Result).CommonBlock.Variables) 938 end 939 else if SectionType = stConst then 940 ParseConstantList(TTypeRecord(Result).CommonBlock.Constants, True) 941 else if SectionType = stType then 942 ParseTypeList(TTypeRecord(Result).CommonBlock.Types, True); 943 end; 944 Expect('end'); 944 else ReadCode; 945 //TTypeRecord(Result).CommonBlock.Types.Add(ParseType(TypeList, True, ':')); 946 //TType(TTypeRecord(Result).CommonBlock.Types.Last).Visibility := Visibility; 947 end 948 else if SectionType = stConst then 949 ParseConstantList(TTypeRecord(Result).CommonBlock.Constants, True) 950 else if SectionType = stType then 951 ParseTypeList(TTypeRecord(Result).CommonBlock.Types, True, '='); 952 end; 953 end; 954 Expect('end'); 945 955 end; 946 956
Note:
See TracChangeset
for help on using the changeset viewer.