A compiler in C++ that parses a small imperative language and generates x86-64 assembly, with a focus on tagged-union AST design.
- Integer arithmetic (+, -, *, /)
- Variable bindings (let)
- Program exit statements
- Lexical scoping
- Uses a tagged-union AST: each node has a NodeType tag and a union of payloads.
- Move semantics are used for node data management.
- Manual destructors handle cleanup for union members.
- Linux OS
nasm,ld,cmake
mkdir build && cd build
cmake .. && make
./testy ../test_input_files/test_input_1.txt let x = 2 + 3;
exit x;section .data
x dq 0 ; global variable
section .text
global _start
_start:
mov rax, 2
mov rbx, rax
add rax, 3 ; RAX = 2 + 3
mov [x], rax
mov rdi, rax
mov rax, 60 ; exit syscall
syscallchmod +x compiler_test.sh
./compiler_test.sh
## Example
let x = 2 + 3;
exit x;