Operator precedence
Exponentiation has higher precedence than multiplication and division, which have higher precedence than addition and subtraction.
In infix notation, an operator appears between its operands, such as A + B.
In postfix notation, the operator appears after its operands: A B +.
Postfix expressions can be evaluated with a stack and do not require parentheses.
Enter an expression and click Convert.
| # | Token | Type | Status |
|---|
for each token:
if token is an operand:
append token to output
else if token is an operator:
while stack top should be processed first:
append stack.pop() to output
stack.push(token)
else if token is "(":
stack.push(token)
else if token is ")":
pop operators until "("
discard the matching "("
pop remaining operators to output
Exponentiation has higher precedence than multiplication and division, which have higher precedence than addition and subtraction.
Exponentiation is right-associative. Therefore, A ^ B ^ C becomes
A B C ^ ^, representing A ^ (B ^ C).
Identifiers such as value1, names such as total, and numbers
such as 123 are treated as complete tokens rather than separate characters.
The converter rejects mismatched parentheses, missing operands, adjacent operands, unsupported characters, and incomplete expressions before playback begins.
| Operator | Precedence | Associativity |
|---|---|---|
| Unary +, unary − | 4 | Right |
| ^ | 3 | Right |
| *, /, % | 2 | Left |
| +, − | 1 | Left |