Shunting-Yard Animation
s1291
62 points
16 comments
May 10, 2026
Related Discussions
Found 5 related stories in 89.0ms across 8,303 title embeddings via pgvector HNSW
- Whimsical Animations Course Open House SpyCoder77 · 84 pts · May 01, 2026 · 45% similar
- A Day in the Life of an Enshittificator [video] leephillips · 11 pts · March 01, 2026 · 42% similar
- A Day in the Life of an Enshittificator [video] doener · 11 pts · March 01, 2026 · 42% similar
- Switchlab.dev – Learn switching and routing through interactive labs salad_v · 14 pts · May 14, 2026 · 42% similar
- A sea of sparks: Seeing radioactivity maurycyz · 59 pts · March 30, 2026 · 41% similar
Discussion Highlights (8 comments)
IIAOPSW
Hold up. you can't just have the train take the parenthesis off screen and hand wave away what happens to those cars. What happens when your forced to keep the garbage of a computation because you can't delete anything? ( https://en.wikipedia.org/wiki/Reversible_computing )
dcrazy
I typed `100+88/4` and the resulting output was `100884+/`. Should the algorithm be inserting a symbol to delineate operands?
alter_igel
I'm not familiar with the algorithm and I don't see much explanation on the site (at least on mobile) but AFAICT this is turning parenthesized infix expressions into reverse Polish notation. In other words, it takes human-readable mathematical formulas and converts them into something a simple stack-based machine can compute in one forward pass. It also appears that separate digits aren't interpreted as decimal numerals (i.e. (1)(3) is the sequence 1,3 and not 13) which can look a bit misleading.
abd-nh
I made a basic demo of this years go: https://abdnh.github.io/shunting-yard-algorithm-demo/
pimlottc
I can’t figure out how to make it start processing the input on mobile Safari, am I missing something?
rembicilious
If I start the train and then type a nested bracket expression like 2+(2-(3/5)) the train jumps the track
talkingtab
This is great! As a kid I used to love HO scale model trains. There is an old movie of me on my birthday looking at my train set with eyes as big as plates. Fast forward, and I love networking and programming. I recognized that networking is just trains on Ethernet or Wifi, but now realize even the programming is just the same. Still making things go places and go around after all this time.
timhh
Note the shunting yard algorithm is an iterative (as opposed to recursive) version of Pratt parsing (and also precedence climbing which is virtually identical). However as normally stated it does not do proper error checking - it will accept totally invalid input. That isn't a fundamental limit of the algorithm though; you can easily add error checking, as I did here: https://github.com/Timmmm/expr/blob/1b0aef8f91460974d526b5ba... I'm not really sure why this is omitted.