What is BrainRot Lang?

BrainRot Lang is a fully functional interpreted programming language built from scratch in Go. It replaces traditional programming keywords with internet meme slang — trust_me_bro instead of var, chat_is_this_real instead of if, let_him_cook instead of function.

Despite the meme syntax, BrainRot Lang is a complete, working language that demonstrates every major phase of compiler design — lexical analysis, syntax parsing, AST construction, and tree-walking interpretation.

Why an interpreter and not a compiler?

BrainRot Lang uses a tree-walking interpreter — after the source code is lexed and parsed into an AST, the interpreter executes the AST directly in memory. This is the same approach used by early Python and Ruby. The front-end pipeline (Lexer → Parser → AST) is identical to any compiler; only the back-end differs.

Compiler Pipeline

Every BrainRot program passes through four phases before producing output:

pipeline
Source Code (.brt) │ ▼ ┌─────────────┐ │ Lexer │ lexer/lexer.go │ │ Reads chars → Token stream └──────┬──────┘ │ [VAR][IDENT][ASSIGN][INT][EOF] ▼ ┌─────────────┐ │ Parser │ parser/parser.go │ │ Token stream → AST └──────┬──────┘ │ VarStatement{ Name:"x", Value:IntegerLiteral{42} } ▼ ┌─────────────┐ │ AST │ parser/ast.go │ │ Abstract Syntax Tree (20+ node types) └──────┬──────┘ │ ▼ ┌─────────────┐ │ Interpreter │ interpreter/evalStmt.go │ │ Tree-walks AST → executes directly └──────┬──────┘ │ ▼ Terminal Output

The Lexer implements a DFA (Deterministic Finite Automaton) to scan source characters into tokens. The Parser uses Recursive Descent to build an AST from the token stream. The Interpreter tree-walks the AST, maintaining an Environment (symbol table) for variable scoping.

Quick Example

Here is a complete BrainRot program that declares a variable, prints a greeting, and uses conditional logic:

hello.brt
let_him_cook main() { trust_me_bro name = "world" say_my_name("Hello, " + name + "!") chat_is_this_real (1 == 1) { say_my_name("fr fr this is real") } nah_bro { say_my_name("cap") } }

How It Works

The interpreter evaluates this program by:

  1. Lexing — scanning let_him_cook, trust_me_bro,say_my_name, etc. into a flat token list.
  2. Parsing — building a tree: FuncDecl → VarDecl → PrintStmt → IfStmt
  3. Interpreting — calling main(), binding name = "world", printing, then evaluating the condition.