Web4College

Infix to Postfix Converter

Convert an infix expression to postfix notation and follow each conversion step.

Expression converter

Examples:
A B C * +

Visualization

Watch this interactive visualization convert your infix expression to postfix step by step. Follow how it reads tokens from left to right, sends operands to output and moves operators through a stack using precedence and associativity. Play, pause or step forward and backward to inspect each change.

Infix to postfix · Stack method
Space plays or pauses. Arrow keys step. Ctrl plus arrows changes chapter. Shift plus greater or less changes speed. Escape releases focus.
InfixA+B*CStackPostfixA+B*C

Step-by-Step Conversion · Stack Method

Read from left to right. Send operands to output and keep operators on a stack. Pop higher-precedence operators first; on equal precedence, + − * / pop while ^ waits. Parentheses control grouping. Finally, empty the stack.

  1. Read infix from left to right

    A + B * C

  2. Build postfix using an operator stack

    A B C

  3. Empty the stack to finish postfix

    A B C * +

Conversion methods

Three common ways to convert infix to postfix.

  1. Stack method (shunting yard)

    Used here

    Read left to right, send operands to output and use an operator stack to apply precedence, associativity and parentheses.

  2. Expression tree

    Build a tree, then visit the left operand, right operand and operator in postorder to produce postfix.

  3. Recursive parsing

    Parse nested expressions by precedence, appending each operator after the postfix expressions of its operands.

Important terms to revise

Infix

The operator sits between its operands.

Example

A + B puts the operator between A and B.

Postfix

The operator comes after its operands.

Example

A B + means add A and B.

Operator

A symbol that specifies an operation.

Example

+ adds; * multiplies.

Operand

A value or variable an operator acts on.

Example

In A + 5, A and 5 are operands.

Precedence

Which operator binds more tightly.

Example

In A + B * C, multiply B and C first.

Associativity

How equal-priority operators group.

Example

A - B - C groups as (A - B) - C.

Stack

Stores items in last-in, first-out order.

Example

Push +, then *; pop * first.