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 prefix notation, the operator appears first: + A B. Prefix expressions do
not require parentheses because the evaluation order is encoded by token order.
Enter an expression and click Convert.
| # | Token | Type | Status |
|---|
tokens = tokenize(infix)
postfix = shuntingYard(tokens)
prefixStack = empty stack
for token in postfix:
if token is an operand:
prefixStack.push(token)
else:
right = prefixStack.pop()
left = prefixStack.pop()
prefixStack.push(operator + left + right)
prefix = prefixStack.pop()
Exponentiation has higher precedence than multiplication and division, which have higher precedence than addition and subtraction.
Exponentiation is right-associative, so A ^ B ^ C means
A ^ (B ^ C). The converter preserves this rule.
Multi-character operands such as value1, total, and
123 are treated as single tokens instead of separate characters.
The converter rejects mismatched parentheses, missing operands, adjacent operands, and unsupported characters before starting the visualization.
| Operator | Precedence | Associativity |
|---|---|---|
| Unary +, unary − | 4 | Right |
| ^ | 3 | Right |
| *, /, % | 2 | Left |
| +, − | 1 | Left |