If the token is an operator, pop two numbers off the stack, combine them using the operator, and push the result onto the stack. After processing the last token, the single value remaining on the stack is the value of the expression. Note that we assumed in step 2 that the operators are binary operators. Were an operator unary , we would pop only one number off the stack, apply the operator, and then push the result onto the stack. Instead, we use parentheses and precedence rules to indicate the order in which they should be done.
Exponentiation has the highest precedence.
Perform exponentiations in order first, from left to right. Multiplication and division have the next-highest precedence. After performing all exponentiations, perform multiplications and divisions in order, from left to right. Addition and subtraction have the lowest precedence. After performing all multiplications and divisions, perform additions and subtractions in order, from left to right.