Skip to content

A toy programming language written in Typescript

License

Notifications You must be signed in to change notification settings

sagarparmar881/bhai-lang

 
 

Repository files navigation

Bhai Lang

Total alerts Language grade: JavaScript Build Build Build

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

jo baka
  bol baka "Hello bhai";
aavje baka

Run

bhailang test.bhai

Output

hello bhai

Documentation

General

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

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

Types

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

Built-ins

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

Conditionals

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

Loops

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

Development

You can explore abstract syntax tree(AST) of bhailang here.

About

A toy programming language written in Typescript

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 95.5%
  • JavaScript 3.8%
  • Other 0.7%