A compiled, statically-typed, object-oriented language with Kiswahili syntax, C++/Java-like structure, and native machine code output.
# Swahili Compiler (Educational)
A small, modular compiler written in C that demonstrates the **classical compiler pipeline** using a tiny Swahili-flavored language.
This project is meant for learning: each compiler phase is separated into its own module so you can study and run each stage end-to-end.
## Why this project exists
- Teach compiler fundamentals with a compact codebase.
- Keep each phase independent and readable.
- Use Swahili-inspired keywords (`namba`, `maneno`, `kama`, `sio`, `wakati`, `andika`) so syntax examples feel approachable and distinctive.
## Implemented pipeline
The compiler currently runs the following phases:
1. **Lexical analysis** (`lexer/`)
Converts source text into a stream of tokens.
2. **Parsing / syntax analysis** (`parser/`)
Builds an Abstract Syntax Tree (AST) with expression precedence.
3. **Semantic analysis** (`semantic/`)
Tracks declarations/types and reports semantic errors.
4. **Intermediate Representation (IR) generation** (`ir/`)
Produces simple three-address-code (TAC)-style instructions.
5. **Optimization** (`optimizer/`)
Applies basic optimization passes.
6. **Code generation** (`codegen/`)
Emits readable pseudo-assembly.
Driver entrypoint: `compiler/main.c`.
## Repository structure
```text
compiler/ # pipeline driver (main)
lexer/ # tokenizer + token stream helpers
parser/ # AST definitions + recursive-descent parser
semantic/ # symbol table + semantic checks
ir/ # TAC-style intermediate code generation
optimizer/ # basic IR optimization
codegen/ # pseudo-assembly emitter
examples/ # sample .swa programs
```
> Note: There is also an older `src/` tree in this repository. The command below builds the modular pipeline used by `compiler/main.c`.
## Language overview (current grammar/features)
### Data types
- `namba` → integer
- `maneno` → string
### Statements
- Variable declaration (optional initialization)
- `namba x;`
- `namba x = 10;`
- `namba x ni 10;` (also accepted)
- Assi …