# Michelson Logic understanding problem

If i got it right, Michelson is a stack based language.

3 4 5 * + = 23

how does Michelson know, that it has to mutiplicate 4 * 5 before adding 3?

Just to explain how i think:

The multiplicator comes first so i would think: 3*4+5 = 17

Why is that wrong?

• I tend to think this question is less a Tezos/Michelson specific question and more a general question about postfix notation and stack evaluation ?
– Ezy
Jan 31 '19 at 13:16

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)
, 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 +)

``````

So the result of your computation is `23`.

'*' and '+', in this context, are not the infix operators you are used to. Imagine reading left to right and stacking up the numbers as you go. When you encounter + or * you replace the top two elements of the stack with the result of the operation.