Bhanai is a simple and intuitive programming language with a Nepali touch. It leverages Node.js under the hood for execution, allowing users to create .bhn
files and run them seamlessly.
To install Bhanai globally via NPM, use the following command:
npm install -g bhanai
Once installed, you can run Bhanai programs using the chalau
command:
- Create a
.bhn
file with your Bhanai code. For example,example.bhn
. - Run the program with:
chalau example.bhn
Function | Description | Syntax Example |
---|---|---|
rakha |
Declare a variable. | rakha("name", "Bhanai") |
sadai_rakha |
Declare a constant. | sadai_rakha("PI", 3.14159) |
Function | Description | Syntax Example |
---|---|---|
jod |
Adds two numbers. | rakha("sum", jod(10, 20)) |
ghata |
Subtracts two numbers. | rakha("difference", ghata(50, 30)) |
guna |
Multiplies two numbers. | rakha("product", guna(5, 6)) |
bhaag |
Divides two numbers. | rakha("quotient", bhaag(20, 4)) |
shesh |
Finds the remainder of division. | rakha("remainder", shesh(25, 4)) |
Function | Description | Syntax Example |
---|---|---|
ra |
Logical AND. | yadi age > 18 ra age < 60: |
athawa |
Logical OR. | yadi age < 18 athawa age > 60: |
hoina |
Logical NOT. | yadi hoina(sachho): |
Function | Description | Syntax Example |
---|---|---|
jodString |
Concatenates two strings. | rakha("greeting", jodString("Namaste", "!")) |
lambai |
Returns the length of a string. | rakha("length", lambai("Namaste")) |
tola |
Extracts a substring. | rakha("sub", tola("Namaste", 0, 7)) |
badal |
Replaces a substring. | rakha("newString", badal("Namaste", "Na", "Ka")) |
thuloAkshar |
Converts string to uppercase. | rakha("upper", thuloAkshar("namaste")) |
sanoAkshar |
Converts string to lowercase. | rakha("lower", sanoAkshar("NAMASTE")) |
chhaina |
Checks if substring exists. | yadi chhaina("Namaste", "aste"): |
kattnu |
Splits string into an array. | rakha("words", kattnu("Namaste Bhanai", " ")) |
khaliHatau |
Trims whitespace. | rakha("trimmed", khaliHatau(" Namaste ")) |
khojnu |
Finds position of substring. | rakha("pos", khojnu("Namaste", "aste")) |
ulto |
Reverses a string. | rakha("reverse", ulto("Namaste")) |
thapString |
Pads string on the right. | rakha("padded", thapString("Namaste", "!", 10)) |
suruThap |
Pads string on the left. | rakha("padded", suruThap("Namaste", "*", 10)) |
sabdaGanna |
Counts words in a string. | rakha("count", sabdaGanna("Namaste Bhanai")) |
Function | Description | Syntax Example |
---|---|---|
bhanai |
Outputs to the console. | bhanai("Hello, World!") |
Function | Description | Syntax Example |
---|---|---|
sodhString |
Reads string input from the user. | rakha("name", sodhString("Enter your name: ")) |
sodhNumber |
Reads numeric input from the user. | rakha("age", sodhNumber("Enter your age: ")) |
Structure | Description | Syntax Example |
---|---|---|
yadi ... aru |
If-Else structure. | yadi age < 18: ... aru: |
yadi ... athawa ... aru |
If-Else-If structure. | yadi age < 13: ... athawa age < 20: ... aru: |
Type | Description | Syntax Example |
---|---|---|
Single-line | Inline comments. | # This is a comment |
Multi-line | Block comments. | """ This is a multi-line comment """ |
Here’s a complete example showcasing the features of Bhanai:
tippani This is a sample code for the Bhanai Programming Language
rakha("name", "Bhanai User")
sadai_rakha("PI", 3.14159)
rakha("sum", jod(10, 20))
bhanai("Hello, " + name + "! Sum of 10 and 20 is: " + sum)
# String manipulation
rakha("greeting", "Namaste")
rakha("fullGreeting", jodString(greeting, " Swagat chha Bhanai ma!"))
bhanai("Full Greeting: " + fullGreeting)
yadi age < 18:
bhanai("Timro umar kam chha.")
athawa age == 18:
bhanai("Timro umar 18 chha.")
aru:
bhanai("Timro umar thik chha.")
Save your Bhanai programs with the .bhn
file extension. For example:
example.bhn
To execute .bhn
files:
- Ensure Node.js is installed.
- Run the program using the Bhanai interpreter:
chalau example.bhn