java.lang.Object
com.maroontress.intexpr.impl.Interpreter
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 Summary
Modifier and TypeMethodDescriptionstatic 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.
-
Method Details
-
run
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.
-