Compiling Pascal with LLVM: Part 4
Compilation
It took several hundreds of lines of code, but we're finally there! Today our compiler will come to life and finally compute something for us.
It took several hundreds of lines of code, but we're finally there! Today our compiler will come to life and finally compute something for us.
Today we're going to write a bit less code that last time. But don't worry, I'll compensate that with a healthy scoop of (hopefully) new concepts!
Now to the fun part. We'll be using a recursive parser, just like in Crafting interpreters, so you can easily skip this part if you're familiar with the technique. I made a slight modification to the parsing of binary operators though.
I always wanted to learn LLVM, but I never felt that there are some useful problems I could solve with it in my line of work. Eventually I decided to just have some fun and make something dumb and not useful at all. Yes, we're gonna compile Pascal! A language that I used for the last time like 15 years ago.
This series of posts is highly inspired by the brilliant book "Crafting interpreters" by Bob Nystrom as well as the official tutorial for LLVM. If you're into parsers or compilers, you should definitely check them out!
This is a series of four posts:
And here you can view the final result!
There are two main reasons:
Everything is written in Python3.11
with the llvmlite package.
You can find the (almost) full implementation here. It lacks some minor stuff,
like subrange types, but at this point adding them is more about
implementing a small interface, than inventing something new.