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.
What's New in v3.2 ๐
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 - CFG + Basic Blocks โ inspect control flow using
--cfg - IR Optimizer โ constant folding, dead code elimination, CSE, and DAG local optimization via
--opt-ir - SSA Conversion โ convert IR to SSA form (with PHI nodes) using
--ssa - Full OOP โ classes, inheritance,
yeh(this),upar(super) - Exception Handling โ
koshish/pakad/aakhir(try / catch / finally) - Explicit Runtime Memory Model โ runtime stack + heap objects beyond basic activation records
- Interactive REPL โ persistent state across lines,
--irmode 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.2.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
# Show CFG / basic blocks
merilang run script.meri --cfg
# Optimize IR (constant folding + DCE + CSE + DAG local optimization)
merilang run script.meri --opt-ir
# Convert to SSA and print SSA IR (with PHI nodes)
merilang run script.meri --ssa
# Skip semantic analysis (faster, less safe)
merilang run script.meri --no-semantic
# Interactive REPL
merilang repl
merilang repl --ir # show IR for each line
merilang repl --cfg --opt-ir --ssa
# 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.2.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
โ โโโ ir_analysis.py # Basic blocks + CFG builder
โ โโโ ir_dag.py # DAG local expression optimizer
โ โโโ ir_optimizer.py # Global IR optimization pipeline
โ โโโ ir_ssa.py # SSA conversion pass (PHI insertion)
โ โโโ 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 = โฆ |
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.2 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)
- Basic blocks + CFG
- SSA conversion pass
- DAG local expression optimization
- Explicit stack/heap runtime model
- Bytecode compiler & VM
- Standard library expansion
- VS Code extension
- Debugger with breakpoints
- Package manager
Contributing ๐ค
- Fork the repo
- Create a branch:
git checkout -b feature/my-feature - Commit:
git commit -m "Add my feature" - Push:
git push origin feature/my-feature - 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
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-3.2.0.tar.gz.
File metadata
- Download URL: merilang-3.2.0.tar.gz
- Upload date:
- Size: 101.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
975cbcb215cb5370f8cc77ec309b4a6acfbe5fc9a1fcd467a6967ccd106571c7
|
|
| MD5 |
6fdbbf5414aa54270c91250303d4e12b
|
|
| BLAKE2b-256 |
e17aa17c9789adbe1606e764c919b431bd2ed58488492fae24e2c1b2a2bbff58
|
File details
Details for the file merilang-3.2.0-py3-none-any.whl.
File metadata
- Download URL: merilang-3.2.0-py3-none-any.whl
- Upload date:
- Size: 73.7 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 |
9b33de8d536318794c21cc00dd78f078450934c7f979385208ce9205c4e81c59
|
|
| MD5 |
b27f83c2bb2f83f5b4f1ce12f7412220
|
|
| BLAKE2b-256 |
14f5a9e43511a17b19699d088b88c494df315a1f9e50285e2c8efd9eb393a855
|