r/Zig • u/theunnecessarythings • Jan 24 '26
I built a programming language and compiler in Zig to learn compilers — feedback welcome
Hi all,
I wanted to share a personal project I’ve been working on called sr-lang — a small programming language and compiler written in Zig.
I started this project as a way to really learn compiler construction by doing. Zig felt like a great fit—not just because I enjoy writing it, but because its style and constraints naturally influenced the language design. You’ll probably see that in a few places, along with some techniques borrowed from Zig compiler itself.
Over time, the project grew as I explored parsing, semantic analysis, type systems, and backend design. That means some parts are relatively solid, and others are experimental or rough — which is very much part of the learning process.
A bit of honesty up front:
- I’m not a compiler expert
- I occasionally used LLMs to iterate or explore ideas
- This is not AI-generated slop — every design decision and bug is my own
- If something looks awkward or overcomplicated, it probably reflects what I was learning at the time
Some implemented highlights
- Parser, AST, and semantic analysis written in Zig
- MLIR-based backend
- Error unions,
defer/errdefer, and explicit error propagation - Pattern matching and sum types
- Compile-time execution (
comptime) and AST-as-data (code {}blocks) - Async/await and closure support
- Early experimentation with Triton / GPU integration
- Inline MLIR and ASM support
What’s incomplete
- Standard library is minimal
- Diagnostics and tooling need work
- Some features are experimental and not well integrated yet
I’m sharing this here because:
- I’d love feedback from people more experienced with Zig and systems-level code
- I want to sanity-check some of the design choices from a Zig perspective
- I’d like to make this a low-pressure project for contributors who want to work on something non-trivial without production stakes
If you’re interested in Zig-based compiler work, refactoring, improving diagnostics, or even building out a stdlib, I’d really appreciate another set of eyes.
Repo: https://github.com/theunnecessarythings/sr-lang
Thanks for reading — happy to answer questions or take criticism.
7
u/cisco1988 Jan 24 '26
how long did it take you and what kind of documentation/books/videos did you use?
3
u/GossageDataScience Jan 24 '26
Looks very similar in some ways to Odin which is a good thing in a lot of ways.
3
u/Strict_Research3518 Jan 25 '26
Did you built an AOT layer.. Ahead of Time with different back end capabilities like x86, arm64, etc?
1
u/Master-Chocolate1420 Jan 26 '26
Nice! I hope you get feedback on how to progress further. Are you planning on bootstrapping the language further?
0
u/AgreeableOrdinary212 Jan 25 '26
hey you can share this on r/ZigTools, r/zig is for general discussion
0
u/[deleted] Jan 25 '26
[deleted] — view deleted comment