A small, scratch-built compiler written in Rust.
The project implements a simple compiler pipeline that takes arithmetic expressions as input, parses them into an Abstract Syntax Tree (AST), and generates x86-64 assembly code for Windows.
The project is primarily a learning and experimentation project focused on understanding how compilers work at a low level.
Source Expression
│
▼
Lexer
│
▼
Tokens
│
▼
Parser
│
▼
AST
│
▼
Code Generator
│
▼
x86-64 Assembly
│
▼
Executable
- Lexical analysis
- Parsing arithmetic expressions
- Abstract Syntax Tree (AST)
- Integer literals
- Addition (
+) - Subtraction (
-) - x86-64 assembly generation
- Intel assembly syntax
- Basic register and stack usage
- Windows/MinGW executable generation
The compiler can process arithmetic expressions such as:
10 + 5 - 3
and generate x86-64 assembly representing the calculation.
The resulting value is returned through the rax register.
src/
├── lexer.rs # Converts source text into tokens
├── parser.rs # Builds the AST from tokens
├── ast.rs # AST data structures
├── assembly.rs # Generates x86-64 assembly
└── main.rs # Compiler entry point
Make sure you have Rust and Cargo installed.
Clone the repository:
git clone https://github.com/EngineGames-Development/Engine-s-Compiler.git cd Engine-s-Compiler
Build and run the compiler:
cargo run
This generates the assembly output.
The generated assembly can be assembled and linked using MinGW/GCC:
gcc -nostdlib -e _main program.s -o program.exe
Run the resulting executable:
./program.exe
On Windows PowerShell, the result can be inspected using:
$LastExitCodeThis project is being developed as a way to explore compiler construction and low-level programming.
Future goals include:
- Multiplication and division
- Operator precedence
- Parentheses
- Unary operators
- Variables
- Conditional expressions
- Functions
- Improved error reporting
- More complete x86-64 code generation
This compiler is an experimental learning project and is still under development.
The current implementation is intentionally small and focuses on understanding the individual stages of a compiler rather than providing a production-ready programming language.
See the repository for license information.