NepDai is a fun Nepali programming language inspired by Bhailang and adds a unique Nepali twist to the playful coding experience. The language combines familiar programming concepts with Nepali terminology, creating a unique and culturally relevant coding experience.
"Namaste Dai" - Every NepDai program begins with this traditional Nepali greeting!
npm i -g nepdai
NepDai | English | Description |
---|---|---|
solti |
let/var |
Variable declaration |
yadi (condition) bhane |
if |
Conditional statement |
natra |
else |
Else clause |
jaba samma |
while |
While loop |
vai vayo rokki |
break |
Break statement |
aghi badh vai |
continue |
Continue statement |
lekh |
print |
Print to console |
thik |
true |
Boolean true |
galat |
false |
Boolean false |
khali |
null |
Null value |
Namaste Dai
lekh "Namaste Dai";
nepdai test.nepdai
Namaste Dai
tokens <file> Show tokens for a Nepdai program
ast <file> Show AST for a Nepdai program
repl Start Nepdai REPL
Every NepDai program must start with Namaste Dai
as the first line. This traditional greeting serves as the program's entry point and is mandatory for all .nepdai
files. Any code written before this greeting will result in a compilation error, emphasizing the cultural significance of proper greetings in Nepali tradition.
// Error: If anything is present here, greeting above all
Namaste Dai
// code here, and no semicolon after greeting
Nepdai uses lekh
keyword to print in console.
Namaste Dai
lekh "Hello, World!";
solti name = "Nepal";
lekh "Country:", name;
solti a = 5;
solti b = 10;
lekh "Sum:", a + b;
Variables can be declared using solti
keyword.
Namaste Dai
solti a = 1;
solti b = "sahil";
a = a++;
b = "sahilverse";
c = a + 10;
Nepdai supports various data types just like other programming languages. The special value khali
represents null, while boolean logic uses thik
for true conditions and galat
for false conditions.
Namaste Dai
solti string = "string";
solti number = 10;
solti float = 10.2; // Also a number
solti true = thik;
solti false = galat;
solti null = khali;
Nepdai have support for Array as well. To create an array, simply assign a list of values inside square brackets ([]) to a variable declared with solti. Array operations are very limited right now..
Namaste Dai
// Array examples in Nepdai
solti numbers = [1, 2, 3, 4, 5];
solti names = ["Ram", "Shyam", "Gita"];
solti mixed = [1, "hello", thik, khali];
lekh "Numbers:", numbers;
lekh "Names:", names;
lekh "Mixed array:", mixed;
// Empty array
solti empty = [];
lekh "Empty array:", empty;
// Other Operations on Arrays are not supported right now
NepDai supports standard mathematical operations for numeric calculations.
Operator | Description | Example | Result |
---|---|---|---|
+ |
Addition | 5 + 3 |
8 |
- |
Subtraction | 5 - 3 |
2 |
* |
Multiplication | 5 * 3 |
15 |
/ |
Division | 6 / 3 |
2 |
% |
Modulo (Remainder) | 7 % 3 |
1 |
** |
Exponentiation | 2 ** 3 |
8 |
Namaste Dai
solti a = 10;
solti b = 3;
lekh "Addition:", a + b; // 13
lekh "Subtraction:", a - b; // 7
lekh "Multiplication:", a * b; // 30
lekh "Division:", a / b; // 3.333...
lekh "Modulo:", a % b; // 1
lekh "Power:", a ** b; // 1000
These operators compare values and return boolean results (thik
or galat
).
Operator | Description | Example | Result |
---|---|---|---|
== |
Equal to | 5 == 5 |
thik |
!= |
Not equal to | 5 != 3 |
thik |
> |
Greater than | 5 > 3 |
thik |
< |
Less than | 3 < 5 |
thik |
>= |
Greater than or equal | 5 >= 5 |
thik |
<= |
Less than or equal | 3 <= 5 |
thik |
Namaste Dai
solti age = 25;
lekh "Is adult:", age >= 18; // thik
lekh "Is teenager:", age < 20; // galat
lekh "Exact age:", age == 25; // thik
Logical operators work with boolean values and conditions.
Operator | Description | Example | Result |
---|---|---|---|
&& |
Logical AND | thik && galat |
galat |
|| |
Logical OR | thik || galat |
thik |
! |
Logical NOT | !thik |
galat |
Namaste Dai
solti age = 25;
solti hasLicense = thik;
yadi (age >= 18 && hasLicense) bhane {
lekh "Can drive!";
}
yadi (age < 16 || !hasLicense) bhane {
lekh "Cannot drive!";
}
Assignment operators are used to assign and modify variable values.
Operator | Description | Example | Equivalent |
---|---|---|---|
= |
Simple assignment | a = 5 |
a = 5 |
+= |
Add and assign | a += 3 |
a = a + 3 |
-= |
Subtract and assign | a -= 2 |
a = a - 2 |
*= |
Multiply and assign | a *= 2 |
a = a * 2 |
/= |
Divide and assign | a /= 2 |
a = a / 2 |
Namaste Dai
solti score = 100;
score += 50; // score is now 150
score -= 25; // score is now 125
score *= 2; // score is now 250
score /= 5; // score is now 50
lekh "Final score:", score;
These operators increase or decrease a variable's value by 1.
Operator | Description | Example | Effect |
---|---|---|---|
++ |
Increment (postfix) | a++ |
Increase a by 1 |
-- |
Decrement (postfix) | a-- |
Decrease a by 1 |
Namaste Dai
solti counter = 0;
lekh "Initial:", counter; // 0
counter++;
lekh "After increment:", counter; // 1
counter--;
lekh "After decrement:", counter; // 0
The +
operator can also be used to join strings together.
Namaste Dai
solti firstName = "Ram";
solti lastName = "Sharma";
solti fullName = firstName + " " + lastName;
lekh "Full name:", fullName; // Ram Sharma
// Mixing strings and numbers
solti age = 25;
solti message = "I am " + age + " years old";
lekh message; // I am 25 years old
Operators are evaluated in the following order (highest to lowest precedence):
!
(Logical NOT),-
(Unary minus)**
(Exponentiation)*
,/
,%
(Multiplication, Division, Modulo)+
,-
(Addition, Subtraction)<
,<=
,>
,>=
(Comparison)==
,!=
(Equality)&&
(Logical AND)||
(Logical OR)=
,+=
,-=
,*=
,/=
(Assignment)
Namaste Dai
solti result = 2 + 3 * 4; // 14 (not 20)
solti result2 = (2 + 3) * 4; // 20 (parentheses change order)
lekh "Result 1:", result; // 14
lekh "Result 2:", result2; // 20
Nepdai supports conditional statements using yadi (condition) bhane
for "if", natra yadi (condition) bhane
for "else if", and natra
for the final "else". If a yadi
condition is thik
, its block runs. If not, the next natra yadi
(if any) is checked. If all fail, the natra
block runs. Parentheses around conditions are optional!
Namaste Dai
// Conditional statements in Nepdai
solti age = 25;
solti name = "Ram";
lekh "Name:", name;
lekh "Age:", age;
yadi (age >= 18) bhane {
lekh name, "is an adult";
} natra {
lekh name, "is a minor";
}
// Nested conditionals
solti score = 85;
yadi (score >= 90) bhane {
lekh "Grade: A";
} natra yadi (score >= 80) bhane {
lekh "Grade: B";
} natra yadi (score >= 70) bhane {
lekh "Grade: C";
} natra {
lekh "Grade: F";
}
To create loops, use jaba samma
. This repeats code as long as the condition remains thik
. Use vai vayo rokki
to break out of the loop early, and aghi badh vai
to skip to the next iteration.
Namaste Dai
// While loop with break and continue
solti i = 1;
lekh "Counting with break and continue:";
jaba samma (i <= 10) {
yadi (i == 5) bhane {
lekh "Skipping", i;
i++;
aghi badh vai;
}
yadi (i == 8) bhane {
lekh "Breaking at", i;
vai vayo rokki;
}
lekh "Number:", i;
i++;
}
lekh "Loop finished!";