Shunting-Yard Animation

· Source ↗

TLDR

  • Interactive animation of Dijkstra’s shunting-yard algorithm converting infix expressions to postfix (RPN) using a stack and operator precedence rules.

Key Takeaways

  • Numbers and variables go directly to output; operators are held on a stack and flushed by precedence and associativity rules.
  • Left-associative operators trigger early stack flushing when equal-precedence operators follow, preserving correct evaluation order.
  • Parentheses are used only for grouping: left bracket pushed to stack, right bracket triggers flush, then both are discarded.
  • Remaining operators on the stack are pushed to output after input is exhausted.

Hacker News Comment Review

  • Commenters flagged a display bug: multi-digit or adjacent operands like 100+88/4 produce ambiguous RPN output (100884+/) with no delimiter between operands.
  • One commenter raised a deeper theoretical angle: the animation discards parenthesis tokens, which breaks the model for reversible computing where information cannot be destroyed.

Original | Discuss on HN