Skip to main content

Merilang โ€” a desi-flavoured programming language with a full compiler front-end

Project description

Merilang ๐Ÿ‡ฎ๐Ÿ‡ณ

A desi-flavoured programming language with a full compiler front-end โ€” built in Python.

Version PyPI License Python


What's New in v3.0 ๐Ÿ†•

Merilang has graduated from a basic interpreter to a full compiler front-end:

Phase What it does
๐Ÿ” Panic-mode Lexer Collects all bad characters instead of stopping at the first one
๐ŸŒณ Panic-mode Parser Synchronises after errors and reports all syntax problems in one pass
๐Ÿ”ฌ Semantic Analyser Static type-checking, scope resolution, arity checks โ€” before any code runs
๐Ÿ“ IR Generator Lowers the AST to Three-Address Code (3AC) viewable with --ir
๐Ÿš€ Interpreter Unchanged tree-walking execution on the verified AST

Features โœจ

  • Desi Keywords โ€” write code in Hindi-inspired syntax (maan, likho, kaam, โ€ฆ)
  • Panic-mode Error Recovery โ€” see every mistake in one run, not one at a time
  • Static Semantic Analysis โ€” undefined names, type mismatches and arity errors caught before execution
  • IR Dump โ€” inspect the generated Three-Address Code with --ir
  • Full OOP โ€” classes, inheritance, yeh (this), upar (super)
  • Exception Handling โ€” koshish / pakad / aakhir (try / catch / finally)
  • Interactive REPL โ€” persistent state across lines, --ir mode available
  • Bilingual Errors โ€” every error message in English and Hindi

Installation ๐Ÿ“ฆ

From PyPI (recommended)

pip install merilang

From source

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

Quick Start ๐Ÿš€

Hello World

Create hello.meri:

maan naam = "Duniya"
likho("Namaste, " + naam + "!")

Run it:

merilang run hello.meri

Output:

Namaste, Duniya!

Interactive REPL

merilang repl
Merilang v3.0.0 Interactive REPL
>>> maan x = 10
>>> maan y = 32
>>> likho(x + y)
42
>>> niklo
Alvida! ๐Ÿ‘‹

Language Syntax ๐Ÿ“

Comments

// This is a comment

Variables

maan x = 42          // number
maan pi = 3.14       // float
maan naam = "Ravi"   // string
maan flag = sach     // boolean true
maan other = jhoot   // boolean false
maan nothing = khaali // null / None

Operators

Category Operators
Arithmetic + - * / %
Comparison == != > < >= <=
Logical aur (and) ya (or) nahi (not)

Print & Input

likho("Hello!")                    // print with newline
likho_online("Enter name: ")       // print without newline
poocho naam "What is your name? "  // read input into 'naam'

Conditionals

maan umar = 20

agar umar >= 18 {
    likho("Adult")
} warna_agar umar >= 13 {
    likho("Teen")
} warna {
    likho("Child")
}

Loops

While loop:

maan i = 0
jab_tak i < 5 {
    likho(i)
    maan i = i + 1
}

For-each loop:

maan nums = [1, 2, 3, 4, 5]
har n mein nums {
    likho(n)
}

Break & Continue:

jab_tak sach {
    agar x > 10 { ruk }        // break
    agar x == 5 { age_badho }  // continue
    maan x = x + 1
}

Functions

kaam jodo(a, b) {
    wapas a + b
}

maan hasil = jodo(3, 4)
likho(hasil)   // 7

Lambda:

maan double = lambda(x) -> x * 2
likho(double(21))   // 42

Lists & Dicts

maan fruits = ["apple", "mango", "guava"]
likho(fruits[0])           // apple
likho(length(fruits))      // 3
append(fruits, "banana")

maan person = {"naam": "Raj", "umar": 25}
likho(person["naam"])      // Raj

Object-Oriented Programming

class Insaan {
    kaam __init__(naam, umar) {
        yeh.naam = naam
        yeh.umar = umar
    }

    kaam parichay() {
        likho("Mera naam " + yeh.naam + " hai.")
    }
}

class Chaatra extends Insaan {
    kaam __init__(naam, umar, school) {
        upar(naam, umar)
        yeh.school = school
    }

    kaam padhai() {
        likho(yeh.naam + " padh raha hai.")
    }
}

maan c = naya Chaatra("Aryan", 18, "IIT")
c.parichay()   // Mera naam Aryan hai.
c.padhai()     // Aryan padh raha hai.

Exception Handling

koshish {
    maan x = 10 / 0
} pakad galti {
    likho("Error: " + galti)
} aakhir {
    likho("Always runs.")
}

// Throw your own
kaam check_age(umar) {
    agar umar < 0 {
        uchalo "Umar negative nahi ho sakti!"
    }
    wapas sach
}

CLI Reference ๐Ÿ’ป

# Run a script
merilang run script.meri

# Run with debug output (tokens + AST)
merilang run script.meri --debug

# Show Three-Address Code IR before running
merilang run script.meri --ir

# Skip semantic analysis (faster, less safe)
merilang run script.meri --no-semantic

# Interactive REPL
merilang repl
merilang repl --ir           # show IR for each line

# Show version
merilang version
merilang --version

Built-in Functions ๐Ÿ”ง

Function Description
likho(...) Print values
poocho(var, prompt) Read user input
length(x) Length of list or string
append(list, val) Add element to list
pop(list, idx) Remove & return element
insert(list, idx, val) Insert at index
sort(list) Return sorted copy
reverse(list) Return reversed copy
sum(list) Sum of elements
min(list) / max(list) Minimum / Maximum
upper(s) / lower(s) String case conversion
split(s, sep) Split string โ†’ list
join(list, sep) Join list โ†’ string
replace(s, old, new) Replace in string
str(x) / int(x) / float(x) Type conversion
bool(x) / type(x) Type conversion / inspection
abs(x) / round(x, n) Math helpers
range(n) List [0 โ€ฆ n-1]

