Giter Site home page Giter Site logo

dullabs / bhai-lang Goto Github PK

View Code? Open in Web Editor NEW
4.0K 41.0 498.0 1.88 MB

A toy programming language written in Typescript

Home Page: https://bhailang.js.org/

License: MIT License

JavaScript 3.83% TypeScript 95.41% CSS 0.73% HTML 0.02%
programming-language typescript parser interpreter javascript

bhai-lang's Introduction

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

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 with bye bhai. Anything outside of it will be ignored.


This will be ignored

hi bhai
// Write code here
bye bhai

This 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 and galat 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 is sahi, otherwise one of the subsequently added nahi to bhai blocks will execute if their respective condition is sahi, and the warna bhai block will eventually execute if all of the above conditions are galat


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 becomes galat, statement within the loop stops executing and control passes to the statement following the loop. Use bas kar bhai to break the loop and agla 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.

bhai-lang's People

Contributors

aniketsingh0104 avatar ankitchouhan1020 avatar ayush7614 avatar deep-codes avatar dependabot[bot] avatar harshkanjariya avatar lakhankumawat avatar nikhil216 avatar ristri avatar shubh0107 avatar susmita-dey avatar vipul0092 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bhai-lang's Issues

docs if any?

Any docs for this if provided will be helpful. Also, do mention planned features so as to contribute if possible in some way

Bug or feature? : Adding nalla or boolean type to string is possible

Right now, if a developer tries to add nalla or boolean type to string then its possible:

hi bhai;
bol bhai nalla + " crap";
bye bhai;

Output : "nalla crap"

hi bhai;
bol bhai sahi + " crap";
bye bhai;

Output : "sahi crap"

also, if developer tries to add nalla / boolean to number then :

hi bhai;
bol bhai nalla + 45;
bye bhai;

Output : RuntimeException: Are bhai bhai bhai.... : Ye kya kar raha hai: "+" ke sath "string" aur "number" nahi jamte.

Which is kinda misleading.

Issue templates now use Issue forms instead of markdown

Markdown templates often made it difficult to capture the whole context, by expecting the contributors to read the markup, uncomment lines and delete relevant context.

Issue forms beta was released for public repositories last month, as mentioned by GitHub on this blog. We would like to migrate the issue templates to YAML-based forms which are easy to fill up and maintain, helping us capture relevant context.

https://user-images.githubusercontent.com/67006255/157601493-30b1757d-1acf-4ab3-b732-a8973a1b4139.png

Small Suggestion :

I see that nalla, sahi and galat are language specific bult-in variables/macros here.
Make them _nalla, _sahi and _galat or make them all capital to differentiate them from normal variables.

Whats the use-case for NodeType.InitStatement

Hey folks, great work in this.

I am curious, there is a specific reason why the Program contains an InitStatement as it's start block ?

From a brief look I have had till now, this seems it can be removed from the AST, but would love to learn more on why is this designed like this :)

Feat : Ability to copy code on clicking

Description

Description: Currently in the documentation examples on-site and in the playground as well we don't have the ability to copy on click,

Proposed solution: to resolve this we can add a new button at the side of pre-existing buttons like "run" and "clear" named "copy" that will help users to copy the code of the playground that he/she wrote, and for examples in documentation, we can use the similar functionality that we use for GitHub or most other documentation sites that placing a small icon at the markdown example and by clicking on that icon show "copied on clipboard" .

image

Domain

UI/UX

Type of Contribution

Enhancement

Code of Conduct

Support for "Bata Bhai"

Hey all, I just got to know about this today.
Right now I don't see taking input as a feature. I want to propose a "Bata bhai" or "pooch bhai" statement to take input.

What say bhai log ?

how to run the project

i tried to run the project, installed turbo and ran 'turbo run dev --parallel' but local host not opening up, donno at which port is it running... can anyone help me out

Issue with playground code editor on bhailang.js.org

Description

  • Cursor position not proper wrt the word being typed.
  • Syntax highlighting makes other bigger smaller, i.e until a particular word is not keyword it's font size is incosistent with the font size of the keyword.

Requirements
Need the repository for the website.

Domain

Other

Type of Contribution

Enhancement

Code of Conduct

Memes!!

Hey folks,

A lot of memes related to bhailang are being shared online. If you are creating one, please share in this issue.
Les.. go! BhaiLang to the moon 🚀

Add support for 'beda gark'

Description

Add support for beda gark for try-catch bhai yeh kar, beda gark (try - catch)

bhai yeh kar
         bhai ye hai a = 10;
         bhai ye hai b = 10 + (15*20);
         bol bhai "b is greater than a";
beda gark (err)
         bol bhai err

Domain

Bhai Lang

Type of Contribution

Enhancement

Code of Conduct

Possible issue in static scope during multiple runs of the code.

Context: Scope of the entire program is statically set only once. This can potentially create a problem while re-running the code without refreshing the browser. The static scope will persist if the user doesn't refresh the browser tab.

I have observed this while testing:

While running multiple cases one after other, the variables in scope of previous test case were interfering with the current test case variables. To resolve this in testing, I did a scope reset before each test case.

Possible scenario demonstration:

Code 1:

hi bhai;
bhai ye hai a = 7;
bye bhai;

Code 2:

hi bhai;
bhai ye hai a = 30, b = 4;
bye bhai;

Let's say this code 1 runs in the browser and then user runs code 2 in the browser without refreshing the tab, the variable "a" from code 1 will persist in the scope and while running code 2, an error will be thrown.

Possible solution:

in interpret method:

interpret(code: string) {
  const ast = this._parser.parse(code);
  InterpreterModule.getVisitor(ast.type).visitNode(ast);
  InterpreterModule.setCurrentScope(new Scope(null)); // this will make sure that scope is reset after running the code.
}

Support for "Ya fir Bhai"

Description

this will be used in place of "else if"

agar bhai(condition) { // code here, for if part } ya fir bhai(another condition) { // more code here, for else if part } warna bhai{ // else part of code here }

this will help differentiate between, 2 if conditions and a single nested conditions

Domain

Bhai Lang

Type of Contribution

Enhancement

Code of Conduct

Support for error messages

Currently errors like "divide by zero" gives out message as "infinity".

There is potential here to expand on this, like -
"Bhai ye kya kiya"
"Bhai aise nahi hota"
"Bhai ye kya kar diya"

division by zero

Description

DivisionByZeroException

it shows Infinity

mere khayal se

bhai zero se divison kaha

and missing semi-colon ka

bhai semi-colon lga de

should be good......must change to something better if required

Domain

Bhai Lang

Type of Contribution

Refactoring

Code of Conduct

Help

Description

Hi bro .... I want to make my final year project like this one. Can you please help me how should I do it. Which resources should i follow. Please give me the guidence.

Thank you

Domain

Bhai Lang

Type of Contribution

Others

Code of Conduct

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.