Interpretor Next: External InstructionsUp: MachinesPrevious: RsiMachine

Interpretor

Interpretor  extends RsiMachine and defines two flags next and runInterp. To set next to true forces immediate reaction for the next instant, as soon as current instant is over. To set runInterp to true forces the interpretor to run the program.

The init method initializes the keyboard and the instantPrompt method prompts the current instant number.

At creation, the extern node System is created to be able to printmessages (see section 6.2).

Activation creates a new parser to parse the input and then calls the oneStep method which activates the machine.

The main loop creates an interpretor and activates it for ever.

public class Interpretor extends ExtendedRsiMachine
{
  protected External externalContext = null;
  public External getExternalContext() {return externalContext;}

  protected boolean next = false;
  public void next(){ next = true; }

  protected boolean runInterp = false;
  public void runInterp(){ runInterp = true; }

  public Interpretor()
  { 
    externalContext = new External(this);
    new ExternNode("System",externalContext);
    init();  
    instantPrompt();
  }

  protected void instantPrompt(){
    System.out.print(instant + ": "); System.out.flush();
  }
  ...
  protected byte activation(Machine machine)
  {
      do{
        if (!next) parseEntry();
        oneStep();
      }while (next);
    return STOP;
  }

  protected void oneStep()
  {
    if (next || runInterp){ 
      next = runInterp = false;
      super.activation(this);
      instantPrompt();
    }
  }

  public static void main (String argv[])
  {
    Interpretor interp = new Interpretor();
    while (true){ interp.activation(interp); }
  }
}

We end this section with the next instruction which forces the interpretor to immediately execute the next instant as soon as the current one is over.

Next  is like Nothing but it sets the next flag of the executing machine.

public class Next extends Instruction
{
  final public String toString(){ return "next"; }

  final protected byte activation(Machine machine){ 
     ((Interpretor)machine).next();
     return TERM; 
  }
}