A desi toy programming language built with Python
Project description
MeriLang ๐ฎ๐ณ
A desi toy programming language built with Python.
Features โจ
- Simple Syntax: Easy-to-learn syntax with meri keywords
- Full Programming Language: Variables, functions, loops, conditionals, and more
- Object-Oriented Programming: Classes, inheritance, methods, and properties
- Error Handling: Try-catch-finally blocks for robust error management
- Interactive REPL: Test code snippets interactively
- Helpful Error Messages: Clear error messages with line numbers
- Built-in Functions: Rich standard library for common operations
- File I/O: Read and write files
- Module System: Import and reuse code across files
- Web Playground: Browser-based code editor and runner
Installation ๐ฆ
Using pip (Recommended)
pip install merilang
From Source
git clone https://github.com/XploitMonk0x01/merilang.git
cd merilang
pip install -e .
Quick Start ๐
Hello World
Create a file hello.meri:
shuru
dikhao "Hello, World!"
khatam
Run it:
merilang hello.meri
# or
ml hello.meri
Interactive REPL
merilang
# or
ml
MeriLang v1.0.1 Interactive REPL
Type 'exit' or press Ctrl+C to quit
>>> x = 42
>>> dikhao x
42
>>> dikhao x * 2
84
Language Syntax ๐
Program Structure
Every MeriLang program starts with shuru (begin) and ends with khatam (end):
shuru
// Your code here
khatam
Comments
// Single-line comments start with //
Variables
shuru
x = 42 // Integer
pi = 3.14 // Float
naam = "Rajwant" // String
is_valid = sahi // Boolean (true)
is_false = galat // Boolean (false)
khatam
Data Types
- Numbers:
42,3.14 - Strings:
"Hello","เคจเคฎเคธเฅเคคเฅ" - Booleans:
sahi(true),galat(false) - Lists:
[1, 2, 3],["a", "b", "c"]
Operators
Arithmetic:
+Addition-Subtraction*Multiplication/Division%Modulo
Comparison:
>Greater than<Less than>=Greater than or equal<=Less than or equal==Equal to!=Not equal to
Print Statement
shuru
dikhao "Hello" // Print string
dikhao 42 // Print number
dikhao x // Print variable
dikhao x + y // Print expression
khatam
Input
shuru
dikhao "Enter your name:"
padho naam
dikhao "Hello, " + naam
khatam
Conditionals
shuru
age = 25
agar age >= 18 {
dikhao "Adult"
} warna {
dikhao "Minor"
} bas
khatam
Loops
For Loop:
shuru
chalao i se 0 tak 5 {
dikhao i
}
khatam
While Loop:
shuru
count = 0
jabtak count < 5 {
dikhao count
count = count + 1
} band
khatam
Functions
shuru
// Function definition
vidhi add(a, b) {
vapas a + b
} samapt
// Function call
result = add(5, 3)
dikhao result
// Or use bulayo keyword
bulayo add(10, 20)
khatam
Lists
shuru
// Create list
numbers = [1, 2, 3, 4, 5]
// Access element
dikhao numbers[0]
// Modify element
numbers[1] = 99
// Add element
append(numbers, 6)
// List operations
dikhao length(numbers)
dikhao sum(numbers)
dikhao max(numbers)
dikhao min(numbers)
sorted_nums = sort(numbers)
reversed_nums = reverse(numbers)
khatam
Built-in Functions
List Operations:
length(list)- Get lengthappend(list, value)- Add elementpop(list, index)- Remove and return elementinsert(list, index, value)- Insert at indexsort(list)- Return sorted copyreverse(list)- Return reversed copysum(list)- Sum all elementsmin(list/args)- Get minimummax(list/args)- Get maximum
String Operations:
upper(string)- Convert to uppercaselower(string)- Convert to lowercasesplit(string, separator)- Split into listjoin(list, separator)- Join list into stringreplace(string, old, new)- Replace substring
Type Operations:
type(value)- Get type namestr(value)- Convert to stringint(value)- Convert to integerfloat(value)- Convert to float
I/O Operations:
input(prompt)- Read user inputlikho "file.txt" content- Write to filepadho_file("file.txt")- Read from file
File I/O
shuru
// Write to file
likho "output.txt" "Hello, MeriLang!"
// Read from file
content = padho_file("output.txt")
dikhao content
khatam
Importing Modules
// mylib.meri
shuru
vidhi helper_function(x) {
vapas x * 2
} samapt
khatam
// main.meri
shuru
lao "mylib"
result = helper_function(21)
dikhao result
khatam
Object-Oriented Programming
shuru
// Define a class
class Person {
vidhi __init__(naam, umar) {
yeh.naam = naam
yeh.umar = umar
}
samapt
vidhi greet() {
dikhao "Namaste, "
dikhao yeh.naam
}
samapt
}
// Create instance
p = naya Person("Rajesh", 25)
p.greet()
// Access property
dikhao p.naam
// Inheritance
class Student badhaao Person {
vidhi __init__(naam, umar, school) {
yeh.naam = naam
yeh.umar = umar
yeh.school = school
}
samapt
vidhi study() {
dikhao yeh.naam
dikhao " is studying"
}
samapt
}
s = naya Student("Priya", 20, "Delhi University")
s.greet() // Inherited method
s.study() // Own method
khatam
Error Handling
shuru
// Try-catch-finally
koshish {
x = 10 / 0 // This will fail
}
pakdo err {
dikhao "Error: "
dikhao err
}
akhir {
dikhao "Cleanup done"
}
// Throw custom exceptions
vidhi validate_age(age) {
agar age < 0 {
fenko "Age cannot be negative"
}
bas
vapas sahi
}
samapt
koshish {
validate_age(-5)
}
pakdo err {
dikhao "Validation error: "
dikhao err
}
khatam
Examples ๐
See the examples directory for complete programs:
Basic Examples
- Hello World
- Variables
- Conditionals
- Loops
- Functions
- FizzBuzz
- Fibonacci
- Lists
- Prime Numbers
- String Operations
Advanced Examples (OOP & Error Handling)
- Basic Class - Class definition and objects
- Inheritance - Class inheritance with
badhaao - Bank Account - Real-world OOP example
- Error Handling - Try-catch-finally patterns
- Complete OOP + Errors - Advanced combination
CLI Usage ๐ป
# Run a script
merilang script.meri
# or use short alias
ml script.meri
# Start REPL (interactive mode)
merilang
ml
# Show version
merilang --version
ml --version
# Show help
merilang --help
ml --help
Development ๐ ๏ธ
Running Tests
# Install development dependencies
pip install pytest
# Run all tests
pytest tests/
# Run with coverage
pytest tests/ --cov=MeriLang --cov-report=html
# Run specific test file
pytest tests/test_lexer.py -v
Project Structure
merilang/
โโโ merilang/ # Main package
โ โโโ __init__.py
โ โโโ lexer_enhanced.py # Tokenizer
โ โโโ parser_enhanced.py # Parser
โ โโโ ast_nodes_enhanced.py # AST node definitions
โ โโโ interpreter_enhanced.py # Interpreter
โ โโโ environment.py # Environment management
โ โโโ errors_enhanced.py # Error classes
โ โโโ cli.py # Command-line interface
โโโ tests/ # Comprehensive test suite (172+ tests)
โ โโโ test_lexer_enhanced.py
โ โโโ test_parser_enhanced.py
โ โโโ test_interpreter_enhanced.py
โ โโโ test_oop.py
โ โโโ test_error_handling.py
โ โโโ test_integration.py
โโโ examples/ # 25+ example programs (.meri files)
โโโ benchmarks/ # Performance benchmarks
โโโ docs/ # Documentation
โ โโโ TUTORIAL.md # Comprehensive tutorial
โ โโโ API.md # API documentation
โโโ pyproject.toml # Package configuration
Keyword Reference ๐ค
| English | MeriLang | Usage |
|---|---|---|
| Begin | shuru |
Program start |
| End | khatam |
Program end |
dikhao |
Output statement | |
| Input | padho |
Read input |
| If | agar |
Conditional |
| Else | warna |
Alternative branch |
| End If | bas |
Close if block |
| While | jabtak |
While loop |
| End While | band |
Close while loop |
| For | chalao |
For loop |
| From | se |
Loop start |
| To | tak |
Loop end |
| Function | vidhi |
Define function/method |
| Return | vapas |
Return value |
| End Function | samapt |
Close function |
| Call | bulayo |
Call function |
| True | sahi |
Boolean true |
| False | galat |
Boolean false |
| Import | lao |
Import module |
| Write | likho |
Write to file |
| Class | class |
Define class |
| New | naya |
Create object |
| This | yeh |
Current instance |
| Extends | badhaao |
Inherit from class |
| Super | upar |
Call parent method |
| Try | koshish |
Try block |
| Catch | pakdo |
Catch exception |
| Finally | akhir |
Finally block |
| Throw | fenko |
Throw exception |
Error Handling ๐จ
MeriLang provides helpful error messages with line numbers:
Line 5, Column 12: Undefined variable: 'xyz'
Line 8: Division by zero
Line 12: Expected '=' after identifier
You can also handle errors gracefully with try-catch:
koshish {
risky_operation()
}
pakdo err {
dikhao "Error handled: "
dikhao err
}
Documentation ๐
๐ Official Documentation Website
For comprehensive guides, see:
- TUTORIAL.md - Complete beginner-friendly tutorial
- API.md - API documentation and advanced features
- QUICKSTART.md - Quick start guide
- CONTRIBUTING.md - Contribution guidelines
Contributing ๐ค
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License ๐
This project is licensed under the MIT License - see the LICENSE file for details.
Roadmap ๐บ๏ธ
- Full lexer and parser
- Interpreter with scopes
- Functions and recursion
- Lists and data structures
- File I/O and modules
- Object-Oriented Programming (classes, inheritance, methods)
- Error handling (try-catch-finally, exceptions)
- Comprehensive test suite
- CLI and REPL
- Web playground
- Documentation website
- Package manager
- Debugger with breakpoints
- Standard library expansion
- IDE extensions (VS Code, etc.)
- Compiled mode (faster execution)
Credits ๐
Inspired by educational programming languages and the need for culturally relevant learning tools.
Support โญ
If you like MeriLang, please give it a star on GitHub!
Made with โค๏ธ for the meri community
Project details
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 merilang-1.0.2.tar.gz.
File metadata
- Download URL: merilang-1.0.2.tar.gz
- Upload date:
- Size: 94.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23fb85b16073e9bbbf62c37249374495361527d661b8bda4c7e8178016acb508
|
|
| MD5 |
68b8a0e4f90073450f9ab0f6866a6387
|
|
| BLAKE2b-256 |
ecac887647a261e4bc33733a1742b11bbd671e61218f9969a91265c61ce50358
|
File details
Details for the file merilang-1.0.2-py3-none-any.whl.
File metadata
- Download URL: merilang-1.0.2-py3-none-any.whl
- Upload date:
- Size: 59.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36aa1aca2840c0f216b4152a4a5b28929e92816fb0589f38ae9df5882e624f0c
|
|
| MD5 |
34c9b6d914cf7c732e2b8aada9ff6c90
|
|
| BLAKE2b-256 |
fe657cb323a85c66c99ee50f29244a9fe0d4fad58f321e6f41ec63c15d8da6aa
|