Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dullabs/bhai-lang
A toy programming language written in Typescript
https://github.com/dullabs/bhai-lang
interpreter javascript parser programming-language typescript
Last synced: 30 days ago
JSON representation
A toy programming language written in Typescript
- Host: GitHub
- URL: https://github.com/dullabs/bhai-lang
- Owner: DulLabs
- License: mit
- Created: 2021-12-31T12:41:46.000Z (almost 3 years ago)
- Default Branch: develop
- Last Pushed: 2024-01-01T19:38:08.000Z (11 months ago)
- Last Synced: 2024-04-25T21:43:58.600Z (7 months ago)
- Topics: interpreter, javascript, parser, programming-language, typescript
- Language: TypeScript
- Homepage: https://bhailang.js.org/
- Size: 1.84 MB
- Stars: 3,955
- Watchers: 41
- Forks: 500
- Open Issues: 65
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
Bhai Lang
This is official repository for bhai-lang.
Bhai lang is a toy programming language written in Typescript.
Installation
```
npm i -g bhailang
```Usage
Create a new file (
test.bhai
)Edit the file with a text editor.
You can also try out your code on Bhai Lang PlayGround```
hi bhai
bol bhai "Hello bhai";
bye bhai```
Run
```
bhailang test.bhai
```Output
```
hello bhai
```Documentation
General
hi bhai
is the entrypoint for the program and all program must end withbye bhai
. Anything outside of it will be ignored.```
This will be ignored
hi bhai
// Write code here
bye bhaiThis too
```Variables
Variables can be declared using
bhai ye hai
.```
hi bhai
bhai ye hai a = 10;
bhai ye hai b = "two";
bhai ye hai c = 15;
a = a + 1;
b = 21;
c *= 2;
bye bhai
```Types
Numbers and strings are like other languages. Null values can be denoted using
nalla
.sahi
andgalat
are the boolean values.```
hi bhai
bhai ye hai a = 10;
bhai ye hai b = 10 + (15*20);
bhai ye hai c = "two";
bhai ye hai d = 'ok';
bhai ye hai e = nalla;
bhai ye hai f = sahi;
bhai ye hai g = galat;
bye bhai
```Built-ins
Use
bol bhai
to print anything to console.```
hi bhai
bol bhai "Hello World";
bhai ye hai a = 10;
{
bhai ye hai b = 20;
bol bhai a + b;
}
bol bhai 5, 'ok', nalla , sahi , galat;
bye bhai
```Conditionals
Bhailang supports if-else-if ladder construct ,
agar bhai
block will execute if condition issahi
, otherwise one of the subsequently addednahi to bhai
blocks will execute if their respective condition issahi
, and thewarna bhai
block will eventually execute if all of the above conditions aregalat
```
hi bhai
bhai ye hai a = 10;
agar bhai (a < 20) {
bol bhai "a is less than 20";
} nahi to bhai ( a < 25 ) {
bol bhai "a is less than 25";
} warna bhai {
bol bhai "a is greater than or equal to 25";
}
bye bhai
```Loops
Statements inside
jab tak bhai
blocks are executed as long as a specified condition evaluates to sahi. If the condition becomesgalat
, statement within the loop stops executing and control passes to the statement following the loop. Usebas kar bhai
to break the loop andagla dekh bhai
to continue within loop.```
hi bhai
bhai ye hai a = 0;
jab tak bhai (a < 10) {
a += 1;
agar bhai (a == 5) {
bol bhai "andar se bol bhai ", a;
agla dekh bhai;
}
agar bhai (a == 6) {
bas kar bhai;
}
bol bhai a;
}
bol bhai "done";
bye bhai
```Development
You can explore abstract syntax tree(AST) of bhailang here.