BroCode

Toy language, real parser
Bro-Codetypescript, but make it bro

A playful programming language written in Typescript with its own parser, interpreter, and CLI.

Installnpm i -g brocode

Playground

Run Bro-code snippets instantly and inspect output in the embedded terminal.

Sheeeesh bro 🎉

Examples & Docs

Bro-code is a dynamically typed toy language powered by a parser and interpreter written in Typescript. Use these examples as a quick map of the language.

General
hi bro is the entrypoint for the program and all program must end with bye bro. Anything outside of it will be ignored.
example.bro
This will be ignored

hi bro
// Write code here
bye bro

This too
  
Variables
Variables can be declared using bro this is.
example.bro
hi bro
  bro this is a = 10;
  bro this is b = "two";
  bro this is c = 15;
  a = a + 1;
  b = 21;
  c *= 2;
bye bro
  
Types
Numbers and strings are like other languages. Null values can be denoted using nope. yep and nah are the boolean values.
example.bro
hi bro
  bro this is a = 10;
  bro this is b = 10 + (15*20);
  bro this is c = "two";
  bro this is d = 'ok';
  bro this is e = nope;
  bro this is f = yep;
  bro this is g = nah;
bye bro
  
Built-ins
Use say bro to print anything to console.
example.bro
hi bro
  say bro "Hello World";
  bro this is a = 10;
  {
    bro this is b = 20;
    say bro a + b;
  }
  say bro 5, 'ok', nope , yep , nah;
bye bro
  
Conditionals
Bro-code supports if-else-if ladder construct , if bro block will execute if condition is yep, otherwise one of the subsequently added else if bro blocks will execute if their respective condition is yep, and the else bro block will eventually execute if all of the above conditions are nah.
example.bro
hi bro
  bro this is a = 10;
  if bro (a < 20) {
   say bro "a is less than 20";
  } else if bro ( a < 25 ) {
   say bro "a is less than 25";
  } else bro {
   say bro "a is greater than or equal to 25";
  }
bye bro
  
Loops
Statements inside while bro blocks are executed as long as a specified condition evaluates to yep. If the condition becomes nah, statement within the loop stops executing and control passes to the statement following the loop. Use stop bro to break the loop and next bro to continue within loop.
example.bro
hi bro
  bro this is a = 0;
  while bro (a < 10) {
   a += 1;
   if bro (a == 5) {
    say bro "inside say bro ", a;
    next bro;
   }
   if bro (a == 6) {
    stop bro;
   }
   say bro a;
  }
  say bro "done";
bye bro