Ignore:
Timestamp:
Aug 9, 2010, 10:22:30 AM (14 years ago)
Author:
george
Message:

Reworked tokenizer code with state machine instead of direct sequence analyze.
Parser classes with class methods rewrited back to single class TPaascalParser which inherit from TBasePascal.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DelphiToC/UPascalCompiler.pas

    r43 r44  
    1111
    1212type
     13
     14  { TCompiler }
     15
    1316  TCompiler = class
    1417  private
    1518    FOnErrorMessage: TOnErrorMessage;
    1619    procedure ErrorMessage(Text: string);
     20    procedure Init;
    1721  public
    1822    ProgramCode: TProgram;
     
    3236procedure TCompiler.Compile;
    3337begin
    34   Parser.CodePosition := 1;
     38  Init;
     39  Parser.Init;
    3540  try
    36     TParserProgram.Parse(Parser, ProgramCode);
     41    Parser.ParseAll(ProgramCode);
    3742  except
    3843    on EEndOfData do ;
     
    6570end;
    6671
     72procedure TCompiler.Init;
     73begin
     74  with Parser do begin
     75    Log('==== Parse start ====');
     76    with ProgramCode do begin
     77      Modules.Clear;
     78
     79      with TModule(Modules[Modules.Add(TModule.Create)]) do begin
     80        Name := 'Main';
     81        with TType(Types[Types.Add(TType.Create)]) do begin
     82          Name := 'Void';
     83          Size := 0;
     84          UsedType := nil;
     85        end;
     86        with TType(Types[Types.Add(TType.Create)]) do begin
     87          Name := 'Byte';
     88          Size := 1;
     89          UsedType := nil;
     90        end;
     91        with TFunction(Methods[Methods.Add(TFunction.Create)]) do begin
     92          Name := 'Exit';
     93          ResultType := TType(TModule(Modules[0]).Types[0]);
     94        end;
     95        with TFunction(Methods[Methods.Add(TFunction.Create)]) do begin
     96          Name := 'WriteLn';
     97          ResultType := TType(TModule(Modules[0]).Types[0]);
     98        end;
     99      end;
     100    end;
     101  end;
     102end;
     103
    67104end.
Note: See TracChangeset for help on using the changeset viewer.