Changeset 74 for branches/Transpascal/Compiler/Analyze/UPascalParser.pas
- Timestamp:
- Oct 20, 2010, 1:57:17 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Transpascal/Compiler/Analyze/UPascalParser.pas
r73 r74 51 51 SIllegalExpression = 'Illegal expression "%s".'; 52 52 SRedefineIdentifier = 'Identificator "%s" redefinition.'; 53 STypeNotDefined = 'Type "%s" not defined.';54 53 SEndOfDataReached = 'Parser reached to end of input data.'; 55 54 SUndefinedVariable = 'Undefined variable "%s".'; … … 109 108 NewVariable: TVariable; 110 109 NewExpression: TExpression; 111 Method: TFunction;110 NewMethod: TFunction; 112 111 Constant: TConstant; 113 112 // Brackets: Integer; … … 127 126 with TExpression(Expressions.Last) do begin 128 127 SubItems[1] := TExpression.Create; 128 TExpression(SubItems[1]).CommonBlock := SourceCode.CommonBlock; 129 129 ParseExpression(TExpression(SubItems[1])); 130 130 end; … … 148 148 with TExpression(Expressions.Last) do begin 149 149 SubItems[1] := TExpression.Create; 150 TExpression(SubItems[1]).CommonBlock := SourceCode.CommonBlock; 150 151 TExpression(SubItems[1]).NodeType := ntVariable; 151 152 TExpression(SubItems[1]).Variable := NewVariable; … … 157 158 end; 158 159 end else begin 159 Method := CommonBlock.Functions.Search(Identifier); 160 if Assigned(Method) then 161 begin 160 NewMethod := CommonBlock.Functions.Search(Identifier); 161 if Assigned(NewMethod) then begin 162 162 // Referenced method 163 163 with TExpression(Expressions.Last) do begin 164 164 SubItems[1] := TExpression.Create; 165 TExpression(SubItems[1]).CommonBlock := SourceCode.CommonBlock; 165 166 if NextToken = '(' then // Method with parameters 166 167 with TExpression(SubItems[1]) do begin … … 180 181 end; 181 182 TExpression(SubItems[1]).NodeType := ntFunction; 182 TExpression(SubItems[1]).Method := Method;183 TExpression(SubItems[1]).Method := NewMethod; 183 184 end; 184 185 with TExpression(Expressions.Items[Expressions.Add(TExpression.Create)]) do … … 194 195 with TExpression(Expressions.Last) do begin 195 196 SubItems[1] := TExpression.Create; 197 TExpression(SubItems[1]).CommonBlock := SourceCode.CommonBlock; 196 198 TExpression(SubItems[1]).NodeType := ntConstant; 197 199 TExpression(SubItems[1]).Value := Constant.Value; … … 210 212 end else begin 211 213 // Constant value 212 with TExpression(Expressions.Last) do 213 begin 214 with TExpression(Expressions.Last) do begin 214 215 SubItems[1] := TExpression.Create; 215 216 TExpression(SubItems[1]).CommonBlock := SourceCode.CommonBlock; … … 383 384 if NextToken = 'implementation' then 384 385 ParseUnitImplementation(SourceCode); 386 387 if NextToken = 'initialization' then begin 388 Expect('initialization'); 389 end; 390 if NextToken = 'finalization' then begin 391 Expect('finalization'); 392 end; 385 393 end; 386 394 … … 411 419 EndSymbol: char = ';'); 412 420 begin 413 with SourceCode do 414 begin 415 while NextToken <> EndSymbol do 416 begin 421 with SourceCode do begin 422 while (NextToken <> EndSymbol) do begin 417 423 if NextToken = 'var' then 418 424 ParseVariableList(Variables) … … 425 431 else if NextToken = 'function' then 426 432 ParseFunctionList(Functions) 427 else 428 begin 433 else begin 429 434 ParseBeginEnd(Code); 430 435 Break; … … 525 530 end; 526 531 end else 527 ErrorMessage(SRedefineIdentifier, [VariableName], 0);532 ErrorMessage(SRedefineIdentifier, [VariableName], -1); 528 533 Expect(':'); 529 534 TypeName := ReadCode; 530 535 NewValueType := Parent.Types.Search(TypeName); 531 536 if not Assigned(NewValueType) then 532 ErrorMessage(S TypeNotDefined, [TypeName], -1)537 ErrorMessage(SUndefinedType, [TypeName], -1) 533 538 else 534 539 for I := 0 to Identifiers.Count - 1 do … … 550 555 NewValueType := Parent.Types.Search(TypeName); 551 556 if not Assigned(NewValueType) then 552 ErrorMessage(S TypeNotDefined, [TypeName], -1)557 ErrorMessage(SUndefinedType, [TypeName], -1) 553 558 else 554 559 begin … … 607 612 ControlVariable := SourceCode.CommonBlock.Variables.Search(VariableName); 608 613 if not Assigned(ControlVariable) then 609 ErrorMessage(SUndefinedVariable, [VariableName], 0);614 ErrorMessage(SUndefinedVariable, [VariableName], -1); 610 615 Expect(':='); 611 616 Start.CommonBlock := CommonBlock; … … 645 650 end; 646 651 end else 647 ErrorMessage(SRedefineIdentifier, [VariableName], 0);652 ErrorMessage(SRedefineIdentifier, [VariableName], -1); 648 653 Expect(':'); 649 654 TypeName := ReadCode; 650 655 NewValueType := Parent.Types.Search(TypeName); 651 656 if NewValueType = nil then 652 ErrorMessage(S TypeNotDefined, [TypeName], -1)657 ErrorMessage(SUndefinedType, [TypeName], -1) 653 658 else 654 659 for I := 0 to Identifiers.Count - 1 do … … 706 711 end 707 712 else 708 ErrorMessage(SRedefineIdentifier, [ConstantName], 0);713 ErrorMessage(SRedefineIdentifier, [ConstantName], -1); 709 714 Expect(':'); 710 715 TypeName := ReadCode; … … 715 720 716 721 if NewValueType = nil then 717 ErrorMessage(S TypeNotDefined, [TypeName], -1)722 ErrorMessage(SUndefinedType, [TypeName], -1) 718 723 else 719 724 for I := 0 to Identifiers.Count - 1 do … … 792 797 TTypeArray(Result).IndexType := ParseType(TypeList, False); 793 798 if not Assigned(TTypeArray(Result).IndexType) then 794 ErrorMessage(SUndefinedType, [TypeName], 0);799 ErrorMessage(SUndefinedType, [TypeName], -1); 795 800 Expect(']'); 796 801 end; … … 799 804 TTypeArray(Result).ItemType := ParseType(TypeList, False); 800 805 if not Assigned(TTypeArray(Result).ItemType) then 801 ErrorMessage(SUndefinedType, [TypeName], 0);806 ErrorMessage(SUndefinedType, [TypeName], -1); 802 807 end else 803 808 if NextToken = '^' then begin … … 826 831 TType(Result).UsedType := TypeList.Search(TypeName); 827 832 if not Assigned(TType(Result).UsedType) then 828 ErrorMessage(SUndefinedType, [TypeName], 0);833 ErrorMessage(SUndefinedType, [TypeName], -1); 829 834 end else begin 830 835 TType(Result) := TypeList.Search(TypeName); 831 836 if not Assigned(TType(Result)) then 832 ErrorMessage(SUndefinedType, [TypeName], 0);837 ErrorMessage(SUndefinedType, [TypeName], -1); 833 838 end; 834 839 end;
Note:
See TracChangeset
for help on using the changeset viewer.