Hausalang: A Hausa-based educational programming language with structured error reporting
Project description
Hausalang: A Beginner-Friendly Programming Language
A simple, educational Hausa-inspired programming language designed for beginners to learn programming concepts in a familiar language context.
๐ Try It Now
Open Hausalang Web Playground - No installation required, code directly in your browser!
Features
Core Language Constructs
-
Variables & Assignment: Store and manipulate values
suna = "Fatima" adadi = 42
-
Output (rubuta): Print values to console
rubuta "Sannu Duniya" # print string rubuta suna # print variable rubuta 3 + 4 # print expression result
-
Conditionals (idan / in ba haka ba): Control program flow with if/else
idan x > 10: rubuta "x is greater than 10" in ba haka ba: rubuta "x is 10 or less" -
Elif (idan ... kuma): Chain conditional checks
idan x > 10 kuma: rubuta "greater than 10" idan x == 10 kuma: rubuta "equals 10" in ba haka ba: rubuta "less than 10" -
Comments: Ignore code for documentation (# outside strings)
# This is a comment suna = "Ali" # inline comment
-
Arithmetic Expressions: Evaluate mathematical operations with proper precedence
rubuta 2 + 3 * 4 # prints 14 (order of operations respected) rubuta (2 + 3) * 4 # prints 20
-
String Concatenation: Combine strings with +
greet = "Sannu " + "Fatima" rubuta greet # prints "Sannu Fatima"
-
String Repetition: Repeat strings with *
rubuta "ha" * 3 # prints "hahaha"
-
Comparisons: Test values with ==, !=, >, <, >=, <=
idan x == 5: rubuta "x is five" -
Functions (aiki): Define reusable code blocks with parameters
aiki add(a, b): mayar a + b result = add(3, 4) rubuta result # prints 7 -
Return (mayar): Exit a function with a value
aiki greet(name): rubuta "Sannu " + name aiki multiply(a, b): mayar a * b -
Scope: Variables defined in functions are isolated from global scope
x = 10 aiki change_x(n): x = n # local x, doesn't affect global mayar x result = change_x(20) rubuta x # still prints 10
Installation
-
Clone the repository:
git clone https://github.com/yourusername/hausalang.git cd hausalang
-
Create and activate a virtual environment (optional):
python -m venv venv source venv/Scripts/activate # On Windows # or source venv/bin/activate # On Linux/Mac
-
Install dependencies:
pip install -r requirements.txt
Quick Start
Run a program:
python main.py examples/hello.ha
Run all example tests:
python test_all.py
Run pytest tests:
pytest -q
Run the web playground locally:
python web_server.py
Then visit: http://localhost:8000/static/
Developer Setup
Install development dependencies:
pip install -r dev-requirements.txt
Set up pre-commit hooks (optional but recommended):
pre-commit install
pre-commit run --all-files # Run checks once
Format and lint code:
black . # Format with Black
ruff check . --fix # Lint and auto-fix with Ruff
mypy core/ # Type check core modules
Run tests with coverage:
coverage run -m pytest
coverage report
Build and run with Docker (optional):
docker-compose up
Then visit: http://localhost:8000/static/
Deployment
Deploy to Replit (Free, Recommended)
- Go to replit.com
- Click "Create" โ "Import from GitHub"
- Paste:
https://github.com/yourusername/hausalang - Click "Import"
- Click "Run"
Your playground is now live with a shareable URL!
Deploy to Heroku
pip install gunicorn
heroku create your-app-name
git push heroku main
Example Programs
Hello World
rubuta "Sannu Duniya"
Variables
suna = "Nura"
rubuta "Sannu " + suna
Conditionals
x = 15
idan x > 10:
rubuta "greater than 10"
in ba haka ba:
rubuta "10 or less"
Functions
aiki add(a, b):
mayar a + b
suna = "Fatima"
aiki greet(n):
rubuta "Sannu " + n
greet(suna)
res = add(3, 4)
rubuta res
Arithmetic
rubuta 10 + 5 # 15
rubuta 10 - 3 # 7
rubuta 5 * 4 # 20
rubuta 20 / 4 # 5.0
rubuta (2 + 3) * 4 # 20
Implementation Notes
Architecture
- core/interpreter.py: Main execution engine with expression parsing (shunting-yard algorithm)
- core/executor.py: Command execution (rubuta/print)
- core/lexer.py: Tokenization and comment stripping helpers
- core/perser.py: Simple parsing utilities for function signatures and arguments
- tests/: Pytest test suite
Error Handling
Errors are reported bilingually in Hausa and English for clarity:
kuskure: sunan variable mara kyau -> 123x (error: invalid variable name -> 123x)
Expression Evaluation
The interpreter uses the shunting-yard algorithm to convert infix expressions to postfix notation for evaluation, respecting operator precedence:
- Multiplication and division: precedence 2
- Addition and subtraction: precedence 1
- Parentheses for explicit grouping
Block Scoping
Indentation determines block membership. Variables are global unless inside a function (which creates local scope).
File Structure
hausalang/
โโโ main.py # Entry point
โโโ core/
โ โโโ __init__.py
โ โโโ interpreter.py # Main interpreter logic
โ โโโ executor.py # Command execution
โ โโโ lexer.py # Tokenization helpers
โ โโโ perser.py # Parsing helpers
โโโ examples/ # Example programs
โ โโโ hello.ha
โ โโโ variables.ha
โ โโโ if.ha
โ โโโ else.ha
โ โโโ comparisons.ha
โ โโโ arithmetic.ha
โ โโโ comments.ha
โ โโโ functions.ha
โ โโโ elif_demo.ha
โโโ tests/ # Pytest test suite
โ โโโ test_comments.py
โ โโโ test_functions.py
โ โโโ test_elif.py
โโโ test_all.py # Example runner
โโโ requirements.txt # Dependencies
โโโ pytest.ini # Pytest configuration
โโโ README.md # This file
Limitations & Future Work
Current Limitations
- No loops (for/while)
- No lists/arrays
- No dictionaries/maps
- No imports or modules
- No exception handling
- Limited string operations (no slicing, indexing)
- No multiple return values
- Single-threaded execution
Planned Features
- Loop constructs (kaie/repeat for loops)
- List/array support (jerin)
- Dictionary support
- String operations (slicing, indexing, methods)
- Exception handling (try/except)
- Module system
- Type hints (optional)
- Performance optimizations
Testing
Run the pytest suite:
pytest -q
Run individual tests:
pytest tests/test_functions.py -v
Run example programs:
python test_all.py
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new features
- Ensure all tests pass
- Submit a pull request
License
This project is open source and available under the MIT License.
Author
Built as an educational project to make programming more accessible in Hausa.
Status: Alpha - Core features implemented, expanding toward a complete beginner-friendly language.
idan suna == "nura": rubuta "Sannu nura"
idan suna == "ali": rubuta "Wani jiya"
Use `in ba haka ba` (else) for alternate paths:
a = 5
idan a > 10: rubuta "A big"
in ba haka ba: rubuta "A small"
### Comparison Operators
- `==` โ equal
- `!=` โ not equal
- `>` โ greater than
- `<` โ less than
- `>=` โ greater than or equal
- `<=` โ less than or equal
Examples:
idan a > b: rubuta "a is bigger"
idan x != 0: rubuta "x is nonzero"
### Variable Names
Variable names must:
- Start with a letter (aโz, AโZ) or underscore (_)
- Contain only letters, digits (0โ9), and underscores
Valid: `suna`, `_name`, `age2`, `NAME`
Invalid: `1suna`, `suna-name`, `name!`
## Examples
The `examples/` folder contains sample programs:
- `examples/hello.ha` โ prints a greeting
- `examples/variables.ha` โ variable assignment and printing
- `examples/if.ha` โ simple `idan` (if) usage
- `examples/else.ha` โ demonstrates `in ba haka ba` (else)
- `examples/comparisons.ha` โ numbers and various comparison operators
- `examples/badvar.ha` โ shows invalid variable name error handling
- `examples/arithmetic.ha` โ arithmetic expressions and precedence
## Error Messages
Errors are displayed in Hausa with English hints to help learners:
kuskure: sunan variable mara kyau -> 1suna (error: invalid variable name -> 1suna)
This dual format supports learning while building vocabulary in both languages.
## Implementation Notes
- **Interpreter**: A single-pass line-based interpreter written in Python.
- **Parsing**: Simple regex and string-based parsing; no external dependencies.
- **Indentation**: Blocks (if/else bodies) use 4-space indentation, Python-style.
- **Bilingual Errors**: All error messages include Hausa and English for accessibility.
## Project Structure
. โโโ main.py # Entry point โโโ core/ โ โโโ init.py โ โโโ interpreter.py # Main interpreter loop โ โโโ executor.py # Command execution (rubuta, etc.) โ โโโ lexer.py # (Placeholder for future tokenizer) โ โโโ perser.py # (Placeholder for future parser) โโโ examples/ โ โโโ hello.ha โ โโโ variables.ha โ โโโ if.ha โ โโโ else.ha โ โโโ comparisons.ha โ โโโ badvar.ha โโโ README.md
## Future Enhancements
- Arithmetic operations (+, -, *, /)
- String concatenation
- Loops (while, for)
- Functions and procedures
- Comments
- Nested blocks
- More built-in commands
- A proper lexer and parser (currently in `core/lexer.py` and `core/perser.py`)
## Contributing
Hausalang is an educational project. When contributing:
1. Keep the language simple and readable for beginners.
2. Prioritize clear error messages in both Hausa and English.
3. Maintain backward compatibility unless explicitly changing the design.
4. Test all new features with example `.ha` files.
## License
MIT (modify and use freely for educational purposes).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hausalang-1.1.0.tar.gz.
File metadata
- Download URL: hausalang-1.1.0.tar.gz
- Upload date:
- Size: 108.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ee1efaf0f710596f73b34dab85ff4da66f3dbd981007fe0211f3a7b6f503d9f
|
|
| MD5 |
23c52a041cb72269880111a42ac183a0
|
|
| BLAKE2b-256 |
e36a22b62716cd8041424a72a57f63a87609ed6532c7272e8bd9d31704ae81b4
|
File details
Details for the file hausalang-1.1.0-py3-none-any.whl.
File metadata
- Download URL: hausalang-1.1.0-py3-none-any.whl
- Upload date:
- Size: 40.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e16d7690aa1b90e96c604b83adabd4e28a8416667619a34e3cf56f19b4ec092
|
|
| MD5 |
635fdef54e8c685ad0fd6cd5ebb283e7
|
|
| BLAKE2b-256 |
07970a66fa046eeb8d1b2d34a24ac0f49efcd079f639e1709fbc8598b905a653
|