Changeset 205 for branches/interpreter2/UParser.pas
- Timestamp:
- Apr 20, 2020, 1:10:44 AM (5 years ago)
- Location:
- branches/interpreter2
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/interpreter2
- Property svn:ignore
-
old new 4 4 interpreter.res 5 5 heaptrclog.trc 6 Generated
-
- Property svn:ignore
-
branches/interpreter2/UParser.pas
r204 r205 32 32 function ParseIfThenElse(Block: TBlock; out IfThenElse: TIfThenElse): Boolean; 33 33 function ParseWhileDo(Block: TBlock; out WhileDo: TWhileDo): Boolean; 34 function ParseRepeatUntil(Block: TBlock; out RepeatUntil: TRepeatUntil): Boolean; 34 35 function ParseForToDo(Block: TBlock; out ForToDo: TForToDo): Boolean; 35 36 procedure TokenizerError(Pos: TPoint; Text: string); … … 55 56 begin 56 57 if Tokenizer.CheckNext('begin', tkKeyword) then begin 58 Tokenizer.Expect('begin', tkKeyword); 57 59 BeginEnd := TBeginEnd.Create; 58 60 Result := True; 59 Tokenizer.Expect('begin', tkKeyword);60 61 while not Tokenizer.CheckNext('end', tkKeyword) do begin 61 62 if ParseCommand(Block, Command) then begin … … 119 120 WhileDo: TWhileDo; 120 121 ForToDo: TForToDo; 122 RepeatUntil: TRepeatUntil; 121 123 begin 122 124 if ParseIfThenElse(Block, IfThenElse) then begin … … 139 141 Result := True; 140 142 Command := FunctionCall; 143 end else 144 if ParseRepeatUntil(Block, RepeatUntil) then begin 145 Result := True; 146 Command := RepeatUntil; 141 147 end else 142 148 if ParseAssignment(Block, Assignment) then begin … … 496 502 end; 497 503 504 function TParser.ParseRepeatUntil(Block: TBlock; out RepeatUntil: TRepeatUntil 505 ): Boolean; 506 var 507 Expression: TExpression; 508 Command: TCommand; 509 begin 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; 531 end; 532 498 533 function TParser.ParseForToDo(Block: TBlock; out ForToDo: TForToDo): Boolean; 499 534 var
Note:
See TracChangeset
for help on using the changeset viewer.