A walkthrough of building a self-hosting parser for a new systems programming language, covering three generations of parsers: a yacc/lex prototype, a hand-written C recursive descent parser, and finally the self-hosted version written in the language itself. The post details the lexer design (tokenization, lookahead, keyword detection via binary search), parser helper functions (want/try/peek), AST construction for bindings, and operator precedence climbing for binary arithmetic expressions. The parser lives in the standard library to enable language-aware tooling, inspired by Go's approach.
Sort: