A minimal C-like compiler built from scratch, implementing the full pipeline from parsing to x86 code generation.
- Lexical analysis (tokenization)
- Recursive descent parser with operator precedence
- Abstract Syntax Tree (AST) generation
- Intermediate Representation (IR) generation
- x86 assembly code generation
- Cross-platform support (Linux and Windows)
- Final executable generation using GCC
Source Code (.tinyc)
↓
Lexer
↓
Parser
↓
AST
↓
IR Generation
↓
Code Generation (x86)
↓
Assembly (.s)
↓
GCC → Executable
TinyC/
├── include/ # Header files
│ ├── ast.h
│ ├── codegen.h
│ ├── irgen.h
│ ├── ir.h
│ ├── lexer.h
│ ├── parser.h
│ └── token.h
│
├── src/ # Core compiler implementation
│ ├── lexer.cc
│ ├── parser.cc
│ ├── irgen.cc
│ ├── codegen_linux.cc
│ ├── codegen_windows.cc
│ └── main.cc
│
├── helpers/ # Runtime helpers
│ └── print_helper.c
│
├── main.tinyc # Sample input program
├── output.s # Generated assembly
├── output.exe # Final compiled binary
│
├── Makefile # Linux build
├── Make.bat # Windows build
├── CMakeLists.txt # Alternative build config
│
├── gtc.exe / a.exe # Compiler binaries (generated)
├── lexer.o # Object files (generated)
│
├── LICENSE
└── README.md
make
./gtc main.tinycThen:
gcc output.s helpers/print_helper.c -o output.exe
./output.exeMake.batThen:
gtc.exe main.tinyc
gcc output.s helpers/print_helper.c -o output.exe
output.exeConverts source code into tokens.
Recursive descent parser with operator precedence handling.
Represents the structure of the program.
Transforms AST into an intermediate representation.
Generates x86 assembly (separate implementations for Linux and Windows).
int a = 5;
int b = 55;
int c = a + b;
print(c);
int d = c + 11;
print(d);
int s = 25;
int j = 5;
int k = s / j;
print(k);60
71
5
- Supports only
inttype - Limited to arithmetic operations (
+,-,*,/) - No loops or conditionals yet
- Minimal error handling
This project was built to understand:
- Compiler design
- Parsing techniques
- Intermediate representations
- Low-level code generation
- C / C++
- GCC
- Make / CMake
- x86 Assembly
Ayusman Avisek Nanda https://github.com/AyusmanNanda