A minimalist compiler for a simple C-like language with basic arithmetic, variables, and function calls.
- Variables:
auto x;(local),global y;(global) - Assignment:
x = 5; - Arithmetic:
+,-,*,/(e.g.,y = x + 2;) - Function Calls:
add(x);
- Clone or download this repository.
- Build using Makefile:
This will produce the
make
compilerexecutable in the project directory.
To compile a source file and print the IR:
./compiler yourfile.b --print-irTo compile and generate assembly:
./compiler yourfile.b > yourfile.asmTo run the provided tests and print their IR:
make testThis will build the compiler and run it on the test files, printing the IR output for each test.
main.cpp/main.h- Entry point and IR definitionsir.cpp- IR generation and optimizationsgenerator.cpp- Assembly code generationParser.cpp/Parser.h- Parser for the languageTokenizer.cpp/Tokenizer.h- Tokenizer/lexerMakefile- Build instructionstests/- Example and test programs
auto x;
x = 10;
auto y;
y = x + 5;
print(y);
- Implemented three address code IR.
- Workflow: Tokenize -> Parse -> AST -> IR -> Assembly -> Linker ->.out
- Current optimizations:
- Constant folding
- Constant propagation