Ignore:
Timestamp:
Apr 20, 2020, 11:31:59 PM (4 years ago)
Author:
chronos
Message:
  • Added: Optimizer class for implementation of various optimizations on AST.
  • Added: Transformation of repeat-until loop to while-do loop.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/interpreter2/UGeneratorPascal.pas

    r205 r207  
    2929    procedure GenerateExpressionOperation(Block: TBlock; Expression: TExpressionOperation);
    3030    procedure GenerateExpressionOperand(Block: TBlock; Expression: TExpressionOperand);
     31    procedure GenerateBreak(Block: TBlock; BreakCmd: TBreak);
     32    procedure GenerateContinue(Block: TBlock; ContinueCmd: TContinue);
    3133    procedure GenerateValue(Value: TValue);
    3234  public
     
    4850  else if Command is TRepeatUntil then GenerateRepeatUntil(Block, TRepeatUntil(Command))
    4951  else if Command is TForToDo then GenerateForToDo(Block, TForToDo(Command))
     52  else if Command is TBreak then GenerateBreak(Block, TBreak(Command))
     53  else if Command is TContinue then GenerateContinue(Block, TContinue(Command))
     54  else if Command is TEmptyCommand then
    5055  else raise Exception.Create('Unsupported command type');
    5156end;
     
    5762  AddText(' then ');
    5863  GenerateCommand(Block, IfThenElse.CommandThen);
    59   if Assigned(IfThenElse.CommandElse) then begin
     64  if Assigned(IfThenElse.CommandElse) and not (IfThenElse.CommandElse is TEmptyCommand) then begin
    6065    AddText(' else ');
    6166    GenerateCommand(Block, IfThenElse.CommandElse);
     
    158163    else raise Exception.Create('Unsupported exception operand type.');
    159164  end;
     165end;
     166
     167procedure TGeneratorPascal.GenerateBreak(Block: TBlock; BreakCmd: TBreak);
     168begin
     169  AddText('break');
     170end;
     171
     172procedure TGeneratorPascal.GenerateContinue(Block: TBlock;
     173  ContinueCmd: TContinue);
     174begin
     175  AddText('continue');
    160176end;
    161177
Note: See TracChangeset for help on using the changeset viewer.