minizig

!UNDER CONSTRUCTION! Nothing works yet!

This book is a collection of problems. You solve them, one by one, and by the end you'll have built a programming language from scratch -- interpreter, compiler, virtual machine, the whole thing. The compiler will work on its own source code. A self-compiling compiler is a fantastic party trick that will impress your friends.

Minizig is a strict subset of Zig -- every program we write in minizig also compiles with the normal zig.exe. We stick to the smallest subset of Zig we can get away with, because eventually we have to write a compiler for it in itself, and we are lazy.

Minizig targets WebAssembly -- a bytecode that runs in browsers, servers, and standalone runtimes. Most books show you how to interpret or compile. We do both, and then we build a virtual machine for the bytecode ourselves, because why not.

About me:

When I was in school, at some point I had to choose between computer graphics and compilers. I chose computer graphics, and now I am a game programmer. But compilers intrigue me, and I always wanted to write one. I spend way too much time lurking in compiler communities (hello ziggit!).

About AI:

I wanted to read a list of small questions/answers that would result in writing a self-hosted compiler for a subset of Zig, and such a thing did not exist. So I asked the AI, and we wrote that together. I have not read any book about compilers, so this is a very strange experience trying to write one. In my defense, I would never have tried writing a book without some serious help, and I would be looking at youtube shorts instead.

Note:

Type the code by hand. Resist the urge to copy-paste or ask an AI to write it for you. (I know, if the thing is written by AI, why should I type it manually. It is a strange paradox). Your goal is to learn how to write a compiler, not to have a new bad compiler... The hands do the learning, not the eyes.

Anyway, the best way to read this AI written book is to be as human as you can, and try irrational detours as you progress through the steps. Have fun!

start →

Temporary chapter name for all chapters