1.0.6 • Published 5 months ago

bhanai v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

Bhanai Programming Language

npm version npm downloads license GitHub stars GitHub issues

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.


Table of Contents


Installation

To install Bhanai globally via NPM, use the following command:

npm install -g bhanai

Usage

Once installed, you can run Bhanai programs using the chalau command:

  1. Create a .bhn file with your Bhanai code. For example, example.bhn.
  2. Run the program with:
    chalau example.bhn

Features

1. Variable and Constant Declaration

FunctionDescriptionSyntax Example
rakhaDeclare a variable.rakha("name", "Bhanai")
sadai_rakhaDeclare a constant.sadai_rakha("PI", 3.14159)

2. Arithmetic Operations

FunctionDescriptionSyntax Example
jodAdds two numbers.rakha("sum", jod(10, 20))
ghataSubtracts two numbers.rakha("difference", ghata(50, 30))
gunaMultiplies two numbers.rakha("product", guna(5, 6))
bhaagDivides two numbers.rakha("quotient", bhaag(20, 4))
sheshFinds the remainder of division.rakha("remainder", shesh(25, 4))

3. Logical Operations

FunctionDescriptionSyntax Example
raLogical AND.yadi age > 18 ra age < 60:
athawaLogical OR.yadi age < 18 athawa age > 60:
hoinaLogical NOT.yadi hoina(sachho):

4. String Functions

FunctionDescriptionSyntax Example
jodStringConcatenates two strings.rakha("greeting", jodString("Namaste", "!"))
lambaiReturns the length of a string.rakha("length", lambai("Namaste"))
tolaExtracts a substring.rakha("sub", tola("Namaste", 0, 7))
badalReplaces a substring.rakha("newString", badal("Namaste", "Na", "Ka"))
thuloAksharConverts string to uppercase.rakha("upper", thuloAkshar("namaste"))
sanoAksharConverts string to lowercase.rakha("lower", sanoAkshar("NAMASTE"))
chhainaChecks if substring exists.yadi chhaina("Namaste", "aste"):
kattnuSplits string into an array.rakha("words", kattnu("Namaste Bhanai", " "))
khaliHatauTrims whitespace.rakha("trimmed", khaliHatau(" Namaste "))
khojnuFinds position of substring.rakha("pos", khojnu("Namaste", "aste"))
ultoReverses a string.rakha("reverse", ulto("Namaste"))
thapStringPads string on the right.rakha("padded", thapString("Namaste", "!", 10))
suruThapPads string on the left.rakha("padded", suruThap("Namaste", "*", 10))
sabdaGannaCounts words in a string.rakha("count", sabdaGanna("Namaste Bhanai"))

5. Console Output

FunctionDescriptionSyntax Example
bhanaiOutputs to the console.bhanai("Hello, World!")

6. User Input

FunctionDescriptionSyntax Example
sodhStringReads string input from the user.rakha("name", sodhString("Enter your name: "))
sodhNumberReads numeric input from the user.rakha("age", sodhNumber("Enter your age: "))

7. Conditional Statements

StructureDescriptionSyntax Example
yadi ... aruIf-Else structure.yadi age < 18: ... aru:
yadi ... athawa ... aruIf-Else-If structure.yadi age < 13: ... athawa age < 20: ... aru:

8. Comments

TypeDescriptionSyntax Example
Single-lineInline comments.# This is a comment
Multi-lineBlock comments.""" This is a multi-line comment """

9. Lists and Arrays

FunctionDescriptionSyntax Example
lambaiListGets length of arraybhanai(lambaiList(numbers))
thapListAdds item to end of arraythapList(numbers, 6)
hatauListRemoves and returns last itemrakha("lastItem", hatauList(numbers))
Array AccessAccess array element by indexnumbers[0]

10. Objects

FunctionDescriptionSyntax Example
chaabiListGets object keys as arraybhanai(chaabiList(person))
maanListGets object values as arraybhanai(maanList(person))
Property AccessAccess object propertyperson.name
Nested AccessAccess nested propertiesschool.students[0].name

Example Program

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.")

File Extension

Save your Bhanai programs with the .bhn file extension. For example:

example.bhn

Running Bhanai Programs

To execute .bhn files:

  1. Ensure Node.js is installed.
  2. Run the program using the Bhanai interpreter:
    chalau example.bhn
1.0.6

5 months ago

1.0.5

5 months ago

1.0.4

7 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago