We can simulate the program in the following way.
We write the stack between [...]
and then the operations.
We use three different operations push <int>
, *
and +
.
push
puts an integer at the top of the stack, *
pops two elements from the stack and pushes their product, and +
pops two elements from the stack and pushes their sum.
Your program starts with an empty stack []
and some operations:
[], push 3, push 4, push 5, *, +
-> (evaluation of push 3)
[3], push 4, push 5, *, +
-> (evaluation of push 4)
[3, 4], push 5, *, +
-> (evaluation of push 5)
[3, 4, 5], *, +
-> (evaluation of *)
[3, 20], +
-> (evaluation of +)
[23]
So the result of your computation is 23
.