← Back

Infix to Postfix Converter

What is Postfix Notation?

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.

TokenizationO(n)
ConversionO(n)
Auxiliary spaceO(n)
AlgorithmShunting Yard

Expression and playback controls

500 ms

Step-by-step process

Click Convert to validate and prepare the expression.
Postfix output

Enter an expression and click Convert.

Current token
Operators popped0
Progress0 / 0
ComplexityO(n)

Token table

# Token Type Status

Shunting Yard algorithm

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

Important concepts

Operator precedence

Exponentiation has higher precedence than multiplication and division, which have higher precedence than addition and subtraction.

Associativity

Exponentiation is right-associative. Therefore, A ^ B ^ C becomes A B C ^ ^, representing A ^ (B ^ C).

Tokenization

Identifiers such as value1, names such as total, and numbers such as 123 are treated as complete tokens rather than separate characters.

Validation

The converter rejects mismatched parentheses, missing operands, adjacent operands, unsupported characters, and incomplete expressions before playback begins.

Operator rules

Operator Precedence Associativity
Unary +, unary −4Right
^3Right
*, /, %2Left
+, −1Left