How aftermath22/oxygen_a-compiled-mini-language works
Project Type and Purpose
• This is a small, standalone compiler for the “Oxygen” programming language.
• It implements a traditional three-stage compilation pipeline:
• Lexical Analysis (tokenization)
• Parsing (AST construction)
• Code Generation (x86_64 assembly → object file → executable)
High-Level File / Directory Analysis
• Top-level files:
• CMakeLists.txt: build orchestration
• README.md, LICENSE: documentation
• main (executable stub?)
• test.oxy: sample source
• src/ directory: C++ source and headers
• main.cpp: compiler entry point, command-line interface
• tokenization.hpp: Lexer
• parser.hpp: Recursive-descent Parser → AST
• generation.hpp: Code Generator → x86_64 assembly
• arena.hpp: Custom bump-allocator for AST nodes
a. Front-end (CLI & Build)
• Inputs: .oxy source file
• CMake / build system invoking the compiler
b. Lexer (tokenization.hpp)
• Reads characters → produces Token stream
c. Parser (parser.hpp)
• Consumes Token stream → builds AST in memory
• Uses Arena Allocator for node allocation
d. Arena Allocator (arena.hpp)
• Pre-allocates large memory block
• Provides very fast bump allocations for AST nodes
e. AST Representation
• Variant-based node types (expressions, statements, etc.)
f. Code Generator (generation.hpp)
• Traverses AST → emits x86_64 assembly (out.asm)
• Manages stack frame, registers, scope offsets
g. External Tools
• NASM assembler: out.asm → out.o
• LD linker: out.o → final executable (out)
h. Error Handling Subsystem
• Reports line numbers / messages at lexer/parser stages
Interactions and Data Flow
1. User invokes oxy input.oxy (main.cpp)
2. main.cpp calls Lexer → produces Token stream
3. Token stream passed to Parser → constructs AST (arena-backed)
4. AST passed to Code Generator → writes assembly file
5. Assembly file fed to NASM → object file
6. Object file fed to LD → final executable
7. Any errors bubble up through each stage with contextual info
Architectural Patterns & Principles
• Pipeline Architecture: clear stage separation (Lex → Parse → Generate)
• Recursive Descent Parser: hand-written, precedence management
• Bump Allocator (Arena): bulk allocate AST nodes, free all at once
• Visitor-like traversal in Code Generator
• Modular separation: each component in its own header
• Optional numbering of steps to guide a viewer through the pipeline