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.

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 programs must end with bye bro. Anything outside of these boundaries will be ignored.
example.bro
This will be ignored

hi bro
 // Write code here
 say bro "Hello from Bro-code!";
bye bro

This will be ignored too
  
Variables
Variables can be declared using bro this is. Re-assignments and compound assignments are fully supported.
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 & Literals
Supported primitive types include Numbers (integers & floats), Strings, Null (nope), and Booleans (yep for true, nah for false).
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
  
Operators
Supports arithmetic (+ - * / %), equality (== !=), relational (> < >= <=), logical (&& ||), and compound assignments (+= -= *= /= %=).
example.bro
hi bro
 bro this is x = 10;
 bro this is y = 3;

 say bro "Sum:", x + y;
 say bro "Modulo:", x % y;
 say bro "Check:", x > y && y != 0;

 x += 5;
 say bro "Updated x:", x;
bye bro
  
Built-in I/O
Use say bro to print expressions and comma-separated values to the console.
example.bro
hi bro
 say bro "Hello World";
 bro this is a = 10;
 {
  bro this is b = 20;
  say bro "a + b =", a + b;
 }
 say bro 5, 'ok', nope, yep, nah;
bye bro
  
Conditionals
Bro-code supports if bro, else if bro, and else bro branches evaluating boolean conditions.
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
Use while bro to loop while a condition is yep. Use stop bro to break out or next bro to jump to the next iteration.
example.bro
hi bro
 bro this is a = 0;
 while bro (a < 10) {
  a += 1;
  if bro (a == 5) {
   say bro "inside loop:", a;
   next bro;
  }
  if bro (a == 6) {
   stop bro;
  }
  say bro a;
 }
 say bro "done";
bye bro
  
Blocks & Scope
Blocks created with { } establish local lexical scopes. Variables declared within inner blocks shadow outer variables.
example.bro
hi bro
 bro this is msg = "outer";
 {
  bro this is msg = "inner";
  say bro "Inside block:", msg;
 }
 say bro "Outside block:", msg;
bye bro