Motivation
Recently I’m trying to learn about compilers and programming languages. I want to know how compilers work, how to build a compiler, and how to design a programming language. Therefore, I read some books and papers about compilers and programming languages. I want to keep track of my knowledge and research, so I decided to write this notes. Maybe it’s a very long journey, but I hope I can finish it. I will write this notes in English, but I’m not a native English speaker, so there will be some grammar mistakes. I’m sorry about that.
What is a compiler?
So you’ve designed your fancy new language and it is going to revolutionise the world, but there’s one problem.
How do you run it? That’s the role of a compiler. To explain how compilers work, let’s first flash our minds back to the 19th Century, in the age of the telegraph. Here we have this fancy new telegraph but how do we send messages? Same problem, different domain.
The telegraph operator needs to take in speech and convert it to Morse code, and tap out the code.
The first thing the operator does is make sense of the speech - they split it into words (lexing) , and then understand how those words are used in a sentence (parsing) - are they part of a noun phrase, a subordinate clause etc.
They check if it makes sense by classifying words into categories or types (adjective, noun, verb) and check the sentence makes grammatical sense (we can’t use “runs” to describe a noun as it is a verb not a noun). Finally, they translate (compile) each word into dots and dashs (Morse code), which is then transmitted along the wire.
References
- Compilers: Principles, Techniques, and Tools
- Modern Compiler Implementation in C
- Modern Compiler Implementation in Java
- Modern Compiler Implementation in ML
- Crafting Interpreters
- Essentials of Programming Languages
- Programming Language Pragmatics
- Types and Programming Languages
- Compiling with Continuations
- Advanced Compiler Design and Implementation
- Engineering a Compiler
- Compiler Design in C
- Let’s Build A Simple Interpreter
- So You Want to Build a Language VM
- Inko: I’m trying to contribute to this project. The author is incredibly helpful and friendly. And it’s documentation is seriously amazing. He has a super detailed roadmap for the project.