A compiler for the Dana programming language. Dana is an educational programming language designed as a semester project for the Compilers Course (8th semester) in ECE NTUA.
- Frontend: Lexer (Flex) with layout handling, LALR(1) parser (Bison), AST construction
- Semantic Analysis: Type checking, symbol resolution, control flow validation
- LLVM Backend: Code generation, optimization passes
- Dana Runtime Library: Built-in functions, with similar behavior to their C counterparts.
Comprehensive documentation is available in the docs/ folder:
- Language Reference - Complete Dana language specification
- Architecture Overview - Compiler architecture and design
- Building and Usage - How to build and use the compiler
- API Reference - Internal API documentation
def hello
writeString: "Hello world!\n"
def main
def factorial is int: n as int
if n <= 1: return: 1
else: return: n * factorial(n - 1)
var n result is int
n := readInteger()
result := factorial(n)
writeString: "Factorial: "
writeInteger: result
writeString: "\n"
For more examples, see the tests/programs directory.
dana_compiler/
├── src/
│ ├── frontend/ # Lexer, parser, AST, semantic analysis
│ ├── backend/ # Code generation, optimization
│ ├── runtime/ # Runtime library
│ └── main.cpp # Compiler driver
├── tests/
│ ├── programs/ # Valid test programs
│ └── programs-erroneous/ # Programs that should fail
├── docs/ # Documentation
└── dana2025.pdf # Language specification
Download the latest release from GitHub Releases:
# Download and extract
wget https://github.com/geokoko/dana_compiler/releases/latest/download/danac-linux-x64.tar.gz
tar xzf danac-linux-x64.tar.gz
# Install system-wide
sudo mv danac /usr/local/bin/
# Use it!
danac myprogram.dana && ./a.outgit clone https://github.com/geokoko/dana_compiler.git
cd dana_compiler
# Install dependencies (auto-detects your package manager)
# Supports: Ubuntu/Debian (apt), Fedora/RHEL (dnf/yum)
make deps
# Build and install
sudo make install
# Use it!
danac myprogram.dana && ./a.outHaving issues? See Manual Installation for step-by-step instructions.
- Build essentials (gcc, g++, make)
- Clang 18 (with C++17 support)
- LLVM 18 (development libraries)
- Flex & Bison
- Python 3 with pip and pytest
make # Build compiler
make deps # Install dependencies (auto-detects package manager)
make install # Install to /usr/local/bin (needs sudo)
make uninstall # Remove installation
make test # Run test suite (requires prior build)
make clean # Clean build artifactsThe make deps command works on:
- Ubuntu/Debian (apt) - LLVM 18 installed via official llvm.sh
- Fedora/RHEL (dnf/yum) - uses system LLVM packages
# Compile a Dana program (generates a.out in current directory)
danac program.dana
# Run the compiled program
./a.outdanac [OPTIONS] <file.dana>
Options:
--ast-tree Print the abstract syntax tree after parsing
--emit-ir Emit LLVM IR to stdout instead of compiling
-O0 No optimization (default)
-O1 Basic optimizations
-O2 Moderate optimizations
-O3 Aggressive optimizations# Compile with optimizations
danac -O3 program.dana && ./a.out
# View generated LLVM IR
danac --emit-ir program.dana > program.ll
# Debug: view AST structure
danac --ast-tree program.dana
# Compile and run with input
./a.out < input.txt