import java.util.Stack;

public class Kellermaschine {
	Stack<Integer> keller = new Stack<Integer>();
	int pc = 0;
	Instruction[] prog;

	public Kellermaschine(Instruction[] prog) {
		super();
		this.prog = prog;
		System.out.println("Start "+prog.length);
	}

	void step() {
		System.out.println(" "+pc+" "+prog[pc]+" "+keller);
		Instruction instr = prog[pc];
		instr.execute(this);
	}

	void run() {
		while (!end()) {
			step();
		}
		System.out.println(keller.pop());
	}

	boolean end() {
		return prog[pc] instanceof End;
	}

}
