Changeset 65 for branches/Transpascal/Compiler/Analyze/UParser.pas
- Timestamp:
- Oct 18, 2010, 8:53:48 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Transpascal/Compiler/Analyze/UParser.pas
r64 r65 35 35 procedure GetNextToken; 36 36 function ReadCode: string; 37 function NextToken: string; 37 38 procedure Expect(Code: string); 38 39 function IsWhiteSpace(Character: char): boolean; … … 345 346 GetNextToken; 346 347 Log('Read: ' + Result); 348 end; 349 350 function TBaseParser.NextToken: string; 351 begin 352 Result := FNextToken; 347 353 end; 348 354 … … 1064 1070 Expect(AssignSymbol); 1065 1071 end; 1066 if FNextToken = 'record' then begin 1072 if NextToken = '(' then begin 1073 // Enumeration 1074 Expect('('); 1075 Result := TTypeEnumeration.Create; 1076 TTypeEnumeration(Result).Parent := TypeList; 1077 TTypeEnumeration(Result).Name := Name; 1078 with TTypeEnumeration(Result) do 1079 with TEnumItem(Items[Items.Add(TEnumItem.Create)]) do begin 1080 Name := ReadCode; 1081 if (NextToken = '=') and (FNextTokenType = ttConstantNumber) then begin 1082 Expect('='); 1083 Index := StrToInt(ReadCode); 1084 end; 1085 end; 1086 while (NextToken = ',') and (FNextTokenType <> ttEndOfFile) do 1087 begin 1088 Expect(','); 1089 with TTypeEnumeration(Result) do 1090 with TEnumItem(Items[Items.Add(TEnumItem.Create)]) do begin 1091 Name := ReadCode; 1092 if (NextToken = '=') and (FNextTokenType = ttConstantNumber) then begin 1093 Expect('='); 1094 Index := StrToInt(ReadCode); 1095 end; 1096 end; 1097 end; 1098 Expect(')'); 1099 end else 1100 if NextToken = 'record' then begin 1067 1101 Expect('record'); 1068 1102 Result := TTypeRecord.Create; 1069 1103 TTypeRecord(Result).Parent := TypeList; 1070 1104 TType(Result).Name := Name; 1071 while ( FNextToken <> 'end') and (FNextTokenType <> ttEndOfFile) do1105 while (NextToken <> 'end') and (FNextTokenType <> ttEndOfFile) do 1072 1106 begin 1073 1107 TTypeRecord(Result).Items.Add(ParseType(TypeList, True, ':')); … … 1076 1110 Expect('end'); 1077 1111 end else 1078 if FNextToken = 'array' then begin 1112 if NextToken = 'class' then begin 1113 Expect('class'); 1114 Result := TTypeClass.Create; 1115 TTypeClass(Result).Parent := TypeList; 1116 TTypeClass(Result).Name := Name; 1117 if NextToken <> ';' then begin 1118 while (NextToken <> 'end') and (FNextTokenType <> ttEndOfFile) do 1119 begin 1120 TTypeClass(Result).Items.Add(ParseType(TypeList, True, ':')); 1121 Expect(';'); 1122 end; 1123 Expect('end'); 1124 end; 1125 end else 1126 if NextToken = 'array' then begin 1079 1127 Expect('array'); 1080 1128 Result := TTypeArray.Create; 1081 1129 TTypeArray(Result).Parent := TypeList; 1082 1130 TType(Result).Name := Name; 1083 if FNextToken = '[' then begin1131 if NextToken = '[' then begin 1084 1132 Expect('['); 1085 1133 TypeName := FNextToken; … … 1094 1142 if not Assigned(TTypeArray(Result).ItemType) then 1095 1143 ErrorMessage(SUndefinedType, [TypeName]); 1144 end else 1145 if NextToken = '^' then begin 1146 Expect('^'); 1147 Result := TTypePointer.Create; 1148 TTypePointer(Result).Parent := TypeList; 1149 TTypePointer(Result).Name := Name; 1150 TTypePointer(Result).UsedType := ParseType(TypeList, False); 1151 end else 1152 if NextToken = 'type' then begin 1153 Expect('type'); 1154 Result := TTypeInherited.Create; 1155 TTypeInherited(Result).Parent := TypeList; 1156 TTypeInherited(Result).Name := Name; 1157 if NextToken = '(' then begin 1158 Expect('('); 1159 TTypeInherited(Result).UsedType := ParseType(TypeList, False); 1160 Expect(')'); 1161 end else TTypeInherited(Result).UsedType := nil; 1096 1162 end else begin 1097 1163 TypeName := ReadCode; 1098 if TypeName = 'internal' then begin1099 Result := TType.Create;1100 TType(Result).Parent := TypeList;1101 TType(Result).Name := Name;1102 TType(Result).UsedType := nil;1103 end else1104 1164 if ExpectName then begin 1105 1165 Result := TType.Create;
Note:
See TracChangeset
for help on using the changeset viewer.