
Preliminariesīefore you start, you need to decide on two things: what language to write your compiler in, and how to handle parsing and lexing. I’ve also written some test programs that you can use to validate that each stage of your compiler works correctly. I’ll cover arithmetic operations, conditionals, local variables, function calls, and perhaps more. This series is adapted from Ghuloum’s paper - the original paper is about compiling Scheme, so I had to make some adjustments to compile C instead. Every step is small enough to feel manageable, and at the end of the every step you have a working compiler. In step one, you just return constants in a later step you handle addition and subtraction and so on. Then you add new language features, one step at a time. I really like Ghuloum’s approach: you start by compiling a tiny, trivial subset of your source language all the way down to x86 assembly. I’ve been working on my own C compiler, nqcc for the past several weeks, using Abdulaziz Ghuloum’s An Incremental Approach to Compiler Construction as a roadmap. It seems like an impossibly hard project (but isn’t!), so writing one will make you feel like a badass.You’ll learn about assembly, calling conventions, and all the gritty, low-level details of how computers, like, do stuff.Handy for working with linters, static analyzers, and metaprogramming of all sorts. You’ll learn about abstract syntax trees (ASTs) and how programs can represent and manipulate other programs.Here are some reasons to write a compiler: The goal for Rumi is to be a language that provides compiler's interface in compile time, so that the developer can decide how certain things should be have, such as how a certain struct is initializing its values or how a function should be linked.This is the first post in a series on writing your own C compiler. The main feature is that rumi's meta language is itself. But let's start by showing off what rumi can do: Rumi's Introduction Just to keep things interesting, I'm going to rewrite it entirely from scratch, so that I can explore more options in bootstrapping. So I decided to rewrite rumi in itself, and keeping a log of what happened and how I handled the problem. It quickly reached to a point where I could run and compile complex programs in it, however, it was a bother to have such a good language and not be able to use it to further develop the compiler.


The process involved writing a C++ code and using LLVM to optimize and generate the code.

During the past year I started working on a compiler called Rumi, where I implemented small things that I found useful.
