Ignore:
Timestamp:
Aug 4, 2010, 1:53:01 PM (14 years ago)
Author:
george
Message:
  • Upraveno: Rozšířen pascal syntetizer.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Syntetizer/USyntetizer.pas

    r27 r33  
    2626  TCommand = class(TInterfacedObject, ISyntetizable)
    2727    procedure Syntetize(Syntetizer: TSyntetizer); virtual;
    28   end;
    29 
    30   TProcedureParameter = class(TElement)
    31     Value: string;
    32   end;
    33 
    34   { TProcedureCall }
    35 
    36   TProcedureCall = class(TCommand)
    37     Name: string;
    38     Parameters: TList; // TList<TProcedureParameter>
    39     constructor Create;
    40     destructor Destroy; override;
    41     procedure Syntetize(Syntetizer: TSyntetizer); override;
    4228  end;
    4329
     
    5642  end;
    5743
    58   { TVariableSection }
    59 
    6044  TVariableSection = class(TInterfacedObject, ISyntetizable)
    6145    Variables: TList; // TList<TVariableDeclaration>
     
    6549  end;
    6650
     51  TProcedure = class(TInterfacedObject, ISyntetizable)
     52    Name: string;
     53    Parameters: TList;
     54    Code: TBeginEnd;
     55    constructor Create;
     56    destructor Destroy; override;
     57    procedure Syntetize(Syntetizer: TSyntetizer);
     58  end;
     59
     60  TProcedureList = class(TInterfacedObject, ISyntetizable)
     61    Procedures: TList; // TList<TProcedure>
     62    procedure Syntetize(Syntetizer: TSyntetizer);
     63    constructor Create;
     64    destructor Destroy; override;
     65  end;
     66
     67  TProcedureParameter = class(TInterfacedObject)
     68    Name: string;
     69    VarType: string;
     70  end;
     71
     72  TProcedureParameterValue = class(TInterfacedObject)
     73    Value: string;
     74  end;
     75
     76  TProcedureCall = class(TCommand)
     77    Name: string;
     78    Parameters: TList; // TList<TProcedureParameter>
     79    constructor Create;
     80    destructor Destroy; override;
     81    procedure Syntetize(Syntetizer: TSyntetizer); override;
     82  end;
     83
    6784  TProgram = class(TInterfacedObject, ISyntetizable)
    6885    Name: string;
    6986    Code: TBeginend;
    7087    CompilerDirectives: TList; // TList<TCompilerDirective>
     88    Procedures: TProcedureList; // TList<TProcedure>
    7189    Variables: TVariableSection;
    7290    procedure Syntetize(Syntetizer: TSyntetizer);
     
    7492    destructor Destroy; override;
    7593  end;
    76 
    77   { TSyntetizer }
    7894
    7995  TSyntetizer = class
     
    126142begin
    127143  Syntetizer.AddLine('program ' + Name + ';');
     144  Syntetizer.AddLine('');
    128145  for I := 0 to CompilerDirectives.Count - 1 do
    129146    TCompilerDirective(CompilerDirectives[I]).Syntetize(Syntetizer);
     147  Syntetizer.AddLine('');
     148  Procedures.Syntetize(Syntetizer);
    130149  Variables.Syntetize(Syntetizer);
    131150  Code.Syntetize(Syntetizer);
     
    137156  CompilerDirectives := TList.Create;
    138157  Variables := TVariableSection.Create;
     158  Procedures := TProcedureList.Create;
    139159  Code := TBeginEnd.Create;
    140160  Code.LastEnd := True;
     
    145165  I: Integer;
    146166begin
     167  Procedures.Destroy;
    147168  Variables.Destroy;
    148169  for I := 0 to CompilerDirectives.Count - 1 do
     
    207228begin
    208229  for I := 0 to Parameters.Count - 1 do
    209     ParameterString := ParameterString + TProcedureParameter(Parameters[I]).Value;
     230    ParameterString := ParameterString + TProcedureParameterValue(Parameters[I]).Value;
    210231  if Parameters.Count > 0 then
    211232    ParameterString := '(' + ParameterString + ')';
     
    264285end;
    265286
     287{ TProcedure }
     288
     289constructor TProcedure.Create;
     290begin
     291  Parameters := TList.Create;
     292  Code := TBeginEnd.Create;
     293end;
     294
     295destructor TProcedure.Destroy;
     296var
     297  I: Integer;
     298begin
     299  Code.Destroy;
     300  //for I := 0 to Parameters.Count - 1 do
     301  //  TParameter(Parameters[I]).Destroy;
     302  Parameters.Destroy;
     303  inherited Destroy;
     304end;
     305
     306procedure TProcedure.Syntetize(Syntetizer: TSyntetizer);
     307var
     308  I: Integer;
     309  ParameterString: string;
     310begin
     311  with Syntetizer do begin
     312    for I := 0 to Parameters.Count - 1 do
     313    with TProcedureParameter(Parameters[I]) do begin
     314      ParameterString := ParameterString + Name + ': ' + VarType;
     315
     316    end;
     317    if Parameters.Count > 0 then
     318      ParameterString := '(' + ParameterString + ')';
     319    AddLine('procedure ' + Name + ParameterString + ';');
     320    Code.Syntetize(Syntetizer);
     321    AddLine('');
     322  end;
     323end;
     324
     325{ TProcedureList }
     326
     327procedure TProcedureList.Syntetize(Syntetizer: TSyntetizer);
     328var
     329  I: Integer;
     330begin
     331  for I := 0 to Procedures.Count - 1 do
     332    TProcedure(Procedures[I]).Syntetize(Syntetizer);
     333end;
     334
     335constructor TProcedureList.Create;
     336begin
     337  Procedures := TList.Create;
     338end;
     339
     340destructor TProcedureList.Destroy;
     341var
     342  I: Integer;
     343begin
     344  for I := 0 to Procedures.Count - 1 do
     345    TProcedure(Procedures[I]).Destroy;
     346  Procedures.Destroy;
     347  inherited Destroy;
     348end;
     349
    266350end.
    267351
Note: See TracChangeset for help on using the changeset viewer.