Ignore:
Timestamp:
Aug 5, 2010, 3:13:03 PM (14 years ago)
Author:
george
Message:

Enhanced C code generation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DelphiToC/Analyze/UPascalParser.pas

    r41 r42  
    104104resourcestring
    105105  SUnknownIdentifier = 'Unknown identificator "%s".';
     106  SIllegalExpression = 'Illegal expression "%s".';
    106107  SExpectedButFound = 'Expected "%s" but "%s" found.';
    107108  SRedefineIdentifier = 'Identificator "%s" redefinition.';
     
    430431    if NextCode = 'begin' then begin
    431432      Result := TBeginEnd.Create;
    432       Result.CommonBlock := SourceCode;
     433      TBeginEnd(Result).CommonBlock := SourceCode;
     434      //ShowMessage(IntToStr(Integer(SourceCode))
     435      // + ' ' + IntToStr(Integer(Result)));
    433436      TParserBeginEnd.Parse(Parser, TBeginEnd(Result));
    434437    end else
    435438    if NextCode = 'if' then begin
    436439      Result := TIfThenElse.Create;
    437       Result.CommonBlock := SourceCode;
     440      TIfThenElse(Result).CommonBlock := SourceCode;
    438441      TParserIfThenElse.Parse(Parser, TIfThenElse(Result));
    439442    end else
    440443    if NextCode = 'while' then begin
    441444      Result := TWhileDo.Create;
    442       Result.CommonBlock := SourceCode;
     445      TWhileDo(Result).CommonBlock := SourceCode;
    443446      TParserWhileDo.Parse(Parser, TWhileDo(Result));
    444447    end else
     
    446449      if Assigned(SourceCode.Variables.Search(NextCode)) then begin
    447450        Result := TAssignment.Create;
    448         Result.CommonBlock := SourceCode;
     451        TAssignment(Result).CommonBlock := SourceCode;
    449452        IdentName := ReadCode;
    450453        TAssignment(Result).Target := SourceCode.Variables.Search(IdentName);
     
    456459      if Assigned(SourceCode.Methods.Search(NextCode)) then begin
    457460        Result := TMethodCall.Create;
    458         Result.CommonBlock := SourceCode;
     461        TMethodCall(Result).CommonBlock := SourceCode;
     462        TMethodCall(Result).Method := SourceCode.Methods.Search(NextCode);
     463        ReadCode;
    459464  //      ParseMetVariable(TMethodCall(Result).Target);
    460465      end else begin
     
    462467        ErrorMessage(SUnknownIdentifier, [ReadCode]);
    463468      end;
     469    end else begin
     470      Result := nil;
     471      ErrorMessage(SIllegalExpression, [ReadCode]);
    464472    end;
    465473  end;
     
    650658    Modules.Clear;
    651659    with TModule(Modules[Modules.Add(TModule.Create)]) do begin
    652       Name := 'main';
     660      Name := 'Main';
    653661      with TType(Types[Types.Add(TType.Create)]) do begin
    654         Name := 'void';
     662        Name := 'Void';
    655663        Size := 0;
    656664        UsedType := nil;
    657665      end;
    658666      with TType(Types[Types.Add(TType.Create)]) do begin
    659         Name := 'byte';
     667        Name := 'Byte';
    660668        Size := 1;
    661669        UsedType := nil;
    662670      end;
    663671      with TFunction(Methods[Methods.Add(TFunction.Create)]) do begin
    664         Name := 'exit';
     672        Name := 'Exit';
     673        ResultType := TType(TModule(Modules[0]).Types[0]);
     674      end;
     675      with TFunction(Methods[Methods.Add(TFunction.Create)]) do begin
     676        Name := 'WriteLn';
    665677        ResultType := TType(TModule(Modules[0]).Types[0]);
    666678      end;
     
    699711  NewCommand: TCommand;
    700712begin
     713  //ShowMessage(IntToStr(Integer(SourceCode)) + ' ' + IntToStr(Integer(SourceCode.CommonBlock)));
    701714  with Parser, SourceCode do begin
    702715    Expect('begin');
     
    766779class procedure TParserIfThenElse.Parse(Parser: TPascalParser; SourceCode: TIfThenElse);
    767780begin
    768   with Parser do begin
     781  with Parser, Sourcecode do begin
    769782    Expect('if');
    770     Expect('than');
     783    Condition.CommonBlock := CommonBlock;
     784    TParserExpression.Parse(Parser, Condition);
     785    Expect('then');
     786    Command := TParserCommonBlock.ParseCommand(Parser, CommonBlock);
    771787    if NextCode = 'else' then begin
    772788      Expect('else');
     789      ElseCommand := TParserCommonBlock.ParseCommand(Parser, CommonBlock);
    773790    end;
    774791  end;
     
    790807    Expect('var');
    791808    while IsIdentificator(NextCode) do begin
     809      Identifiers.Clear;
    792810      VariableName := ReadCode;
    793811      Variable := Search(VariableName);
Note: See TracChangeset for help on using the changeset viewer.