⚠️ For Educational Purposes Only: Bodhi is intended for learning and experimentation only. It is not designed for, tested for, or suitable for production use. The language lacks features required for production software such as performance optimizations, comprehensive error handling, a standard library, package management, security hardening, and extensive testing.
Bodhi is a simple, expressive programming language with Python-style significant whitespace and a clean, readable syntax. It is being developed as an educational interpreter project with a focus on clarity and modern language design.
Bodhi is an interpreted language that aims to combine the readability of Python with the simplicity of a teaching language. It features:
- Significant whitespace for block structure (no braces needed)
- Simple syntax with clear, readable constructs
- First-class expressions with arithmetic, comparison, and logical operators
- Immutable variables via
letdeclarations - Control flow with
if/elif/elseandforloops - Built-in print for output
This repository contains the Bodhi interpreter implementation in Python. Current status:
| Component | Status | Description |
|---|---|---|
| Lexer | ✅ Complete | Tokenizes source code with Python-style indentation |
| Parser | 🚧 In Progress | AST construction from token stream |
| Interpreter | 📋 Planned | Expression evaluation and statement execution |
- Python 3.12+
- pytest (for running tests)
# Clone the repository
git clone <repository-url>
cd bodhi-lang
# Set up virtual environment
python3.12 -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
pip install pytest# Run all lexer tests
pytest test_lexer.py -v
# Run specific test category
pytest test_lexer.py -k "TestNumberLiterals" -vlet x = 5
let name = "Bodhi"
let pi = 3.14159
let flag = true
let sum = 1 + 2
let product = 3 * 4
let result = (10 - 5) / 2
let is_valid = x > 0 and x < 100
let ready = not false
if x > 0:
print("positive")
elif x < 0:
print("negative")
else:
print("zero")
for i in 1..10:
print(i)
print("Hello, World!")
print(42)
print(x + y)
| Type | Examples |
|---|---|
| Numbers | 42, 3.14, .5, 5. |
| Strings | "hello", "hello\nworld" |
| Booleans | true, false |
| Nil | nil |
| Category | Operators |
|---|---|
| Arithmetic | +, -, *, /, % |
| Comparison | ==, !=, <, <=, >, >= |
| Logical | and, or, not |
| Range | .. |
let, if, elif, else, for, in, print, and, or, not, true, false, nil
The Bodhi interpreter follows a classic three-phase architecture:
Source Code → Lexer → Tokens → Parser → AST → Interpreter → Execution
The lexer transforms source code into a stream of tokens. Key features:
- Location tracking: Every token has line and column information
- Indentation handling: Python-style INDENT/DEDENT tokens for block structure
- Error reporting: Descriptive errors with exact locations
- Escape sequences: Support for
\n,\t,\",\\in strings
See lexer.py for the complete implementation.
Will produce an Abstract Syntax Tree (AST) from tokens, handling:
- Operator precedence and associativity
- Block structure via indentation tokens
- Syntax error recovery and reporting
Will execute the AST with:
- Environment for variable storage
- Expression evaluation with type checking
- Control flow execution
- Runtime error reporting
bodhi-lang/
├── lexer.py # Lexer implementation
├── test_lexer.py # Comprehensive lexer tests
├── openspec/ # Specification documents
│ ├── specs/ # Current specifications
│ └── changes/ # Change history
├── .claude/ # Claude Code configuration
├── .opencode/ # OpenCode configuration
└── README.md # This file
The project uses pytest for testing. Tests are organized by feature:
TestNumberLiterals- Integer and float tokenizationTestStringLiterals- String parsing with escapesTestBooleanAndNilLiterals- Boolean and nil valuesTestKeywords- Reserved wordsTestIdentifiers- Variable namesTestOperators- Arithmetic and comparison operatorsTestIndentation- INDENT/DEDENT handlingTestErrors- Error detection and reportingTestIntegration- Full program tokenization
Run tests with:
pytest test_lexer.py -vThis project uses specification-driven development with the OpenSpec methodology. Specifications are written in a structured format with:
- Requirements - What the system must do
- Scenarios - Concrete examples of behavior
See the openspec/ directory for detailed specifications.
This is an educational project. Contributions are welcome:
- Fork the repository
- Create a feature branch
- Write tests for new functionality
- Implement the feature
- Submit a pull request
MIT License - See LICENSE file for details.
Bodhi draws inspiration from:
- Lox - The language from "Crafting Interpreters"
- Python - For significant whitespace and readability
- Lua - For simplicity and minimalism
This software is provided for educational and learning purposes only.
Bodhi is an experimental programming language created as a learning project. It should not be used for:
- Production applications or services
- Mission-critical systems
- Handling sensitive data
- Performance-sensitive workloads
- Any scenario where reliability and security are paramount
The language implementation lacks many features expected in production-grade languages, including but not limited to: garbage collection optimization, comprehensive error handling, security audits, extensive test coverage, standard library stability guarantees, and long-term maintenance support.
Use at your own risk for learning purposes only.
Note: This is a work in progress. The lexer is complete, parser and interpreter are under development.