Nothing in computer science sounds more challenging than writing a compiler.
And indeed, it is challenging - very challenging. You probably have to be one of those genius guys in order to be able to write a real compiler.
Nevertheless, in this series of blog posts, we are going to show the basic structure of a compiler by implementing a very simple compiler in javascript
: our compiler is going to compile code in LISP
-like syntax into C
-like syntax.
Something like (add 1 2)
will become add(1, 2)
.
This is not going to be easy - but I can guarantee you that you are going to enjoy. I know that for sure because in this series there will be a lot of code snippets and all the code snippets are going to be interactive. You can modify the code as you read the articles. And for sure, it will make this hard journey a lot more fun.
(The interactive code snippets are powered by a tool of mine named KLIPSE.)
This series has been inspired by the super tiny compiler.
Our hope is that you will enjoy this journey and at the end of it, you’ll be a bit less scared by compilers.
The planOur journey is made of 4 stations - each of them depending on the previous ones:
LISP
syntax - into an array of tokens.C
-like code.At the end of the journey, you will have code that does that does the following:
compiler("(add 1 2 (mult 3 4))")
This code snippet is interactive - feel free to play with it…
Are you ready for the journey?
Take a deep breath…
Let’s start with the tokenizer!
One last thing: please don’t try to read all the posts of the series at once, you won’t enjoy. Take at least a couple of hours of rest between each station…
Subscribe to Yehonathan Sharvit newsletterGet the latest and greatest from Yehonathan Sharvit delivered straight to your inbox every week.
Read Next TagsRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4