Skip to main content

A desi toy programming language built with Python

Project description

MeriLang ๐Ÿ‡ฎ๐Ÿ‡ณ

A desi toy programming language built with Python.

Version PyPI License 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 length
  • append(list, value) - Add element
  • pop(list, index) - Remove and return element
  • insert(list, index, value) - Insert at index
  • sort(list) - Return sorted copy
  • reverse(list) - Return reversed copy
  • sum(list) - Sum all elements
  • min(list/args) - Get minimum
  • max(list/args) - Get maximum

String Operations:

  • upper(string) - Convert to uppercase
  • lower(string) - Convert to lowercase
  • split(string, separator) - Split into list
  • join(list, separator) - Join list into string
  • replace(string, old, new) - Replace substring

Type Operations:

  • type(value) - Get type name
  • str(value) - Convert to string
  • int(value) - Convert to integer
  • float(value) - Convert to float

I/O Operations:

  • input(prompt) - Read user input
  • likho "file.txt" content - Write to file
  • padho_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

  1. Hello World
  2. Variables
  3. Conditionals
  4. Loops
  5. Functions
  6. FizzBuzz
  7. Fibonacci
  8. Lists
  9. Prime Numbers
  10. String Operations

Advanced Examples (OOP & Error Handling)

  1. Basic Class - Class definition and objects
  2. Inheritance - Class inheritance with badhaao
  3. Bank Account - Real-world OOP example
  4. Error Handling - Try-catch-finally patterns
  5. 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
Print 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:

Contributing ๐Ÿค

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. 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

merilang-1.0.2.tar.gz (94.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

merilang-1.0.2-py3-none-any.whl (59.0 kB view details)

Uploaded Python 3

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

Hashes for merilang-1.0.2.tar.gz
Algorithm Hash digest
SHA256 23fb85b16073e9bbbf62c37249374495361527d661b8bda4c7e8178016acb508
MD5 68b8a0e4f90073450f9ab0f6866a6387
BLAKE2b-256 ecac887647a261e4bc33733a1742b11bbd671e61218f9969a91265c61ce50358

See more details on using hashes here.

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

Hashes for merilang-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 36aa1aca2840c0f216b4152a4a5b28929e92816fb0589f38ae9df5882e624f0c
MD5 34c9b6d914cf7c732e2b8aada9ff6c90
BLAKE2b-256 fe657cb323a85c66c99ee50f29244a9fe0d4fad58f321e6f41ec63c15d8da6aa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page