Class Interpreter

java.lang.Object
com.maroontress.intexpr.impl.Interpreter

public final class Interpreter extends Object
A tiny interpreter that is an implementation of a stack machine, retrieves instructions from an iterator, and executes them.

Each instruction has a specific operation to the stack, so performing it involves interaction with the stack. When the iterator gets empty, the interpreter stops and provides the remaining values at the top of the stack as the final solution.

  • Method Details

    • run

      public static int run(int stackSize, Iterable<Instruction> all)
      Executes the instructions retrieved from the specified iterator with the stack that has the specified size and returns the result value.
      Parameters:
      stackSize - The size of stack.
      all - All the instructions in Reverse Polish notation.
      Returns:
      The result value.