Leaf — Minimal Compiler (C++)
A small example compiler implemented in C++ that parses a tiny language, generates x86-64 assembly, assembles it with NASM and links it to produce an executable.
Prerequisites
- A C++17-compatible compiler
- NASM
Quick start
Clone the repository :
git clone https://github.com/BhuvanB404/leaf.git
cd leafBuild
Compile the compiler driver :
g++ -std=c++17 -O2 -I src -o leaf src/main.cppNotes:
- The program expects a source file in the project-specific
.hyformat (example below). - The compiler will generate
out.asm, then invokenasm -felf64 out.asmandld -o out out.oto produce an executable calledout.
Makefile
A minimal Makefile can automate the build steps. If a Makefile is present in this directory, use:
make
make run
make clean Create a minimal input file example.hy with a single exit statement:
exit(0);Then run:
./leaf example.hy
./outCleaning
rm -f leaf out out.o out.asmLicense
This directory is licensed under the MIT License — see the included LICENSE file for details.