Umbra Technologies

RSS

A Compiler for a C-inspired Language

Hey!

Updates on the voxel engine have been few and slow. This is both due to school and other occupations, and that I needed to take my mind off the project for a while. There is nothing better to do for relaxation purposes other than starting another programming project!

So here I present my newest project: a compiler!

What I’m making is a compiler which will take a piece of code and spit out x86 machine code. The piece of code will be written in a language (which has no name at the moment) that is very similar to C. The compiler will hopefully also be able to assemble executables too, although it’s not a first priority.

This image shows current progress on variable declaration.

The preprocessor will take the code and turn it into something more friendly for the tokenizer.

The tokenizer splits the code into tokens, for instance an identifier, operator or a keyword or function. It then translates the infix expressions to postfix, also known as RPN ( Reverse Polish Notation), expressions using the Shunting-Yard algorithm. This means that the expression (2 + 4) will be turned into (2 4 +). Read more about RPN here.

The (currently) last stage turns the tokenized and RPNified(?) code into a pseudo-assembly language. This code will be reviewed, optimized and error-checked in the later stages of the compiler. And lastly, the code will be compiled into x86 assembly.