Skip to content

Repository files navigation

Bro-code

Deploy to GitHub Pages License: MIT TypeScript

Bro-code is a toy programming language written in TypeScript with its own custom tokenizer, recursive-descent parser, AST, and tree-walking interpreter.

Quick start (language)

Minimal program:

hi bro
  say bro "Hello bro";
bye bro

Expected output:

Hello bro

Language reference

1. Program boundaries

Every executable program starts with hi bro and ends with bye bro. Anything outside those boundaries is ignored.

This will be ignored

hi bro
  // code here
bye bro

This too

2. Comments

  • Single-line comments: // ...
  • Multi-line comments: /* ... */
hi bro
  // single line comment
  /*
    multi line comment
  */
  say bro "comments work";
bye bro

3. Variables

Declare variables with bro this is.

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

4. Types and literals

  • Number: 10, 20.5
  • String: "hello", 'hello'
  • Null: nope
  • Boolean true: yep
  • Boolean false: nah
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

5. Output

Use say bro to print values.

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

6. Operators

Supported operators include:

  • Arithmetic: +, -, *, /, %
  • Assignment: =, +=, -=, *=, /=, %=
  • Equality: ==, !=
  • Relational: >, <, >=, <=
  • Logical: &&, ||

Notes:

  • String concatenation is supported with +.
  • Arithmetic with nope or boolean values can throw runtime errors.
  • Division by zero throws a runtime error.

7. Conditionals

Use if bro, else if bro, and else 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

8. Loops

Use while bro for loops.

  • stop bro breaks the loop.
  • next bro continues to next iteration.
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

9. Scope

Blocks create scope with { ... }.

hi bro
  bro this is a = 10;
  {
    bro this is b = 20;
    say bro a + b;
  }
bye bro

Architecture overview

Bro code follows a modular pipeline:

  1. Tokenizer converts source code into tokens from grammar spec.
  2. Parser builds an AST from the token stream.
  3. Interpreter evaluates AST nodes using node-type visitors.
  4. Playground (web app) runs code in-browser via interpreter package.
flowchart LR
  A[Bro code source] --> B[Tokenizer]
  B --> C[Parser]
  C --> D[AST]
  D --> E[Interpreter visitors]
  E --> F[Runtime output]
Loading

Monorepo layout

  • apps/docs: Next.js docs + playground UI.
  • packages/parser: grammar, tokenizer, parser, AST node definitions.
  • packages/interpreter: runtime evaluator and scope handling.
  • packages/cli: command-line entrypoint for local file execution.
  • packages/config: shared ESLint config package.
  • packages/tsconfig: shared TypeScript config package.

Technical details

Core design choices

  • Language implementation is fully in TypeScript.
  • Parser and interpreter are separated into independent packages.
  • Interpreter uses visitor dispatch by AST node type.
  • Runtime scope is reset after each interpretation cycle.
  • Turborepo manages builds, tests, and package orchestration.

Runtime characteristics

  • Dynamically typed runtime semantics.
  • Block-scoped variable behavior.
  • Explicit runtime exceptions for invalid operations.
  • Control flow support for conditional branches and loops.

Local development

Prerequisites

  • Node.js >= 18
  • npm >= 7

Installation

git clone https://github.com/ClaudeMaxUser/bro-code.git
cd bro-code
npm install

Scripts

# Start local docs & playground development server
npm run dev

# Run all test suites across packages
npm run test

# Lint all workspaces
npm run lint

# Build all packages & export docs site
npm run build

# Format code with Prettier
npm run format

Links

License

MIT

About

Bro Code is a toy programming language built with TypeScript, featuring a custom tokenizer, parser, and AST interpreter, plus a browser playground for running code snippets.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages