Postfix quiz

Practice converting an expression into standard postfix one step at a time using an operator stack. Every move is checked live, and the final result matches what parse() outputs.

How it works
  • Operands (numbers and variables) go straight to the output. A minus attached to a number stays part of it (-5 is one operand), unless a power or subscript follows (-2^2 means −(2²), so that minus is neg).
  • Operators pop anything on the stack with higher or equal precedence, then get pushed. Because ^ is right-associative, it only pops strictly higher precedence.
  • Unary minus (neg) is a prefix operator — push it without popping anything.
  • Functions and opening brackets go on the stack. A closing bracket pops until its matching opener, then discards the opener; a function stays on the stack until something of lower precedence comes along.
  • Variadic functions (max, min, sum, prod, gcd, mean) include their argument count when written (a b 2 max). A comma pops back to the bracket and counts an argument, without going to the output.
  • When there are no tokens left, pop everything remaining on the stack.
  • Implicit multiplication becomes * (2x, 2(x+1)), and <= >= != == become ≤ ≥ ≠ =. Use brackets for functions like sin(x).

Precedence from low to high:

Shortcuts: O output · S stack · P pop · D discard · N next · Z undo · H hint · R reveal next move. The expression is saved in the URL so you can share it.

Infix

Postfix output

Stack (top first)

Steps

TokenPostfix afterStack after (top first)