Ignore:
Timestamp:
Apr 20, 2020, 11:31:59 PM (5 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/UParser.pas

    r205 r207  
    3434    function ParseRepeatUntil(Block: TBlock; out RepeatUntil: TRepeatUntil): Boolean;
    3535    function ParseForToDo(Block: TBlock; out ForToDo: TForToDo): Boolean;
     36    function ParseBreak(Block: TBlock; out BreakCmd: TBreak): Boolean;
     37    function ParseContinue(Block: TBlock; out ContinueCmd: TContinue): Boolean;
    3638    procedure TokenizerError(Pos: TPoint; Text: string);
    3739    procedure InitSystemBlock(Block: TBlock);
     
    121123  ForToDo: TForToDo;
    122124  RepeatUntil: TRepeatUntil;
     125  BreakCmd: TBreak;
     126  ContinueCmd: TContinue;
    123127begin
    124128  if ParseIfThenElse(Block, IfThenElse) then begin
     
    149153    Result := True;
    150154    Command := Assignment;
    151   end else Result := False;
     155  end else
     156  if ParseBreak(Block, BreakCmd) then begin
     157    Result := True;
     158    Command := BreakCmd;
     159  end else
     160  if ParseContinue(Block, ContinueCmd) then begin
     161    Result := True;
     162    Command := ContinueCmd;
     163  end else
     164    Result := False;
    152165end;
    153166
     
    563576end;
    564577
     578function TParser.ParseBreak(Block: TBlock; out BreakCmd: TBreak): Boolean;
     579begin
     580  Result := False;
     581  if Tokenizer.CheckNext('break', tkKeyword) then begin
     582    Tokenizer.Expect('break', tkKeyword);
     583    Result := True;
     584    BreakCmd := TBreak.Create;
     585  end;
     586end;
     587
     588function TParser.ParseContinue(Block: TBlock; out ContinueCmd: TContinue
     589  ): Boolean;
     590begin
     591  Result := False;
     592  if Tokenizer.CheckNext('continue', tkKeyword) then begin
     593    Tokenizer.Expect('continue', tkKeyword);
     594    Result := True;
     595    ContinueCmd := TContinue.Create;
     596  end;
     597end;
     598
    565599procedure TParser.TokenizerError(Pos: TPoint; Text: string);
    566600begin
Note: See TracChangeset for help on using the changeset viewer.