Skip to main content

A Hindustani-inspired programming language interpreter

Project description

MeriLang ๐Ÿ‡ฎ๐Ÿ‡ณ

A meri-inspired toy programming language built with Python. Learn programming concepts with familiar Hindi/Urdu keywords!

Version 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 ๐Ÿ“ฆ

From Source

git clone https://github.com/XploitMonk0x01/MeriLang.git
cd MeriLang
pip install -e .

Using pip (when published)

pip install merilang

Quick Start ๐Ÿš€

Hello World

Create a file hello.meri:

shuru
dikhao "Hello, World!"
khatam

Run it:

python -m MeriLang run hello.meri

Interactive REPL

python -m MeriLang repl
MeriLang v1.0.0 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
python -m MeriLang run script.meri

# Run with debug output
python -m MeriLang run script.meri --debug

# Start REPL
python -m MeriLang repl

# Show version
python -m MeriLang version
python -m MeriLang --version

# Show help
python -m MeriLang --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
โ”‚   โ”œโ”€โ”€ __main__.py    # CLI entry point
โ”‚   โ”œโ”€โ”€ lexer.py       # Tokenizer
โ”‚   โ”œโ”€โ”€ parser.py      # Parser
โ”‚   โ”œโ”€โ”€ ast_nodes.py   # AST node definitions
โ”‚   โ”œโ”€โ”€ interpreter.py # Interpreter
โ”‚   โ”œโ”€โ”€ builtins.py    # Built-in functions
โ”‚   โ”œโ”€โ”€ errors.py      # Error classes
โ”‚   โ””โ”€โ”€ cli.py         # Command-line interface
โ”œโ”€โ”€ tests/             # Test suite
โ”‚   โ”œโ”€โ”€ test_lexer.py
โ”‚   โ”œโ”€โ”€ test_parser.py
โ”‚   โ”œโ”€โ”€ test_interpreter.py
โ”‚   โ””โ”€โ”€ test_integration.py
โ”œโ”€โ”€ examples/          # Example programs
โ”œโ”€โ”€ playground/        # Web playground
โ””โ”€โ”€ docs/             # Documentation

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 ๐Ÿ“–

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
  • Package manager
  • Debugger with breakpoints
  • Standard library expansion
  • IDE extensions (VS Code, etc.)
  • Compiled mode (faster execution)
  • Documentation website

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.1.tar.gz (94.6 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.1-py3-none-any.whl (59.0 kB view details)

Uploaded Python 3

File details

Details for the file merilang-1.0.1.tar.gz.

File metadata

  • Download URL: merilang-1.0.1.tar.gz
  • Upload date:
  • Size: 94.6 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.1.tar.gz
Algorithm Hash digest
SHA256 27cbb974b0047d59e57c76564178e5acedc40e854d4d6e999df3450ae5b1ae5a
MD5 b3346c3811d9b8058034589af754c4d3
BLAKE2b-256 ccf7bdc43d2cf9c007aa0785bde3eba0ed87b08bd5701eae3a2d2bfa034778a1

See more details on using hashes here.

File details

Details for the file merilang-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: merilang-1.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e3f320d944859a526de5107fa28be3d8f41006ea28b9ea33e4fc0fb2ebd90a92
MD5 35cc9b3a2a1fc493186887c2c9bfb268
BLAKE2b-256 e0be079385c355d5e1d533aadc208d9191380673397776a708ca806aad9ba14c

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