flâneur — a map of the web's best reading

Blog Posts – Naming Things

blog.bruce-hill.com · 272 words · saved by 1 readers

Packrat parsing is a relatively new approach to parsing code introduced by Bryan Ford in his 2002 Master’s thesis. Packrat parsers are capable of very efficiently parsing a class of grammars called Parsing Expression Grammars (PEGs). I covered PEGs in more depth in my previous post, PEGs and the Structure of Languages, so if you’re new to the topic, I recommend you begin there. The packrat parser is based on earlier work on recursive descent parsers, dating back to the 70s, but focused specifically on Parsing Expression Grammars. In this post, I’ll attempt to demystify packrat parsers by walking through a complete packrat parser implementation that fits in a few dozen lines of Javascript code.

In programming, there are a lot of benefits to using immutable values, but the benefits are unrelated to whether variables can be reassigned. Immutable values are a type of data that are guaranteed to never change (as opposed to mutable data, which can change). Using immutable values helps you: Safely store values in a cache so the same value can be reused later. Use trees or lists with shared subcomponents. Preserve invariants in datastructures like hash tables. Store unchanging historical records like undo logs. Share data between threads safely without synchronization primitives. In essence

Explore this link on the map →

related reading