Writing a C Compiler, in Zig (2025)

· coding · Source ↗

TLDR

  • Author built paella, a C compiler in Zig, following Nora Sandler’s Writing a C Compiler as both a Zig learning exercise and a job-search-avoidance project.

Key Takeaways

  • The project covers 10 chapters: integers, unary/binary ops, logic, variables, conditions, blocks, loops, functions, and linking.
  • Built as a series of live writeups collected at a single index page; chapters were not edited post-hoc except for broken links.
  • The compiler is named paella and lives in a public GitHub repo, making it a readable reference for anyone learning Zig via systems projects.
  • Series is explicitly open-ended: future chapters from Sandler’s book will be added if the author continues.

Hacker News Comment Review

  • Commenters questioned whether a C compiler needs low-level language features at all, noting that compilers are essentially text-to-text translators that can delegate machine-level work to an assembler – Pascal compilers written in Pascal were cited as precedent.
  • One commenter flagged that Zig already bundles a C compiler (via Clang/LLVM) and raised whether a pure-Zig C frontend could eventually reduce that dependency, framing this as aligned with Zig’s early “maintain C projects in Zig” value proposition.
  • The repo’s own writeup (c19.md) suggests the author grew frustrated with lower-level language constraints and stopped, giving the series an abrupt ending that the index page’s open-ended framing does not fully convey.

Notable Comments

  • @fuhsnn: Points to c19.md in the repo where the author apparently documents hitting a wall with lower-level language friction and quitting.
  • @scatbot: Asks whether a project like this could eventually replace Clang as the C frontend in Zig’s own toolchain.

Original | Discuss on HN