नेपालीमा प्रोग्रामिङ Programming in Nepali
लिपि (Lipi), a programming language
lipi /li·pi/ n. 1. script; writing. 2. A small programming language you write with Nepali words, and that tells you where you went wrong in Nepali too.
curl -fsSL https://raw.githubusercontent.com/RusilKoirala/lipi/master/install.sh | sh
rakha naam = "Ram";
bhana("Namaste, " + naam);
kaam jod(a, b) {
farkau a + b;
}
yadi (jod(2, 3) > 4) {
bhana("thulo!");
} natra {
bhana("sano");
}
This is the real interpreter, compiled from Go to WebAssembly. Edit the code and press Run.
शब्दकोश · Dictionary
Eight words to learn
Lipi uses everyday Nepali words for the few things every program needs. If you can say it, you can write it.
Read the docs- rakha राख let
- Keep a value under a name.
- rakha naam = "Sita";
- kaam काम function
- A piece of work you can call again.
- kaam jod(a, b) { … }
- farkau फर्काउ return
- Send a value back from a kaam.
- farkau a + b;
- yadi यदि if
- Run a block only when the condition holds.
- yadi (umer > 17) { … }
- natra नत्र else
- Otherwise, run this block instead.
- } natra { … }
- sahi · galat सही · गलत true · false
- The two answers a question can have.
- rakha thik = sahi;
- bhana भन print
- Say something on the screen.
- bhana("Namaste");
- lambai लम्बाइ len
- How many letters a string has.
- lambai("Pokhara")
गल्ती · Galti
Errors that speak your language
When something goes wrong, Lipi says what happened and on which line, in plain Nepali. Beginners get a message they can read, not a stack trace.
Try breaking a program$ lipi hisab.lip
Galti: line 3 ma semicolon birsiyo
Line 3: you forgot a semicolon.
$ lipi naam.lip
Galti: line 7 ma 'umer' bhanne naam bhetiyena
Line 7: no name called 'umer' was found.
$ lipi jod.lip
Galti: line 2 ma sankhya ra string jodna mildaina
Line 2: a number and a string can't be added.
कसरी चल्छ · How it runs
From text to answer in four steps
-
Lexer
Reads your file one character at a time and cuts it into tokens: rakha, naam, =, "Ram". Every token remembers its line, which is how a Galti can point at line 3.
-
Parser
A Pratt parser arranges the tokens into a tree. Each operator has a strength, so 1 + 2 * 3 becomes 1 + (2 * 3) without any special cases.
-
Evaluator
Walks the tree and runs it. Variables live in environments that point to the scope around them, which is what makes closures work.
-
Everywhere
The same Go code builds the lipi command for your terminal and the WebAssembly file that runs the editor on this page.
Lipi was built step by step following Writing an Interpreter in Go by Thorsten Ball, with Nepali keywords and error messages swapped in. Read how it works.
लिपि is open source.
Read the code, open an issue, or leave a star if you would like to see it grow. Loops and arrays are next.