Changeset 64 for branches/Transpascal/Compiler/Analyze/UParser.pas
- Timestamp:
- Oct 15, 2010, 2:13:42 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Transpascal/Compiler/Analyze/UParser.pas
r60 r64 402 402 Expressions := TExpressionList.Create; 403 403 Expressions.Add(TExpression.Create); 404 with SourceCode do 405 begin 404 with SourceCode do begin 406 405 while ((FNextToken <> ';') and (FNextToken <> ',') and 407 406 (not IsKeyWord(FNextToken))) and not 408 (((FNextToken = ')') or (FNextToken = ']'))) do 409 begin 407 (((FNextToken = ')') or (FNextToken = ']'))) do begin 410 408 Identifier := ReadCode; 411 if Identifier = '(' then 412 begin 409 if Identifier = '(' then begin 413 410 // Subexpression 414 with TExpression(Expressions.Last) do 415 begin 411 with TExpression(Expressions.Last) do begin 416 412 SubItems[1] := TExpression.Create; 417 413 ParseExpression(TExpression(SubItems[1])); … … 423 419 end; 424 420 Expect(')'); 425 end 426 else 427 if IsOperator(Identifier) then 428 begin 421 end else 422 if IsOperator(Identifier) then begin 429 423 // Operator 430 424 TExpression(Expressions.Last).OperatorName := Identifier; 431 425 TExpression(Expressions.Last).NodeType := ntOperator; 432 end 433 else 434 if IsIdentificator(Identifier) then 435 begin 426 end else 427 if IsIdentificator(Identifier) then begin 436 428 // Reference to identificator 437 429 NewVariable := CommonBlock.Variables.Search(Identifier); 438 if Assigned(NewVariable) then 439 begin 430 if Assigned(NewVariable) then begin 440 431 // Referenced variable 441 with TExpression(Expressions.Last) do 442 begin 432 with TExpression(Expressions.Last) do begin 443 433 SubItems[1] := TExpression.Create; 444 434 TExpression(SubItems[1]).NodeType := ntVariable; … … 450 440 SubItems[0] := TExpression(Expressions[Expressions.Count - 2]).SubItems[1]; 451 441 end; 452 end 453 else 454 begin 442 end else begin 455 443 Method := CommonBlock.Functions.Search(Identifier); 456 444 if Assigned(Method) then 457 445 begin 458 446 // Referenced method 459 with TExpression(Expressions.Last) do 460 begin 447 with TExpression(Expressions.Last) do begin 461 448 SubItems[1] := TExpression.Create; 462 449 if FNextToken = '(' then // Method with parameters 463 with TExpression(SubItems[1]) do 464 begin 450 with TExpression(SubItems[1]) do begin 465 451 Expect('('); 466 452 NewExpression := TExpression.Create; … … 468 454 ParseExpression(NewExpression); 469 455 SubItems.Add(NewExpression); 470 while FNextToken = ',' do 471 begin 456 while FNextToken = ',' do begin 472 457 Expect(','); 473 458 NewExpression := TExpression.Create; … … 487 472 TExpression(Expressions[Expressions.Count - 2]).SubItems[1]; 488 473 end; 489 end 490 else 491 begin 474 end else begin 492 475 Constant := CommonBlock.Constants.Search(Identifier); 493 if Assigned(Constant) then 494 begin 476 if Assigned(Constant) then begin 495 477 // Referenced constant 496 with TExpression(Expressions.Last) do 497 begin 478 with TExpression(Expressions.Last) do begin 498 479 SubItems[1] := TExpression.Create; 499 480 TExpression(SubItems[1]).NodeType := ntConstant; … … 501 482 end; 502 483 with TExpression(Expressions.Items[Expressions.Add( 503 TExpression.Create)]) do 504 begin 484 TExpression.Create)]) do begin 505 485 CommonBlock := SourceCode.CommonBlock; 506 486 SubItems[0] := 507 487 TExpression(Expressions[Expressions.Count - 2]).SubItems[1]; 508 488 end; 509 end 510 else 511 begin 489 end else begin 512 490 ErrorMessage(SUnknownIdentifier, [Identifier]); 513 491 end; 514 492 end; 515 493 end; 516 end 517 else 518 begin 494 end else begin 519 495 // Constant value 520 496 with TExpression(Expressions.Last) do … … 524 500 TExpression(SubItems[1]).NodeType := ntConstant; 525 501 526 if Identifier[1] = '''' then 527 begin 502 if Identifier[1] = '''' then begin 528 503 TExpression(SubItems[1]).Value := Identifier; 529 504 //SetLength(TExpression(SubItems[1]).Value, Length(Identifier)); 530 505 //for I := 1 to Length(Identifier) do 531 506 // TExpression(SubItems[1]).Value[I - 1] := Byte(Identifier[I]); 532 end 533 else 534 begin 507 end else begin 535 508 TExpression(SubItems[1]).Value := Identifier; 536 509 end; … … 546 519 547 520 // Build expression tree 548 for II := 0 to High(Operators) do 549 begin 521 for II := 0 to High(Operators) do begin 550 522 I := 1; 551 while (I < Expressions.Count - 1) do 552 begin 523 while (I < Expressions.Count - 1) do begin 553 524 if not TExpression(Expressions[I]).Associated and 554 525 (TExpression(Expressions[I]).OperatorName = Operators[II]) then … … 558 529 TExpression(Expressions[I + 1]).SubItems[0] := Expressions[I]; 559 530 //Expressions.Delete(I); 560 end 561 else 562 Inc(I); 531 end else Inc(I); 563 532 end; 564 533 end; … … 569 538 if Expressions.Count > 1 then 570 539 TExpression(Expressions[1]).SubItems[0] := nil; 571 Expressions. Destroy;540 Expressions.Free; 572 541 end; 573 542 end; … … 1168 1137 begin 1169 1138 Name := ReadCode; 1139 if FNextToken = 'in' then begin 1140 Expect('in'); 1141 Location := ReadCode; 1142 end else Location := Name + '.pas'; 1170 1143 Module := SourceCode.ParentModule.ParentProgram.Modules.Search(Name); 1171 1144 if not Assigned(Module) then begin … … 1181 1154 begin 1182 1155 Name := ReadCode; 1156 if FNextToken = 'in' then begin 1157 Expect('in'); 1158 Location := ReadCode; 1159 end else Location := Name + '.pas'; 1183 1160 Module := SourceCode.ParentModule.ParentProgram.Modules.Search(Name); 1184 1161 if not Assigned(Module) then begin
Note:
See TracChangeset
for help on using the changeset viewer.