Compilers Resources

This post is a compilation of great resources I found while building a type checker for Python. These resources are free and highly focused on specific topics, making them ideal for learning by doing rather than going through extensive materials.

Parser

There are different ways to approach parsing. You can either write one by hand or use a parser generator. For compilers or interpreters, you can use a parser generator. However, if you’re working on tools like formatters or language servers, your parser needs to handle broken code gracefully. This can be either done with a tool like treesitter that can handle broken code to some extent and also by writing your own. Of course writing your own is more fun.

Compilers & Interpreters

“Crafting Interpreters” is an essential resource for compilers. I recommend reading it chapter by chapter as you build your project.

For a comprehensive understanding of relevant topics, consider following the Stanford Compilers Class. Although I haven’t watched it personally, I found this guide based on the class quite helpful.

You can find examples of implemented programming languages and use them as a reference Programming Languages Zoo is one resource for this.

Symbol Table

For symbol table you need to check the language implementation and know the scoping rules, private/public, and different kinds of symbols. There’s no all in one solution.

This series on the Python symbol table implementation from Eli Bendersky is useful for learning how does a symbol table works.

RustPython’s SymbolTable implementation.

Semantic Analyzer

While resources specific to the semantic analysis phase are scarce, you can find inspiration and solutions in existing projects:

  • MyPy wiki.
  • Pyright’s binder.ts is an example of you would do it.

Type Checking

For type checking you are mostly interested in the type rules in that language. Therefore it’s good to check other type checker implementations. They will teach you the rules and how to do it.

LSP (Language Server Protocol)

For a comprehensive understanding of language servers, file systems, updates, and testing, check out this Explaining Rust AnalyzerYouTube playlist from Matkald.

LSP specifications are very easy to read. It’s long but you don’t need everything in the beginning. To skip the part of defning every structure yourself you can use Tower LSP.

Linters

Same as with type checking, for linters it’s best to look into implementations and learn from them. Specially linters have a lot in common with compilers and interpreters because they just emit a human readable error instead of machine code.

The following tools are useful to understand how analysis is done and errors are reported:

Final Words

Compilers are super fun. If you have more resources please send them to me.