Changeset 53 for branches/DelphiToC/Analyze/UParser.pas
- Timestamp:
- Aug 10, 2010, 10:14:57 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DelphiToC/Analyze/UParser.pas
r51 r53 65 65 procedure ParseConstantList(SourceCode: TConstantList); 66 66 procedure ParseTypeList(SourceCode: TTypeList); 67 function ParseType(TypeList: TTypeList): TType; 68 function ParseRecordItem(TypeList: TTypeList): TType; 67 function ParseType(TypeList: TTypeList; ExpectName: Boolean = True; AssignSymbol: string = '='): TType; 69 68 private 70 69 end; … … 999 998 begin 1000 999 Expect('type'); 1001 while IsIdentificator(FNextToken) do 1000 while IsIdentificator(FNextToken) do begin 1002 1001 NewType := ParseType(SourceCode); 1003 1002 if Assigned(NewType) then begin … … 1005 1004 Add(NewType); 1006 1005 end; 1006 Expect(';'); 1007 end; 1007 1008 end; 1008 1009 end; … … 1010 1011 { TParserType } 1011 1012 1012 function TPascalParser.ParseType(TypeList: TTypeList ): TType;1013 function TPascalParser.ParseType(TypeList: TTypeList; ExpectName: Boolean = True; AssignSymbol: string = '='): TType; 1013 1014 var 1014 1015 Name: string; 1015 UsedTypeName: string;1016 TypeName: string; 1016 1017 begin 1017 1018 //with SourceCode do 1018 1019 begin 1019 Name := ReadCode; 1020 Expect('='); 1020 if ExpectName then begin 1021 Name := ReadCode; 1022 Expect(AssignSymbol); 1023 end; 1021 1024 if FNextToken = 'record' then begin 1022 1025 Expect('record'); … … 1026 1029 while (FNextToken <> 'end') and (FNextTokenType <> ttEndOfFile) do 1027 1030 begin 1028 TTypeRecord(Result).Items.Add(ParseRecordItem(TypeList)); 1031 TTypeRecord(Result).Items.Add(ParseType(TypeList, True, ':')); 1032 Expect(';'); 1029 1033 end; 1030 1034 Expect('end'); 1035 end else 1036 if FNextToken = 'array' then begin 1037 Expect('array'); 1038 Result := TTypeArray.Create; 1039 TTypeArray(Result).Parent := TypeList; 1040 TType(Result).Name := Name; 1041 if FNextToken = '[' then begin 1042 Expect('['); 1043 TypeName := FNextToken; 1044 TTypeArray(Result).IndexType := ParseType(TypeList, False); 1045 if not Assigned(TTypeArray(Result).IndexType) then 1046 ErrorMessage(SUndefinedType, [TypeName]); 1047 Expect(']'); 1048 end; 1049 Expect('of'); 1050 TypeName := FNextToken; 1051 TTypeArray(Result).ItemType := ParseType(TypeList, False); 1052 if not Assigned(TTypeArray(Result).ItemType) then 1053 ErrorMessage(SUndefinedType, [TypeName]); 1031 1054 end else begin 1032 UsedTypeName := ReadCode; 1033 Result := TType.Create; 1034 TType(Result).Parent := TypeList; 1035 TType(Result).Name := Name; 1036 TType(Result).UsedType := TypeList.Search(UsedTypeName); 1037 if not Assigned(TType(Result).UsedType) then ErrorMessage(SUndefinedType, [UsedTypeName]); 1038 end; 1039 Expect(';'); 1040 end; 1041 end; 1042 1043 function TPascalParser.ParseRecordItem(TypeList: TTypeList): TType; 1044 var 1045 Name: string; 1046 UsedTypeName: string; 1047 begin 1048 //with SourceCode do 1049 begin 1050 Name := ReadCode; 1051 Expect(':'); 1052 if FNextToken = 'record' then begin 1053 Expect('record'); 1054 Result := TTypeRecord.Create; 1055 TTypeRecord(Result).Parent := TypeList; 1056 TTypeRecord(Result).Name := Name; 1057 while (FNextToken <> 'end') and (FNextTokenType <> ttEndOfFile) do 1058 begin 1059 TTypeRecord(Result).Items.Add(ParseRecordItem(TypeList)); 1060 end; 1061 Expect('end'); 1062 end else begin 1063 UsedTypeName := ReadCode; 1064 Result := TType.Create; 1065 TType(Result).Parent := TypeList; 1066 TType(Result).Name := Name; 1067 TType(Result).UsedType := TypeList.Search(UsedTypeName); 1068 if not Assigned(TType(Result).UsedType) then ErrorMessage(SUndefinedType, [UsedTypeName]); 1069 end; 1070 Expect(';'); 1055 TypeName := ReadCode; 1056 if ExpectName then begin 1057 Result := TType.Create; 1058 TType(Result).Parent := TypeList; 1059 TType(Result).Name := Name; 1060 TType(Result).UsedType := TypeList.Search(TypeName); 1061 if not Assigned(TType(Result).UsedType) then 1062 ErrorMessage(SUndefinedType, [TypeName]); 1063 end else begin 1064 TType(Result) := TypeList.Search(TypeName); 1065 if not Assigned(TType(Result)) then 1066 ErrorMessage(SUndefinedType, [TypeName]); 1067 end; 1068 end; 1071 1069 end; 1072 1070 end;
Note:
See TracChangeset
for help on using the changeset viewer.