Changeset 5 for trunk/Compiler/Analyze/UPascalParser.pas
- Timestamp:
- Nov 5, 2010, 9:36:20 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Compiler/Analyze/UPascalParser.pas
r4 r5 137 137 function TPascalParser.ParseExpression(SourceCode: TExpression): Boolean; 138 138 var 139 NewVariable: TVariable;140 NewExpression: TExpression;141 NewMethod: TFunction;142 Constant: TConstant;143 UseType: TType;144 // Brackets: Integer;145 139 Expressions: TListExpression; 146 I: integer;147 II: integer;140 I: Integer; 141 II: Integer; 148 142 begin 149 143 try 150 144 Expressions := TListExpression.Create; 145 Expressions.OwnsObjects := False; 151 146 Expressions.Add(TExpression.Create); 152 147 with SourceCode do begin … … 155 150 if not ParseExpressionParenthases(SourceCode, Expressions) then 156 151 if not ParseExpressionOperator(SourceCode, Expressions) then 157 if not ParseExpressionRightValue(SourceCode, Expressions) then begin 152 if not ParseExpressionRightValue(SourceCode, Expressions) then 153 begin 158 154 ErrorMessage(SInvalidAssignmentValue, [NextToken]); 159 155 ReadToken; … … 171 167 Expressions[I - 1].SubItems.Last := Expressions[I]; 172 168 Expressions[I + 1].SubItems.First := Expressions[I]; 173 //Expressions.Delete(I);169 Expressions.Delete(I); 174 170 end else Inc(I); 175 171 end; … … 196 192 // Subexpression 197 193 NewExpression := TExpression.Create; 194 NewExpression.Braces := True; 198 195 NewExpression.CommonBlock := SourceCode.CommonBlock; 199 196 ParseExpression(NewExpression); … … 230 227 NewExpression: TExpression; 231 228 Identifier: string; 232 O: TObject;233 begin 234 O:= nil;235 with SourceCode do 236 if IsIdentificator(NextToken) then begin229 IntConst: Integer; 230 begin 231 NewExpression := nil; 232 with SourceCode do begin 233 // if IsIdentificator(NextToken) then begin 237 234 // Start with type 238 235 UseType := CommonBlock.Types.Search(NextToken); … … 240 237 ReadToken; 241 238 if (UseType is TTypeRecord) or (UseType is TTypeClass) then begin 239 // type.variable or type.function 242 240 Expect('.'); 243 241 Identifier := ReadToken; 244 242 UseVariable := TTypeRecord(UseType).CommonBlock.Variables.Search(Identifier); 245 243 if Assigned(UseVariable) then begin 246 O := UseVariable; 247 end; 248 if not Assigned(O) then begin 244 NewExpression := TExpression.Create; 245 NewExpression.CommonBlock := SourceCode.CommonBlock; 246 NewExpression.NodeType := ntVariable; 247 NewExpression.Variable := UseVariable; 248 end; 249 if not Assigned(NewExpression) then begin 249 250 UseFunction := TTypeRecord(UseType).CommonBlock.Functions.Search(Identifier); 250 251 if Assigned(UseFunction) then begin 251 O := UseFunction; 252 NewExpression := TExpression.Create; 253 NewExpression.CommonBlock := SourceCode.CommonBlock; 254 NewExpression.NodeType := ntFunction; 255 NewExpression.FunctionCall := UseFunction; 252 256 end; 253 257 end; 254 if not Assigned( O) then258 if not Assigned(NewExpression) then 255 259 ErrorMessage(SUndefinedVariable, [Identifier]); 256 260 end else ErrorMessage(SIllegalExpression, [Identifier]); 257 261 end; 258 if not Assigned(O) then begin 259 UseVariable := CommonBlock.Variables.Search(Identifier); 262 if not Assigned(NewExpression) then begin 263 // Referenced variable 264 UseVariable := CommonBlock.Variables.Search(NextToken); 260 265 if Assigned(UseVariable) then begin 261 // Referenced variable262 266 ReadToken; 263 267 NewExpression := TExpression.Create; 264 268 NewExpression.CommonBlock := SourceCode.CommonBlock; 265 269 NewExpression.NodeType := ntVariable; 266 NewExpression.Variable := TVariable(UseVariable); 267 SubItems.Last := NewExpression; 268 end; 269 end; 270 if not Assigned(O) then begin 271 ParseExpressionFunctionCall(SourceCode, Expressions, TFunction(O)); 272 NewExpression := TExpression.Create; 273 NewExpression.CommonBlock := SourceCode.CommonBlock; 274 NewExpression.NodeType := ntFunction; 275 NewExpression.FunctionCall := TFunction(O); 276 SubItems.Last := NewExpression; 277 end; 278 if not Assigned(O) then begin 270 NewExpression.Variable := UseVariable; 271 end; 272 end; 273 if not Assigned(NewExpression) then begin 274 // Function call 275 ParseExpressionFunctionCall(SourceCode, Expressions, UseFunction); 276 if Assigned(UseFunction) then begin 277 NewExpression := TExpression.Create; 278 NewExpression.CommonBlock := SourceCode.CommonBlock; 279 NewExpression.NodeType := ntFunction; 280 NewExpression.FunctionCall := UseFunction; 281 end; 282 end; 283 if not Assigned(NewExpression) then begin 284 // Referenced constant 279 285 UseConstant := CommonBlock.Constants.Search(NextToken); 280 286 if Assigned(UseConstant) then begin 281 287 ReadToken; 282 O := UseConstant;283 288 NewExpression := TExpression.Create; 284 289 NewExpression.CommonBlock := SourceCode.CommonBlock; 285 290 NewExpression.NodeType := ntConstant; 286 NewExpression.Constant := TConstant(O); 287 SubItems.Last := NewExpression; 288 end; 289 end; 290 if not Assigned(O) then begin 291 NewExpression.Constant := UseConstant; 292 end; 293 end; 294 if not Assigned(NewExpression) then begin 291 295 // Constant value 292 O := TConstant.Create;293 TConstant(O).Value := ReadToken;294 296 NewExpression := TExpression.Create; 295 297 NewExpression.CommonBlock := SourceCode.CommonBlock; 296 NewExpression.NodeType := ntConstant; 297 NewExpression.Constant := TConstant(O); 298 SubItems.Last := NewExpression; 299 end; 300 if not Assigned(O) then begin 298 NewExpression.NodeType := ntValue; 299 NewExpression.Constant := TConstant.Create; 300 NewExpression.Value := ReadToken; 301 if TryStrToInt(NewExpression.Value, IntConst) then 302 NewExpression.Value := IntConst; 303 end; 304 if Assigned(NewExpression) then begin 305 Expressions.Last.SubItems.Last := NewExpression; 306 with Expressions.Items[Expressions.Add(TExpression.Create)] do 307 begin 308 CommonBlock := SourceCode.CommonBlock; 309 SubItems.First := NewExpression; 310 end; 311 Result := True; 312 end else begin 313 Result := False; 301 314 ErrorMessage(SUnknownIdentifier, [ReadToken]); 302 315 end; 303 304 with Expressions.Items[Expressions.Add(TExpression.Create)] do 305 begin 306 CommonBlock := SourceCode.CommonBlock; 307 SubItems.First := NewExpression; 308 end; 309 Result := True; 310 end else Result := False; 316 // end else Result := False; 317 end; 311 318 end; 312 319
Note:
See TracChangeset
for help on using the changeset viewer.