Skip to content

teddyaryono/bodhi-lang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bodhi Programming Language

⚠️ 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.

Overview

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 let declarations
  • Control flow with if/elif/else and for loops
  • Built-in print for output

Project Status

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

Quick Start

Prerequisites

  • Python 3.12+
  • pytest (for running tests)

Installation

# 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

Running Tests

# Run all lexer tests
pytest test_lexer.py -v

# Run specific test category
pytest test_lexer.py -k "TestNumberLiterals" -v

Language Features

Variables

let x = 5
let name = "Bodhi"
let pi = 3.14159
let flag = true

Arithmetic

let sum = 1 + 2
let product = 3 * 4
let result = (10 - 5) / 2

Comparison and Logical Operators

let is_valid = x > 0 and x < 100
let ready = not false

Control Flow

if x > 0:
    print("positive")
elif x < 0:
    print("negative")
else:
    print("zero")

For Loops

for i in 1..10:
    print(i)

Print Statements

print("Hello, World!")
print(42)
print(x + y)

Syntax Reference

Literals

Type Examples
Numbers 42, 3.14, .5, 5.
Strings "hello", "hello\nworld"
Booleans true, false
Nil nil

Operators

Category Operators
Arithmetic +, -, *, /, %
Comparison ==, !=, <, <=, >, >=
Logical and, or, not
Range ..

Keywords

let, if, elif, else, for, in, print, and, or, not, true, false, nil

Architecture

The Bodhi interpreter follows a classic three-phase architecture:

Source Code → Lexer → Tokens → Parser → AST → Interpreter → Execution

Lexer

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.

Parser (Planned)

Will produce an Abstract Syntax Tree (AST) from tokens, handling:

  • Operator precedence and associativity
  • Block structure via indentation tokens
  • Syntax error recovery and reporting

Interpreter (Planned)

Will execute the AST with:

  • Environment for variable storage
  • Expression evaluation with type checking
  • Control flow execution
  • Runtime error reporting

Project Structure

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

Testing

The project uses pytest for testing. Tests are organized by feature:

  • TestNumberLiterals - Integer and float tokenization
  • TestStringLiterals - String parsing with escapes
  • TestBooleanAndNilLiterals - Boolean and nil values
  • TestKeywords - Reserved words
  • TestIdentifiers - Variable names
  • TestOperators - Arithmetic and comparison operators
  • TestIndentation - INDENT/DEDENT handling
  • TestErrors - Error detection and reporting
  • TestIntegration - Full program tokenization

Run tests with:

pytest test_lexer.py -v

Specification-Driven Development

This 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.

Contributing

This is an educational project. Contributions are welcome:

  1. Fork the repository
  2. Create a feature branch
  3. Write tests for new functionality
  4. Implement the feature
  5. Submit a pull request

License

MIT License - See LICENSE file for details.

Acknowledgments

Bodhi draws inspiration from:

  • Lox - The language from "Crafting Interpreters"
  • Python - For significant whitespace and readability
  • Lua - For simplicity and minimalism

Disclaimer

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.

About

A simple educational programming language with Python-style indentation. Built from scratch to learn interpreter construction.

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages