Writing the world's worst parser generator
This title could be clearer and more informative.Try out Clickbait Shieldfor free (5 uses left this month).
A live coding session building a rudimentary parser generator in Zig from scratch. The author is motivated by the tedium of hand-rolling parsers for an HTTP-like SIP protocol (specifically parsing 'Via' headers defined in ABNF/BNF). The approach: define a simple intermediate representation of BNF rules, then generate Zig source code (structs, parse functions, unions) from that IR. The session covers designing the IR for single characters, character ranges, rule references, sequences, and 'one-of' alternatives, implementing a low-level parser with buffer indexing, generating typed structs and parse functions, bootstrapping the BNF parser using its own output, and iteratively fixing compilation errors. The author explicitly avoids bottom-up parsing complexity and metaprogramming in favor of straightforward code generation.
Sort: