Ignore:
Timestamp:
Apr 20, 2020, 1:10:44 AM (5 years ago)
Author:
chronos
Message:
  • Added: Support for repeat-until.
Location:
branches/interpreter2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/interpreter2

    • Property svn:ignore
      •  

        old new  
        44interpreter.res
        55heaptrclog.trc
         6Generated
  • branches/interpreter2/UExecutor.pas

    r203 r205  
    102102    procedure ExecuteIfThenElse(Block: TExecutorBlock; IfThenElse: TIfThenElse);
    103103    procedure ExecuteWhileDo(Block: TExecutorBlock; WhileDo: TWhileDo);
     104    procedure ExecuteRepeatUntil(Block: TExecutorBlock; RepeatUntil: TRepeatUntil);
    104105    procedure ExecuteForToDo(Block: TExecutorBlock; ForToDo: TForToDo);
    105106    procedure ExecuteBlock(ParentBlock: TExecutorBlock; Block: TBlock);
     
    432433  else if Command is TIfThenElse then ExecuteIfThenElse(Block, TIfThenElse(Command))
    433434  else if Command is TWhileDo then ExecuteWhileDo(Block, TWhileDo(Command))
     435  else if Command is TRepeatUntil then ExecuteRepeatUntil(Block, TRepeatUntil(Command))
    434436  else if Command is TForToDo then ExecuteForToDo(Block, TForToDo(Command))
    435437  else raise Exception.Create('Unsupported command type');
     
    458460      if not TValueBoolean(Value).Value then Break;
    459461      ExecuteCommand(Block, WhileDo.Command);
     462    end else raise Exception.Create('Expected boolean value.');
     463    Value.Free;
     464  end;
     465end;
     466
     467procedure TExecutor.ExecuteRepeatUntil(Block: TExecutorBlock;
     468  RepeatUntil: TRepeatUntil);
     469var
     470  Value: TValue;
     471  I: Integer;
     472begin
     473  while True do begin
     474    for I := 0 to RepeatUntil.Commands.Count - 1 do
     475      ExecuteCommand(Block, TCommand(RepeatUntil.Commands[I]));
     476    Value := ExecuteExpression(Block, RepeatUntil.Expression);
     477    if Value is TValueBoolean then begin
     478      if TValueBoolean(Value).Value then Break;
    460479    end else raise Exception.Create('Expected boolean value.');
    461480    Value.Free;
Note: See TracChangeset for help on using the changeset viewer.