Ignore:
Timestamp:
Oct 20, 2010, 11:16:02 AM (14 years ago)
Author:
george
Message:
  • Fixed: Searching variable types in other modules.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Transpascal/Compiler/Analyze/UPascalParser.pas

    r72 r73  
    271271begin
    272272  begin
    273     if NextToken = 'begin' then
    274     begin
     273    if NextToken = 'begin' then begin
    275274      Result := TBeginEnd.Create;
    276275      TBeginEnd(Result).CommonBlock := SourceCode;
     
    278277      // + ' ' + IntToStr(Integer(Result)));
    279278      ParseBeginEnd(TBeginEnd(Result));
    280     end
    281     else
    282     if NextToken = 'if' then
    283     begin
     279    end else
     280    if NextToken = 'if' then begin
    284281      Result := TIfThenElse.Create;
    285282      TIfThenElse(Result).CommonBlock := SourceCode;
    286283      ParseIfThenElse(TIfThenElse(Result));
    287     end
    288     else
    289     if NextToken = 'while' then
    290     begin
     284    end else
     285    if NextToken = 'while' then begin
    291286      Result := TWhileDo.Create;
    292287      TWhileDo(Result).CommonBlock := SourceCode;
    293288      ParseWhileDo(TWhileDo(Result));
    294     end
    295     else
    296     if NextToken = 'for' then
    297     begin
     289    end else
     290    if NextToken = 'for' then begin
    298291      Result := TForToDo.Create;
    299292      TForToDo(Result).CommonBlock := SourceCode;
    300293      ParseForToDo(TForToDo(Result));
    301     end
    302     else
    303     if IsIdentificator(NextToken) then
    304     begin
    305       if Assigned(SourceCode.Variables.Search(NextToken)) then
    306       begin
     294    end else
     295    if IsIdentificator(NextToken) then begin
     296      if Assigned(SourceCode.Variables.Search(NextToken)) then begin
    307297        // Variable assignment
    308298        Result := TAssignment.Create;
     
    314304        TAssignment(Result).Source.CommonBlock := SourceCode;
    315305        ParseExpression(TAssignment(Result).Source);
    316       end
    317       else
    318       if Assigned(SourceCode.Functions.Search(NextToken)) then
    319       begin
     306      end else
     307      if Assigned(SourceCode.Functions.Search(NextToken)) then begin
    320308        // Function call
    321309        FunctionName := ReadCode;
     
    334322          Expect(')');
    335323        end;
    336       end
    337       else
    338       begin
     324      end else begin
    339325        Result := nil;
    340326        ErrorMessage(SUnknownIdentifier, [ReadCode], -1);
    341327      end;
    342     end
    343     else
     328    end else
    344329    if NextToken = ';' then
    345     else
    346     begin
     330    else begin
    347331      Result := nil;
    348332      ErrorMessage(SIllegalExpression, [ReadCode], -1);
     
    646630  I: integer;
    647631begin
     632  try
    648633  Identifiers := TStringList.Create;
    649   with SourceCode do
    650   begin
     634  with SourceCode do begin
    651635    Expect('var');
    652     while IsIdentificator(NextToken) and (NextTokenType <> ttEndOfFile) do
    653     begin
     636    while IsIdentificator(NextToken) and (NextTokenType <> ttEndOfFile) do begin
    654637      Identifiers.Clear;
    655638      VariableName := ReadCode;
    656639      Variable := Search(VariableName);
    657       if not Assigned(Variable) then
    658       begin
     640      if not Assigned(Variable) then begin
    659641        Identifiers.Add(VariableName);
    660         while NextToken = ',' do
    661         begin
     642        while NextToken = ',' do begin
    662643          Expect(',');
    663644          Identifiers.Add(ReadCode);
    664645        end;
    665       end
    666       else
     646      end else
    667647        ErrorMessage(SRedefineIdentifier, [VariableName], 0);
    668648      Expect(':');
     
    673653      else
    674654        for I := 0 to Identifiers.Count - 1 do
    675           with TVariable(Items[Add(TVariable.Create)]) do
    676           begin
     655          with TVariable(Items[Add(TVariable.Create)]) do begin
    677656            Name := Identifiers[I];
    678657            ValueType := NewValueType;
     
    681660    end;
    682661  end;
    683   Identifiers.Destroy;
     662  finally
     663    Identifiers.Free;
     664  end;
    684665end;
    685666
     
    688669procedure TPascalParser.ParseVariable(SourceCode: TVariable; Exported: Boolean = False);
    689670begin
    690   with SourceCode do
    691   begin
     671  with SourceCode do begin
    692672    Name := NextToken;
    693673    Expect(':=');
Note: See TracChangeset for help on using the changeset viewer.