This is official repository for bhai-lang.
Bhai lang is a toy programming language written in Typescript.
npm i -g bhailang
Edit the file with a text editor. You can also try out your code on Bhai Lang PlayGround
π€
βοΈ "Hello bhai";
π€
bhailang test.bhai
hello bhai
π€
is the entrypoint for the program and all program must end with π€
. Anything outside of it will be ignored.
This will be ignored
π€
// Write code here
π€
This too
Variables can be declared using π
.
π€
π a = 10;
π b = "two";
π c = 15;
a = a + 1;
b = 21;
c *= 2;
π€
Numbers and strings are like other languages. Null values can be denoted using π«’
. true
and false
are the boolean values.
π€
π a = 10;
π b = 10 + (15*20);
π c = "two";
π d = 'ok';
π e = π«’;
π f = true;
π g = false;
π€
Use βοΈ
to print anything to console.
π€
βοΈ "Hello World";
π a = 10;
{
π b = 20;
βοΈ a + b;
}
βοΈ 5, 'ok', π«’ , true , false;
π€
Bhailang supports if-else-if ladder construct , π
block will execute if condition is true
, otherwise one of the subsequently added π§Ώ
blocks will execute if their respective condition is true
, and the ποΈ
block will eventually execute if all of the above conditions are false
π€
ββπ a = 10;
ββπ (a < 20) {
βοΈ "a is less than 20";
} π§Ώ ( a < 25 ) {
βοΈ "a is less than 25";
} ποΈ {
βοΈ "a is greater than or equal to 25";
}
π€
Statements inside π
blocks are executed as long as a specified condition evaluates to true. If the condition becomes false
, statement within the loop stops executing and control passes to the statement following the loop. Use ππ»
to break the loop and π
to continue within loop.
π€
ββπ a = 0;
ββπ (a < 10) {
βββa += 1;
βββπ (a == 5) {
βββββοΈ "andar se βοΈ ", a;
ββββπ;
βββ}
βββπ (a == 6) {
ββββππ»;
βββ}
ββββοΈ a;
ββ}
βββοΈ "done";
π€
You can explore abstract syntax tree(AST) of bhailang here.