A compiled programming language that uses Bengali keywords, built with Go as a hobby project.
- 📝 Bengali keywords and syntax
- 🔤 Bengali variable names - Full Unicode support for identifiers
- ⚡ Bytecode compiler (3-10x faster than interpretation!)
- 🖥️ Stack-based virtual machine
- 📝 Variables and functions with closures
- 🔢 Numbers, strings, booleans, arrays, and hash maps
- 🔄 Control flow (if-else, while, for loops)
- 🚀 Interactive REPL
- 📚 30+ Built-in functions (file I/O, string methods, math functions, array operations)
- 🎯 Recursion and higher-order functions
- 🔗 Logical operators (&&, ||, !)
- 🔢 Bitwise operators (&, |, ^, ~, <<, >>)
- 📁 File I/O support - Read and write files
- 🔧 Self-hosting capable - Full compiler written in Bhasa itself!
- 🧮 Math functions (power, sqrt, abs, max, min)
- 📝 String manipulation (split, join, uppercase, lowercase, trim, replace)
- 🔢 Multiple numeric types (Byte, Short, Int, Long, Float, Double) with type casting
- 📦 Module system with
অন্তর্ভুক্ত(import) support
| English | Bengali | Usage |
|---|---|---|
| let | ধরি | Variable declaration |
| function | ফাংশন | Function declaration |
| if | যদি | Conditional |
| else | নাহলে | Else clause |
| return | ফেরত | Return statement |
| true | সত্য | Boolean true |
| false | মিথ্যা | Boolean false |
| while | যতক্ষণ | While loop |
| for | পর্যন্ত | For loop |
| break | বিরতি | Break statement |
| continue | চালিয়ে_যাও | Continue statement |
| null | নাল | Null value |
| import | অন্তর্ভুক্ত | Import module |
- 📖 Self-Hosting Compiler Guide - Learn how the Bhasa compiler is written in Bhasa
- 🔧 Compiler API Documentation - Complete API reference for the self-hosted compiler
- 🧪 Test Suite - Comprehensive tests for lexer, parser, compiler, and bootstrap
go build -o bhasa
./bhasaYou can build binaries for different platforms using the provided Makefile:
# Build for all platforms
make all
# Build for specific platform
make linux-amd64 # Linux AMD64
make linux-arm64 # Linux ARM64
make windows-amd64 # Windows AMD64
make windows-arm64 # Windows ARM64
make darwin-amd64 # macOS Intel
make darwin-arm64 # macOS Apple Silicon
# Build for all Linux platforms
make linux
# Build for all Windows platforms
make windows
# Build for all macOS platforms
make darwin
# Clean build artifacts
make cleanBinaries will be created in the bin/ directory with platform-specific names:
bhasa-linux-amd64bhasa-linux-arm64bhasa-windows-amd64.exebhasa-windows-arm64.exebhasa-darwin-amd64bhasa-darwin-arm64
You can also build manually using Go:
# Linux AMD64
GOOS=linux GOARCH=amd64 go build -o bin/bhasa-linux-amd64
# Windows AMD64
GOOS=windows GOARCH=amd64 go build -o bin/bhasa-windows-amd64.exe
# macOS ARM64 (Apple Silicon)
GOOS=darwin GOARCH=arm64 go build -o bin/bhasa-darwin-arm64লেখ("নমস্কার বিশ্ব!")
ধরি x = ৫;
ধরি y = ১০;
ধরি যোগফল = x + y;
লেখ(যোগফল);
// Variables can use Bengali names
ধরি নাম = "রহিম";
ধরি বয়স = ২৫;
ধরি বেতন = ৫০০০০;
// Functions with Bengali names
ধরি যোগফল_বের_করো = ফাংশন(ক, খ) {
ফেরত ক + খ;
};
লেখ(যোগফল_বের_করো(১০, ২০)); // Output: 30
ধরি যোগ = ফাংশন(a, b) {
ফেরত a + b;
};
লেখ(যোগ(৫, ৩));
ধরি x = ১০;
যদি (x > ৫) {
লেখ("x is greater than 5");
} নাহলে {
লেখ("x is not greater than 5");
}
// AND operator
যদি (x > 5 && y < 10) {
লেখ("Both conditions are true");
}
// OR operator
যদি (score < 40 || score > 90) {
লেখ("Special attention needed");
}
// Bitwise AND
ধরি a = ১২ & ১০; // 8
// Bitwise OR
ধরি b = ১২ | ১০; // 14
// Bitwise XOR
ধরি c = ১২ ^ ১০; // 6
// Bitwise NOT
ধরি d = ~৫; // -6
// Left Shift
ধরি e = ৫ << ২; // 20
// Right Shift
ধরি f = ২০ >> ২; // 5
// C-style for loop
পর্যন্ত (ধরি i = ০; i < ১০; i = i + ১) {
লেখ(i);
}
Bhasa now has all the features needed to write a compiler for itself! See examples/simple_lexer_demo.ভাষা for a working lexer written entirely in Bhasa.
Key self-hosting features:
- Character access and manipulation (
অক্ষর,কোড) - String parsing (
সংখ্যা) - File I/O for reading/writing source files
- For loops for iteration
- Arrays and hashes for data structures
- লেখ() - Print to console
- দৈর্ঘ্য() - Length of string/array
- টাইপ() - Get type of value
- বিভক্ত(str, delimiter) - Split string
- যুক্ত(arr, delimiter) - Join array elements
- উপরে(str) - Convert to uppercase
- নিচে(str) - Convert to lowercase
- ছাঁটো(str) - Trim whitespace
- প্রতিস্থাপন(str, old, new) - Replace text
- খুঁজুন(str, substr) - Find substring index
- অক্ষর(str, index) - Get character at index
- কোড(char) - Get Unicode code point
- অক্ষর_থেকে_কোড(code) - Create character from code
- সংখ্যা(str) - Parse string to integer
- লেখা(num) - Convert integer to string
- ফাইল_পড়ো(path) - Read file contents
- ফাইল_লেখো(path, content) - Write to file
- ফাইল_যোগ(path, content) - Append to file
- ফাইল_আছে(path) - Check if file exists
- শক্তি(base, exp) - Power
- বর্গমূল(n) - Square root
- পরম(n) - Absolute value
- সর্বোচ্চ(a, b) - Maximum
- সর্বনিম্ন(a, b) - Minimum
- গোলাকার(n) - Round number
- প্রথম(arr) - First element
- শেষ(arr) - Last element
- বাকি(arr) - All but first
- যোগ(arr, element) - Add element
- উল্টাও(arr) - Reverse array
Bhasa supports multiple numeric types with explicit casting:
// Numeric type conversions
ধরি x = ১০০;
ধরি b = বাইট(x); // Convert to Byte (0-255)
ধরি s = ছোট_সংখ্যা(x); // Convert to Short (-32768 to 32767)
ধরি i = পূর্ণসংখ্যা(x); // Convert to Int
ধরি l = দীর্ঘ_সংখ্যা(x); // Convert to Long
ধরি f = দশমিক(x); // Convert to Float
ধরি d = দশমিক_দ্বিগুণ(x); // Convert to Double
// Character conversion
ধরি ch = অক্ষর_রূপান্তর("A"); // String to Char
- বাইট (Byte): 0 to 255
- ছোট_সংখ্যা (Short): -32,768 to 32,767
- পূর্ণসংখ্যা (Int): -2,147,483,648 to 2,147,483,647
- দীর্ঘ_সংখ্যা (Long): Full 64-bit integer
- দশমিক (Float): 32-bit floating point
- দশমিক_দ্বিগুণ (Double): 64-bit floating point
Bhasa includes a complete self-hosted compiler written entirely in Bhasa itself! This means you can compile Bhasa programs using a compiler written in Bhasa.
All compiler components are implemented in .ভাষা files:
- টোকেন.ভাষা - Token type definitions and utilities
- লেক্সার.ভাষা - Lexical analyzer (tokenizer)
- এএসটি.ভাষা - Abstract Syntax Tree node structures
- পার্সার.ভাষা - Pratt parser with operator precedence
- প্রতীক_টেবিল.ভাষা - Symbol table for scoping
- কোড.ভাষা - Bytecode instruction encoding/decoding
- কম্পাইলার.ভাষা - AST to bytecode compiler
- মডিউল_লোডার.ভাষা - Module import system
- ভাষা_কম্পাইলার.ভাষা - Main compiler driver
// Import compiler modules
অন্তর্ভুক্ত "modules/ভাষা_কম্পাইলার";
// Compile a file
ধরি ফলাফল = ফাইল_কম্পাইল_করো("my_program.ভাষা");
যদি (ফলাফল["সফল"]) {
লেখ("কম্পাইল সফল!");
} নাহলে {
লেখ("ত্রুটি: " + ফলাফল["ত্রুটি"]);
}
For complete documentation, see SELF_HOSTING.md and COMPILER_API.md.
./bhasaThen you can type Bengali code interactively!
bhasa/
├── main.go # Entry point
├── token/ # Token definitions (Go)
├── lexer/ # Lexical analyzer (Go)
├── ast/ # Abstract Syntax Tree (Go)
├── parser/ # Parser implementation (Go)
├── modules/ # Self-hosted compiler modules (.ভাষা)
│ ├── টোকেন.ভাষা # Token module
│ ├── লেক্সার.ভাষা # Lexer module
│ ├── এএসটি.ভাষা # AST module
│ ├── পার্সার.ভাষা # Parser module
│ ├── প্রতীক_টেবিল.ভাষা # Symbol table
│ ├── কোড.ভাষা # Bytecode instructions
│ ├── কম্পাইলার.ভাষা # Compiler module
│ ├── মডিউল_লোডার.ভাষা # Module loader
│ └── ভাষা_কম্পাইলার.ভাষা # Main compiler driver
├── tests/ # Test files (.ভাষা)
│ ├── lexer_test.ভাষা
│ ├── parser_test.ভাষা
│ ├── compiler_test.ভাষা
│ └── bootstrap_test.ভাষা
├── compiler/ # Bytecode compiler
│ ├── compiler.go # AST → Bytecode
│ └── symbol_table.go # Variable scoping
├── code/ # Bytecode instruction set
├── vm/ # Virtual machine
│ ├── vm.go # Stack-based VM
│ └── frame.go # Call frames
├── object/ # Object system
├── repl/ # Interactive REPL
└── examples/ # Example programs
Compilation Pipeline:
Bengali Source → Lexer → Parser → AST → Compiler → Bytecode → VM → Execution
Key Components:
- Compiler: Translates AST to bytecode (35+ opcodes)
- Virtual Machine: Stack-based execution engine
- Symbol Table: Manages variable scopes (global, local, free, builtin)
- Closures: Full support for lexical scoping
See COMPILER.md for detailed architecture documentation.