Learning to Write Compilers
Tags:compiler
comp_sci
c
So as I have previously mentioned before, I decided to dive into the crazy yet super interesting world of compiler writing. I have been reading textbooks such as Engineering a Compiler by Cooper and Torczon, they are super interesting but I will admit that compiler textbooks are definitely one of the most difficult types of books to digest that I have ever come across! Aside from textbooks, another super useful resource is going through implementations of compilers to see how it is really done. Some of the resources I have used include Crafting Intepreters which teaches one how to write a simple object-oriented language, but I found it interesting because it gave me an idea of how one might implement a bytecode virtual machine. But what I truly enjoyed was acwj and Practical Compiler Construction by Nils Holm as these taught me how to write a compiler for C (well just a subset of C but still it was pretty instructive). C is one of my favourite languages and learning how to write a compiler for it gave me an even more profound understanding of the language and how it works. Before going through the exercise of learning how to write a C compiler, I only had a rudimentary understanding of how assembly code worked, after I was done with the self-compiler C subset compiler I daresay that I had a much much better understanding of assembly code and the what is generated from the code that you and I write on a daily basis. I must say that learning about compilers and assembly code has been an incredibly illuminating experience, I can’t believe that I didn’t learn about all this earlier because before this I really did take for granted the existence of compilers and the amount of amazing work they do for us. I plan on diving deeper into compilers by continuing to read up on the literature that’s available, I also intend to write another C compiler in Rust which will hopefully be an aggregate of the best tricks and ideas that I have seen so far. I also want to learn more about compiler optimisation, which admittedly is something that I don’t know enough of. Alright that’s all for now!