Project Structure ๐Ÿ—‚๏ธ

merilang/
โ”œโ”€โ”€ merilang/
โ”‚   โ”œโ”€โ”€ __init__.py              # Public API (v3.0.0)
โ”‚   โ”œโ”€โ”€ __main__.py              # python -m merilang
โ”‚   โ”œโ”€โ”€ cli.py                   # Arg parsing + pipeline wiring
โ”‚   โ”œโ”€โ”€ errors_enhanced.py       # All error classes (bilingual)
โ”‚   โ”œโ”€โ”€ lexer_enhanced.py        # Phase 1 โ€” tokeniser (panic-mode)
โ”‚   โ”œโ”€โ”€ ast_nodes_enhanced.py    # AST node dataclasses
โ”‚   โ”œโ”€โ”€ parser_enhanced.py       # Phase 2 โ€” recursive-descent parser
โ”‚   โ”œโ”€โ”€ symbol_table.py          # Scope manager for semantic analysis
โ”‚   โ”œโ”€โ”€ semantic_analyzer.py     # Phase 3 โ€” static analyser
โ”‚   โ”œโ”€โ”€ ir_nodes.py              # 3AC instruction dataclasses
โ”‚   โ”œโ”€โ”€ ir_generator.py          # Phase 4 โ€” AST โ†’ IR lowering
โ”‚   โ”œโ”€โ”€ environment.py           # Runtime variable scoping
โ”‚   โ””โ”€โ”€ interpreter_enhanced.py  # Phase 5 โ€” tree-walking interpreter
โ”œโ”€โ”€ tests/
โ”‚   โ””โ”€โ”€ smoke_test_pipeline.py   # Full pipeline smoke tests
โ”œโ”€โ”€ examples/                    # .meri example programs
โ”œโ”€โ”€ Guide.md                     # In-depth developer guide
โ”œโ”€โ”€ pyproject.toml               # PEP 517/518 packaging config
โ””โ”€โ”€ setup.py                     # Legacy build compat shim

Full developer reference: Guide.md


Keyword Reference ๐Ÿ”ค

Concept Merilang Python
Variable maan x = โ€ฆ x = โ€ฆ
Print likho(โ€ฆ) print(โ€ฆ)
Input poocho var "prompt" var = input("prompt")
If agar โ€ฆ { } if โ€ฆ:
Elif warna_agar โ€ฆ { } elif โ€ฆ:
Else warna { } else:
While jab_tak โ€ฆ { } while โ€ฆ:
For-each har x mein list { } for x in list:
Break ruk break
Continue age_badho continue
Function kaam name(โ€ฆ) { } def name(โ€ฆ):
Return wapas โ€ฆ return โ€ฆ
Lambda lambda(x) -> expr lambda x: expr
Class class Name { } class Name:
Inherit class A extends B { } class A(B):
New object naya Name(โ€ฆ) Name(โ€ฆ)
This yeh self
Super upar(โ€ฆ) super().__init__(โ€ฆ)
Try koshish { } try:
Catch pakad e { } except e:
Finally aakhir { } finally:
Throw uchalo โ€ฆ raise โ€ฆ
True / False sach / jhoot True / False
Null khaali None
Not nahi not
And / Or aur / ya and / or

Error System ๐Ÿšจ

Merilang reports errors in English + Hindi with line/column positions. In v3.0 all errors from a single run are reported together (panic-mode), so you fix all issues at once.

[LexerError]  Line 4, Col 9: Unexpected character: '@'
[ParseError]  Line 8, Col 1: Expected expression, got 'EOF'
[SemanticError] Line 12: Undefined name 'resutl' โ€” did you mean 'result'?
[TypeCheckError] Line 15: Cannot apply '-' to string and number

Roadmap ๐Ÿ—บ๏ธ

  • Lexer + parser
  • Tree-walking interpreter
  • OOP (classes, inheritance)
  • Exception handling
  • Interactive REPL
  • Panic-mode error recovery (v3.0)
  • Semantic analysis pass (v3.0)
  • IR / Three-Address Code generation (v3.0)
  • Bytecode compiler & VM
  • Standard library expansion
  • VS Code extension
  • Debugger with breakpoints
  • Package manager

Contributing ๐Ÿค

  1. Fork the repo
  2. Create a branch: git checkout -b feature/my-feature
  3. Commit: git commit -m "Add my feature"
  4. Push: git push origin feature/my-feature
  5. Open a Pull Request

See Guide.md for a step-by-step walkthrough of how to add a new language feature.


License ๐Ÿ“„

MIT โ€” see LICENSE.


Made with โค๏ธ for the desi developer 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-3.0.0.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-3.0.0-py3-none-any.whl (62.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: merilang-3.0.0.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-3.0.0.tar.gz
Algorithm Hash digest
SHA256 4615ff3424326e8ca9e1849f7b3f7a814a7d13d63b7aaba167a233b5d5598a73
MD5 fef6c5c8cd6747940fba70f22166bf3d
BLAKE2b-256 2362b59443783bed5e8a5c3c0bd0dea7e7edc102c250b5879a5ff683f4a29ff3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: merilang-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 62.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for merilang-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d16ddadca2a3971fcf815e6aef678dbfcf8dc621456eaffc65283f74b42a65fb
MD5 ce4334cf3c4a0c71878dc45747109615
BLAKE2b-256 1d700c9a5d27ac9d7ff7e2476cebf3cb7336d4e38507f162d9c7d9796d2c7555

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