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
jo baka
bol baka "Hello bhai";
aavje baka
bhailang test.bhai
hello bhai
jo baka
is the entrypoint for the program and all program must end with aavje baka
. Anything outside of it will be ignored.
This will be ignored
jo baka
// Write code here
aavje baka
This too
Variables can be declared using baka aa che
.
jo baka
baka aa che a = 10;
baka aa che b = "two";
baka aa che c = 15;
a = a + 1;
b = 21;
c *= 2;
aavje baka
Numbers and strings are like other languages. Null values can be denoted using nakkamo
. sachu
and khotu
are the boolean values.
jo baka
baka aa che a = 10;
baka aa che b = 10 + (15*20);
baka aa che c = "two";
baka aa che d = 'ok';
baka aa che e = nakkamo;
baka aa che f = sachu;
baka aa che g = khotu;
aavje baka
Use bol baka
to print anything to console.
jo baka
bol baka "Kem Party!";
baka aa che a = 10;
{
baka aa che b = 20;
bol baka a + b;
}
bol baka 5, 'ok', nakkamo , sachu , khotu;
aavje baka
Bhailang supports if-else-if ladder construct , jo agar
block will execute if condition is sachu
, otherwise one of the subsequently added athva toh
blocks will execute if their respective condition is sachu
, and the nahi toh
block will eventually execute if all of the above conditions are khotu
jo baka
baka aa che a = 10;
jo agar (a < 20) {
bol baka "a is less than 20";
} athva toh ( a < 25 ) {
bol baka "a is less than 25";
} nahi toh {
bol baka "a is greater than or equal to 25";
}
aavje baka
Statements inside jya sudhi
blocks are executed as long as a specified condition evaluates to sachu. If the condition becomes khotu
, statement within the loop stops executing and control passes to the statement following the loop. Use roki de
to break the loop and chalva de
to continue within loop.
jo baka
baka aa che a = 0;
jya sudhi (a < 10) {
a += 1;
jo agar (a == 5) {
bol baka "andar thi bol baka ", a;
chalva de;
}
jo agar (a == 6) {
roki de;
}
bol baka a;
}
bol baka "done";
aavje baka
You can explore abstract syntax tree(AST) of bhailang here.