Ignore:
Timestamp:
Apr 22, 2020, 9:00:02 AM (4 years ago)
Author:
chronos
Message:
  • Added: Executor support for Break and Continue statements.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/interpreter2/UParser.pas

    r207 r211  
    6363    while not Tokenizer.CheckNext('end', tkKeyword) do begin
    6464      if ParseCommand(Block, Command) then begin
     65        Command.Parent := BeginEnd;
    6566        BeginEnd.Commands.Add(Command);
    6667        Tokenizer.Expect(';', tkSpecialSymbol);
     
    185186    Prog.Block.Free;
    186187    Prog.Block := Block;
     188    Block.Parent := Prog;
    187189    Tokenizer.Expect('.', tkSpecialSymbol);
    188190  end else begin
     
    198200  Result := False;
    199201  Block := TBlock.Create;
    200   Block.Parent := ParentBlock;
     202  Block.ParentBlock := ParentBlock;
    201203  ParseBlockVar(Block);
    202204  ParseBlockConst(Block);
     
    205207    Block.BeginEnd.Free;
    206208    Block.BeginEnd := BeginEnd;
     209    BeginEnd.Parent := Block;
    207210  end else Block.Free;
    208211end;
     
    293296  Variable: TVariable;
    294297  Expression: TExpression;
    295 begin
     298  LastPos: TTokenizerPos;
     299begin
     300  LastPos := Tokenizer.Pos;
    296301  Result := False;
    297302  Token := Tokenizer.GetNext;
    298303  if Token.Kind = tkIdentifier then begin
    299     Result := True;
    300304    Variable := Block.GetVariable(Token.Text);
    301305    if Assigned(Variable) then begin
     
    308312          Assignment.Expression.Free;
    309313          Assignment.Expression := Expression;
     314          Expression.Parent := Assignment;
    310315        end else begin
    311316          Result := False;
     
    316321    end else Error('Variable ' + Token.Text + ' not defined.');
    317322  end;
     323  if not Result then Tokenizer.Pos := LastPos;
    318324end;
    319325
     
    481487        IfThenElse.CommandThen.Free;
    482488        IfThenElse.CommandThen := Command;
     489        Command.Parent := IfThenElse;
    483490        if Tokenizer.CheckNext('else', tkKeyword) then begin
    484491          Tokenizer.Expect('else', tkKeyword);
     
    486493            IfThenElse.CommandElse.Free;
    487494            IfThenElse.CommandElse := Command;
     495            Command.Parent := IfThenElse;
    488496          end else Error('Expected command');
    489497        end;
     
    510518        WhileDo.Command.Free;
    511519        WhileDo.Command := Command;
     520        Command.Parent := WhileDo;
    512521      end else Error('Expected command');
    513522    end else Error('Expected expression');
     
    529538      if ParseCommand(Block, Command) then begin
    530539        RepeatUntil.Commands.Add(Command);
     540        Command.Parent := RepeatUntil;
    531541        Tokenizer.Expect(';', tkSpecialSymbol);
    532542      end else begin
     
    569579            ForToDo.Command.Free;
    570580            ForToDo.Command := Command;
     581            Command.Parent := ForToDo;
    571582          end else Error('Expected command.');
    572583        end else Error('Expected expression.');
Note: See TracChangeset for help on using the changeset viewer.