A compiler for a German-keyword programming language (.d files) built with Flex/Bison. Generates LLVM IR for further compilation to native code.
University Project — This was a compiler construction course project. The codebase is complete and serves as an educational reference implementation. No further development is expected.
- Bison ≥ 3.8.2 (macOS: install via Homebrew, system version is too old)
- Flex
- CMake ≥ 3.28
- C++17 compiler (GCC or Clang)
- LLVM (for IR generation and native compilation)
mkdir build && cd build
cmake ..
makemacOS users: Homebrew Bison is required:
cmake -DBISON_EXECUTABLE=$(brew --prefix bison)/bin/bison ..The compiler parses .d source files and generates LLVM IR (.ll files). To produce an executable binary, you need to compile the IR and link it with a C/C++ wrapper.
./build/compiler program.dThis generates output.ll in the current directory.
# Step 1: Compile D source to LLVM IR
./build/compiler program.d
# Step 2: Compile IR to object file
llc -filetype=obj output.ll -o program.o
# Step 3: Link with C/C++ wrapper
clang wrapper.cc program.o -o program
# Step 4: Run
./programSee src/llvm/ for example C++ wrapper files and test IR.
-p— Trace parsing (Flex/Bison parser only)-s— Trace scanning (Flex/Bison parser only)
| Directory | Purpose |
|---|---|
src/parser/ |
Flex/Bison parser + Driver |
src/manual/ |
Hand-written recursive-descent parser ( |
src/ast/ |
AST node types, Visitor pattern, ASTPrinter, AST→Symboltable |
src/symboltable/ |
Symbol table implementation and printer |
src/semantic/ |
Semantic analysis passes (GlobalDeclPass, SemanticChecker) |
src/ir-generator/ |
LLVM IR code generation (CodegenVisitor) |
src/llvm/ |
Example C++ wrappers and test IR files |
src/common/ |
Shared types: SourceLocation, Token, Types |
tests/ |
Test suite with correct/incorrect programs |
cd tests && bash parser_test.shThe test script:
- Rebuilds the compiler from scratch
- Runs all
.dfiles intests/correct/(expects exit code 0) - Runs all
.dfiles intests/incorrect/(expects exit code 1) - Automatically detects Homebrew Bison on macOS
The manual parser in src/manual/ is no longer maintained. Use the default Flex/Bison parser for all compilation tasks. See src/manual/README.md for architectural documentation.
The source language uses German keywords such as:
funk(function)leer(void)zurück(return)- and others
See test files in tests/correct/ for example programs.