>

Unordered Notes on Compiler Research

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

hnidoaht-101

A 🦀 love open sources. Actually just a pet lover with passion to build the nice things.


By hn1Do@ht-0n3z3Roo11e, 2023-06-24