0. Frontmatter

All in all, it wasn’t a bad first day.

— Arnie Cunningham

The journey you are about to be accompanied by is a long one. In fact, it can even turn into a career, if you are not careful enough. More often than not, however, it is a book about a passion for something.

There are tons of resources out there already, so why bother with another resource? Rest assoured, I make sure that you have lots of references and pointers to look at to dig deeper into whatever rabbithole you may find yourself in. This book is a documented journey, it is full of opinionated and uninformed passages. — yet, I believe you that you might quite like it for what it is. It is not a book just about parsing or just about theory or just about how to implement things. A lot of thought has been put into careful balancing all of this.

What even is a programming language?

The technological advances in relatively recent times have given us fast machines. These machines process (a) list(s) of instructions. 1 1 Not necessarily in order… However, how are these lists constructed? In very early practice, researchers have written down these lists, meticulously instructing a machine what to do: “Read from this location, add 5, write the result to that location”.

Software has become ever so slightly more complex that writing these lists by hand has become intractable. Individual items on this list are too simple, e.g., “go here”, “if this is zero, go there”, or “add these together”, and doing anything fun with them can be very tiresome. A programming language maps these low-level instructions onto high-level constructs, arguably in an easier to understand and more readable fashion. 2 2 Some programming languages, such as CoffeeScript, map to another programming language, which again maps to another… The mapping is what is commonly being referred to as compilation and what this book is about.

Some boring notes

To ensure we are on the same page, we should be spending some time into understanding how this book works.

Sidenotes

You may already have seen a sidenote 3 3 Like this one. . They contain potentially interesting but not critical information. It may be a line of thought, an inner monologue expressed in text. It may be a joke or two 4 4 Well, I can at least attempt to be funny, am I right? :) , but always something you can safely skip.

Code

The book may show some code like this:

(* Prints a greeting to the terminal. *)
let () = print_endline "Hi mom & dad!"
Snippet 1. The first snippet.

While some books show all code necessary for the implementation, this book leaves out some parts as an exercise for the reader. Nevertheless, you will not be left alone and should be able to fill in the blank with ease. For example, you may see the code for compiling “addition” and are tasked for implementing “subtraction”.

While I assume you have basic understanding of programming, i.e., knowing what a loop or a condition is, you need not to know about any concrete programming language. The book ensures to explain everything necessary and abstain from obscure language features or libraries.

Code outside of figures is an output/screenshot, for example of a terminal. For example, after compiling the above, we may see the following:

λ ~/first_snippet/ dune exec first_snippet 
Hi mom & dad!

Dialogue

The book is supposed to be fun. In an attempt to raise the fun, you will see some dialogue boxes.

Much like sidenotes, it should more or less be safe to skip them, although they may add some context to the text you are reading. For example, there may be some point I was trying to make and this is contested:

Sounds not fun. How exactly is this artificial interaction fun? It’s just you talking to yourself.

I think it’s fun.

And then you may see me continue here, agreeing that dialogue boxes are fun and continuing to explain why: They break monotonous text into chunks and may contain questions you have had in your head as well, thus increasing your engagement with regards to reading.

If you skip the dialogues, some things at the beginning of paragraphs may not necessarily make much sense, as I use them as a tool to build up tension and construct a line of thought, incrementally working towards a solution.

Callouts

Occasionally, you may encounter boxes such as:

Def.
Compiler\text{Compiler}

A compiler translates from one programming language into another. More formally, given two languages S\src{S} and T\trg{T}, a compiler is a function ST\src{S}\to\trg{T}.

These should not be skipped, as they explain an important concept or contain information that you may need to refer back to. For example, we will build a compiler and you can now hover over the word “compiler” and read back the definition to remember what it is that we are building.

Moreover, there may be exercises and such, which are also clearly marked:

  Exercise

Make sure to understand what a compiler is.

The point of an exercise is to help you understand better. If you don’t think it would be interesting, skip it. It’s about fun.

Footnotes