Changeset 68 for branches/Transpascal/Compiler/Analyze/UParser.pas
- Timestamp:
- Oct 18, 2010, 2:14:52 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Transpascal/Compiler/Analyze/UParser.pas
r67 r68 83 83 procedure ParseTypeList(SourceCode: TTypeList; Exported: Boolean = False); 84 84 function ParseType(TypeList: TTypeList; ExpectName: Boolean = True; AssignSymbol: string = '='): TType; 85 function ParseTypeEnumeration(TypeList: TTypeList; Name: string): TType; 86 function ParseTypeRecord(TypeList: TTypeList; Name: string): TType; 85 87 property OnGetSource: TGetSourceEvent read FOnGetSource 86 88 write FOnGetSource; … … 744 746 begin 745 747 with SourceCode do begin 746 while FNextToken <> 'implementation'do begin748 while (FNextToken <> 'implementation') and (FNextTokenType <> ttEndOfFile) do begin 747 749 if FNextToken = 'var' then 748 750 ParseVariableList(Variables) … … 755 757 else if FNextToken = 'function' then 756 758 ParseFunctionList(Functions, True) 757 else ErrorMessage(SUnknownIdentifier, [FNextToken]); 759 else begin 760 ErrorMessage(SUnknownIdentifier, [FNextToken]); 761 ReadCode; 762 end; 758 763 end; 759 764 end; … … 1071 1076 end; 1072 1077 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(')'); 1078 Result := ParseTypeEnumeration(TypeList, Name); 1099 1079 end else 1100 1080 if NextToken = 'record' then begin 1101 Expect('record'); 1102 Result := TTypeRecord.Create; 1103 TTypeRecord(Result).Parent := TypeList; 1104 TType(Result).Name := Name; 1105 while (NextToken <> 'end') and (FNextTokenType <> ttEndOfFile) do 1106 begin 1107 TTypeRecord(Result).Items.Add(ParseType(TypeList, True, ':')); 1108 Expect(';'); 1109 end; 1110 Expect('end'); 1081 Result := ParseTypeRecord(TypeList, Name); 1111 1082 end else 1112 1083 if NextToken = 'class' then begin … … 1178 1149 end; 1179 1150 1151 function TPascalParser.ParseTypeEnumeration(TypeList: TTypeList; Name: string): TType; 1152 begin 1153 Expect('('); 1154 Result := TTypeEnumeration.Create; 1155 TTypeEnumeration(Result).Parent := TypeList; 1156 TTypeEnumeration(Result).Name := Name; 1157 with TTypeEnumeration(Result) do 1158 with TEnumItem(Items[Items.Add(TEnumItem.Create)]) do begin 1159 Name := ReadCode; 1160 if (NextToken = '=') and (FNextTokenType = ttConstantNumber) then begin 1161 Expect('='); 1162 Index := StrToInt(ReadCode); 1163 end; 1164 end; 1165 while (NextToken = ',') and (FNextTokenType <> ttEndOfFile) do 1166 begin 1167 Expect(','); 1168 with TTypeEnumeration(Result) do 1169 with TEnumItem(Items[Items.Add(TEnumItem.Create)]) do begin 1170 Name := ReadCode; 1171 if (NextToken = '=') and (FNextTokenType = ttConstantNumber) then begin 1172 Expect('='); 1173 Index := StrToInt(ReadCode); 1174 end; 1175 end; 1176 end; 1177 Expect(')'); 1178 end; 1179 1180 function TPascalParser.ParseTypeRecord(TypeList: TTypeList; Name: string 1181 ): TType; 1182 var 1183 Visibility: TTypeVisibility; 1184 begin 1185 Visibility := tvPublic; 1186 Expect('record'); 1187 Result := TTypeRecord.Create; 1188 TTypeRecord(Result).Parent := TypeList; 1189 TType(Result).Name := Name; 1190 while (NextToken <> 'end') and (FNextTokenType <> ttEndOfFile) do 1191 begin 1192 if NextToken = 'public' then begin 1193 Expect('public'); 1194 Visibility := tvPublic; 1195 end else 1196 if NextToken = 'private' then begin 1197 Expect('private'); 1198 Visibility := tvPrivate; 1199 end else 1200 if NextToken = 'published' then begin 1201 Expect('published'); 1202 Visibility := tvPublished; 1203 end else 1204 if NextToken = 'protected' then begin 1205 Expect('protected'); 1206 Visibility := tvProtected; 1207 end else 1208 if NextToken = 'var' then 1209 ParseVariableList(TTypeRecord(Result).CommonBlock.Variables) 1210 else if FNextToken = 'const' then 1211 ParseConstantList(TTypeRecord(Result).CommonBlock.Constants, True) 1212 else if FNextToken = 'type' then 1213 ParseTypeList(TTypeRecord(Result).CommonBlock.Types, True) 1214 else if FNextToken = 'procedure' then 1215 ParseFunctionList(TTypeRecord(Result).CommonBlock.Functions, True) 1216 else if FNextToken = 'function' then 1217 ParseFunctionList(TTypeRecord(Result).CommonBlock.Functions, True) 1218 else begin 1219 TTypeRecord(Result).CommonBlock.Types.Add(ParseType(TypeList, True, ':')); 1220 TType(TTypeRecord(Result).CommonBlock.Types.Last).Visibility := Visibility; 1221 end; 1222 Expect(';'); 1223 end; 1224 Expect('end'); 1225 end; 1226 1180 1227 constructor TPascalParser.Create; 1181 1228 begin
Note:
See TracChangeset
for help on using the changeset viewer.