Diogo Lisboa

Devlog March 2025

March was a busy month in my personal life with much less free time than I expected. The Brazilian Carnival was right in the beginning of the month which for our family usually means traveling and sure enough we had alread planned a 10 day trip, cutting the month short by a third. Multiple other family functions took some of the wind out of my learning sails. That’s something I’ve learned to deal with in general professional life but it’s still a little disheartening when it happens.

Goal

The goal for the month was to write a full C compiler up to the C11 standard — one capable of compiling a large program like git — but as I mentioned this was not a great month to set this goal. I made good headway into the lexer and parser but got bogged down when the amount of labor necessary for small incremental changes got too big. The choice of language (Go) might’ve had something to do with the labor too.

This was a good learning opportunity: goals like these have to be made less ambitious so you can still get something done without feeling discouraged. I sort of knew that already but it’s hard for me to internalize it. It takes some discipline to be satisfied with small steps.

Goal #2

In that spirit the next goal is still to write a C compiler, just breaking it down into much simpler use cases. Rather than compiling a large program focus on small programs and be happy with the results. Build it from the bottom up this time.

(I made the foolish mistake of reading the C11 specification and trying to implement it as presented in the text, building the parser and AST “top-down”. Which meant I’d have nothing to be happy with until I finished the whole thing.)

To make my life easier I’ll finally use lexer and parser generators. Admittedly there was some pride involved in my decision to not use them, I thought I’d learn more by doing it all by hand. Surely there’s some truth to that but C is not the easiest language to parse and a lot of parsing is just busywork: repetitive and slow.

One interesting idea that came from this self-reflection was using OCaml to write the compiler instead of Go. The language is better suited for it and has good support for lexer/parser generators. So that’s the plan now: write a small C compiler in OCaml as a prototype, increase the size of programs that it can compile, rewrite it in a different language later.

Books, Articles and Talks

There was some interesting reading throughout the month. I read Mads Tofte’s Four Lectures on Standard ML to brush up on ML-like languages. It’s always fun to see just how influenced some modern languages are by the old ones, even down to syntax and keyword choice.

But this month most of the time was spent coding Go with the compiler and other small tools. I started on a few books to help with the compiler creation but by now I have a pretty good handle on the initial stages so there wasn’t as much reading necessary.