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/UParser.pas

    r204 r205  
    3232    function ParseIfThenElse(Block: TBlock; out IfThenElse: TIfThenElse): Boolean;
    3333    function ParseWhileDo(Block: TBlock; out WhileDo: TWhileDo): Boolean;
     34    function ParseRepeatUntil(Block: TBlock; out RepeatUntil: TRepeatUntil): Boolean;
    3435    function ParseForToDo(Block: TBlock; out ForToDo: TForToDo): Boolean;
    3536    procedure TokenizerError(Pos: TPoint; Text: string);
     
    5556begin
    5657  if Tokenizer.CheckNext('begin', tkKeyword) then begin
     58    Tokenizer.Expect('begin', tkKeyword);
    5759    BeginEnd := TBeginEnd.Create;
    5860    Result := True;
    59     Tokenizer.Expect('begin', tkKeyword);
    6061    while not Tokenizer.CheckNext('end', tkKeyword) do begin
    6162      if ParseCommand(Block, Command) then begin
     
    119120  WhileDo: TWhileDo;
    120121  ForToDo: TForToDo;
     122  RepeatUntil: TRepeatUntil;
    121123begin
    122124  if ParseIfThenElse(Block, IfThenElse) then begin
     
    139141    Result := True;
    140142    Command := FunctionCall;
     143  end else
     144  if ParseRepeatUntil(Block, RepeatUntil) then begin
     145    Result := True;
     146    Command := RepeatUntil;
    141147  end else
    142148  if ParseAssignment(Block, Assignment) then begin
     
    496502end;
    497503
     504function TParser.ParseRepeatUntil(Block: TBlock; out RepeatUntil: TRepeatUntil
     505  ): Boolean;
     506var
     507  Expression: TExpression;
     508  Command: TCommand;
     509begin
     510  Result := False;
     511  if Tokenizer.CheckNext('repeat', tkKeyword) then begin
     512    Tokenizer.Expect('repeat', tkKeyword);
     513    RepeatUntil := TRepeatUntil.Create;
     514    Result := True;
     515    while not Tokenizer.CheckNext('until', tkKeyword) do begin
     516      if ParseCommand(Block, Command) then begin
     517        RepeatUntil.Commands.Add(Command);
     518        Tokenizer.Expect(';', tkSpecialSymbol);
     519      end else begin
     520        Error('Unexpected token ' + Tokenizer.GetNext.Text);
     521        Result := False;
     522        Break;
     523      end;
     524    end;
     525    Tokenizer.Expect('until', tkKeyword);
     526    if ParseExpression(Block, Expression) then begin
     527      RepeatUntil.Expression.Free;
     528      RepeatUntil.Expression := Expression;
     529    end else Error('Expected expression');
     530  end else Result := False;
     531end;
     532
    498533function TParser.ParseForToDo(Block: TBlock; out ForToDo: TForToDo): Boolean;
    499534var
Note: See TracChangeset for help on using the changeset viewer.