Polish Notation Converter

By: Calculator Grid

Polish Notation Converter

Convert arithmetic expressions among infix, prefix, and postfix notation, or evaluate a numeric Polish-notation expression with a transparent step trace.

Source: Infix Target: Postfix 11 tokens 3 operators

Example ready. The workbook has been validated and can be downloaded.

Expression settings

Conversion preserves symbols. Evaluation requires numeric operands and detects prefix or postfix automatically.

Use spaces between tokens for prefix and postfix input. Infix input may use parentheses.

Accepted operators: +, -, *, /, and ^. Operands may be numbers or letters.

Live result

Postfix expression
3 4 + 7 2 - *
Operands
4
Operators
3
Maximum stack depth
3
Expression status
Valid
Choose a mode and enter a complete expression to see the result.

Conversion or evaluation steps

Step Token Action Output / value stack Operator stack
1 ( Push left parenthesis (
2 3 Send operand to output 3 (
3 + Push operator 3 ( +
4 4 Send operand to output 3 4 ( +
5 ) Pop to matching parenthesis 3 4 +
6 * Push operator 3 4 + *
7 ( Push left parenthesis 3 4 + * (
8 7 Send operand to output 3 4 + 7 * (
9 - Push operator 3 4 + 7 * ( -
10 2 Send operand to output 3 4 + 7 2 * ( -
11 ) Pop to matching parenthesis 3 4 + 7 2 - *
12 End Drain remaining operators 3 4 + 7 2 - *
The step table is generated from the same canonical token model used for the displayed result and Excel workbook.

How to use the Polish notation converter

What this calculator does

This calculator rewrites a binary arithmetic expression between infix notation, prefix notation, and postfix notation. It can also evaluate a numeric prefix or postfix expression. Infix places an operator between operands, as in 3 + 4. Prefix places it first, as in + 3 4. Postfix places it last, as in 3 4 +. The converter supports +, -, *, /, and ^, follows standard precedence, treats exponentiation as right-associative, and checks parentheses and operand counts. It does not process functions, implicit multiplication, factorials, commas, or unary operators applied to grouped expressions.

When to use it

Use the tool when checking homework on expression notation, learning how an operator stack works, preparing examples for a compiler or data-structures class, or translating a formula for a stack-based evaluator. The step table is especially useful for finding the point where an invalid token, unmatched parenthesis, or missing operand breaks the expression.

How to calculate

  1. The calculator opens with a complete demonstration: (3 + 4) * (7 - 2) converted from infix to postfix. Its result and a validated example XLSX are available immediately.
  2. Choose Mode. Select Convert expression to change notation without evaluating variables, or Evaluate prefix or postfix to calculate a numeric result.
  3. In conversion mode, choose Conversion type. Then replace the demonstration in Expression. Prefix and postfix tokens must be separated by spaces.
  4. Read the live result, summary pills, operand and operator counts, maximum stack depth, and the token-by-token table. Use Download Excel to export the current validated model.
  5. Reset clears the demonstration data and result. Download Excel is then disabled until a complete valid expression is entered again.

Input guide

Mode is required and accepts one of two choices. “Convert expression” preserves numeric and symbolic operands; “Evaluate prefix or postfix” requires finite numeric operands. A common mistake is choosing evaluation for an expression containing letters. Conversion type is required in conversion mode. It accepts Infix to prefix, Infix to postfix, Prefix to infix, or Postfix to infix. For example, choose Infix to postfix for (3 + 4) * (7 - 2). Changing this control changes the expected source syntax and the target notation. Expression is required text. Infix input may contain spaces or no spaces and may use parentheses. Prefix and postfix input must separate every operand and operator with spaces, such as + 5 7 or 7 6 *. Decimal numbers and identifiers made of letters, digits, or underscores are accepted for conversion. Scientific notation and implicit forms such as 2x are rejected rather than silently reinterpreted.

Output guide

Primary result is the converted expression or numeric evaluation. It is an exact notation transformation for a valid conversion and a finite arithmetic estimate for evaluation. Source and Target identify the detected or selected notation pair. Token count counts lexical items in the source expression, including infix parentheses. Operands and Operators count the expression tree leaves and binary operations. A valid binary expression always has one more operand than operator. Maximum stack depth is the largest number of simultaneous values needed while processing the postfix form; higher values indicate more intermediate values held at once. Expression status reports Valid only after all syntax and finite-result checks pass. The table columns show the current token, the action taken, the output or value stack, and the operator stack. Empty or invalid input produces a compact empty state instead of stale output.

Worked example

The startup expression is (3 + 4) * (7 - 2). The first parenthesized group becomes 3 4 +; the second becomes 7 2 -. Multiplication is applied after both groups, so the final postfix expression is 3 4 + 7 2 - *. There are 4 operands, 3 operators, and 11 source tokens including parentheses. Evaluating the postfix form would push 3 and 4, replace them with 7, push 7 and 2, replace them with 5, and finally multiply to obtain 35. The largest value-stack size is 3.

Learn more

The shunting-yard algorithm explanation describes how precedence and an operator stack convert infix expressions to postfix. For the stack-evaluation idea and historical context, see Wolfram MathWorld's reverse Polish notation article.

How the notation rules work

Infix notation needs precedence and associativity because the operator sits between its operands. Multiplication and division bind more tightly than addition and subtraction, while exponentiation binds more tightly than both and associates from the right. Parentheses override those defaults. Prefix and postfix move operators to positions that make the grouping explicit, so a parser can reconstruct the same expression tree without parentheses.

Infix: (A + B) * C
Prefix: * + A B C
Postfix: A B + C *

For a postfix evaluation, scan left to right. Push every operand. When an operator appears, pop the right operand, then the left operand, apply the operator, and push the result. Prefix evaluation uses the corresponding right-to-left scan. The University of Texas compiler notes on reverse Polish notation show why the representation is unambiguous and parenthesis-free.

Validation rule: a complete binary expression has exactly one final tree root. Too few operands leaves an operator unable to combine two values; too many operands leaves extra values after the scan.

Common mistakes

  • Writing prefix or postfix tokens without spaces, which makes multi-digit numbers and identifiers ambiguous.
  • Forgetting that subtraction and division are order-sensitive: the first popped postfix value is the right operand.
  • Treating A ^ B ^ C as left-associative. Standard infix parsing reads it as A ^ (B ^ C).
  • Using a symbolic operand in evaluation mode. Conversion accepts variables; numerical evaluation does not.