A simple compiler for a very simple toy language. This is a learning project that focuses on simplicity to keep things easy to understand. There will be things that could be done more efficiently, but that's not the point.
What I want is to write a little compiler with hopefully nothing more than Rust's standard library.
I didn't name it, as that isn't important. The aim is to make a simple language that transpiles to C, making type definition a bit easier. This little snippet:
tipo Circulo(centro: Punto, radio: Real);
tipo Punto(x: Entero, y: Entero);
Will produce this output:
typedef struct Punto {
long x;
long y;
} Punto;
typedef struct Circulo {
Punto centro;
double radio;
} Circulo;
Note that the order in the input language doesn't matter, it will produce C code that compiles nicely.
To build simple-compiler
you need:
- Rust
1.31.0
or better. - Cargo
And just run cargo build --release
- The Super Tiny Compiler: Inspired me to do this.
- Writing An Interpreter In Go: Using only the tools in the standard library is an interesting concept.