Ignore:
Timestamp:
Jan 17, 2018, 2:25:45 PM (7 years ago)
Author:
chronos
Message:
  • Modified: ParseBeginEnd method split to several other items for parsing each specific command.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/easy compiler/USourceExecutor.pas

    r145 r146  
    3131    FOnOutput: TOutputEvent;
    3232    Variables: TExecutorVariables;
    33     procedure ExecuteBeginEnd(BeginEnd: TSourceBeginEnd);
     33    procedure ExecuteBeginEnd(BeginEnd: TCommandBeginEnd);
    3434  public
    3535    constructor Create;
     
    8484end;
    8585
    86 procedure TSourceExecutor.ExecuteBeginEnd(BeginEnd: TSourceBeginEnd);
     86procedure TSourceExecutor.ExecuteBeginEnd(BeginEnd: TCommandBeginEnd);
    8787var
    8888  IP: Integer;
    89   Instruction: TSourceInstruction;
     89  Instruction: TSourceCommand;
    9090  Variable: TSourceVariable;
    9191  Value: TSourceValue;
     
    9393  Text: string;
    9494  IntValue: Integer;
     95  SkipNext: Boolean;
    9596
    9697function ReadValueReference(Reference: TSourceReference): TSourceValue;
     
    114115
    115116begin
     117  SkipNext := False;
    116118  IP := 0;
    117119  while IP < BeginEnd.Instructions.Count do begin
    118     Instruction := TSourceInstruction(BeginEnd.Instructions[IP]);
    119     if Instruction is TSourceFunctionCall then
    120     with TSourceFunctionCall(Instruction) do begin
     120    if SkipNext then begin
     121      SkipNext := False;
     122      Inc(IP);
     123      Continue;
     124    end;
     125    Instruction := TSourceCommand(BeginEnd.Instructions[IP]);
     126    if Instruction is TCommandFunctionCall then
     127    with TCommandFunctionCall(Instruction) do begin
    121128      if Name = 'print' then begin
    122129        if Assigned(FOnOutput) then begin
     
    178185        else raise Exception.Create('Wrong type for increment');
    179186      end else
    180       raise Exception.Create('Unsupported function: ' + TSourceFunctionCall(Instruction).Name);
     187      raise Exception.Create('Unsupported function: ' + TCommandFunctionCall(Instruction).Name);
    181188    end else
    182     if Instruction is TSourceBeginEnd then begin
    183       ExecuteBeginEnd(TSourceBeginEnd(Instruction));
     189    if Instruction is TCommandBeginEnd then begin
     190      ExecuteBeginEnd(TCommandBeginEnd(Instruction));
     191    end else
     192    if Instruction is TCommandIfZero then begin
     193      ExecutorVar := Variables.Search(TCommandIfZero(Instruction).Variable);
     194      if Assigned(ExecutorVar) then begin
     195        if ExecutorVar.Variable.ValueType.Name = 'Integer' then begin
     196          if TSourceValueInteger(ExecutorVar.Value).Value = 0 then SkipNext := True;
     197        end else
     198        raise Exception.Create('Can compare only integers');
     199      end else
     200      raise Exception.Create('Variable not found');
    184201    end else
    185202    raise Exception.Create('Unsupported instruction');
Note: See TracChangeset for help on using the changeset viewer.