Errors
BrainRot Lang uses error recovery — the parser collects all errors instead of stopping at the first one. All errors follow a consistent [SKILL ISSUE] branded format.
Error Format
Every error in BrainRot Lang follows the same structure — a [SKILL ISSUE] header, followed by the error phase and the line number with a descriptive message.
# Every error follows this format:
[SKILL ISSUE]
[Runtime Error]
Line 3 → variable 'x' is ghosted (not defined)
# Parser errors use the same structure:
[SKILL ISSUE]
[Parser Error]
Line 5 → expected '}' but got 'EOF'Error Categories
| Category | When | Source |
|---|---|---|
| Parser errors | Token stream violates grammar rules | parser/parser.go |
| Runtime errors | Valid syntax but invalid execution | interpreter/ |
| CLI errors | Missing file argument or unknown command | main.go |
The lexer does not produce error messages directly — it emits ILLEGAL tokens for unrecognized characters, which the parser then reports as syntax errors.
Parser Errors
Parser errors occur when the token stream does not match the expected grammar. The parser uses error recovery — it continues parsing after an error to find additional issues in a single run.
# Missing closing brace
let_him_cook main() {
say_my_name("hello")
# Output:
# [SKILL ISSUE]
# [Parser Error]
# Line 4 → expected '}' but got 'EOF'# Bad for-loop initializer
let_him_cook main() {
run_it_back ("hello"; i < 10; i += 1) {
say_my_name(i)
}
}
# Output:
# [SKILL ISSUE]
# [Parser Error]
# Line 2 → expected variable declaration or assignment but got '"hello"'Runtime Errors
Runtime errors occur during AST interpretation — when the program is syntactically valid but semantically incorrect.
Undefined variable
let_him_cook main() {
say_my_name(x)
}
# Output:
# [SKILL ISSUE]
# [Runtime Error]
# Line 2 → variable 'x' is ghosted (not defined)Variable redeclaration
let_him_cook main() {
trust_me_bro x = 10
trust_me_bro x = 20
}
# Output:
# [SKILL ISSUE]
# [Runtime Error]
# Line 3 → variable 'x' already declared in this scope
# — you can't declare it twiceMissing main function
# No main function defined
trust_me_bro x = 42
say_my_name(x)
# Output:
# [SKILL ISSUE]
# [Runtime Error]
# Line 0 → no main() found — BrainRot Lang needs
# 'let_him_cook main() { ... }'Argument count mismatch
let_him_cook add(a, b) {
take_this a + b
}
let_him_cook main() {
say_my_name(add(1, 2, 3))
}
# Output:
# [SKILL ISSUE]
# [Runtime Error]
# Line 6 → function expects 2 args but got 3Calling a non-function
let_him_cook main() {
trust_me_bro x = 42
x(1, 2)
}
# Output:
# [SKILL ISSUE]
# [Runtime Error]
# Line 3 → '42' is not a function broArray out of bounds
let_him_cook main() {
trust_me_bro arr = [1, 2, 3]
say_my_name(arr[10])
}
# Output:
# [SKILL ISSUE]
# [Runtime Error]
# Line 3 → index 10 out of bounds (array length 3)CLI Errors
CLI-level errors are printed in red and use a distinctive meme message when no file argument is provided.
# No file argument provided:
$ brainrot run
# Output (in red):
# File nahi bhejega ke Meh kya ladle meow ghop ghop ghop
# Unknown command:
$ brainrot yeet
# Output:
# Unknown command: yeetAll Runtime Messages
Complete list of runtime error messages from the interpreter:
| Error | Cause |
|---|---|
variable 'x' is ghosted (not defined) | Using an undeclared variable |
variable 'x' already declared in this scope | Redeclaring a variable in the same scope |
++ / -- can only be used on variables | Postfix operator on a non-identifier |
++ / -- can only be used on integers | Postfix operator on a non-integer value |
index operator used on non-array value | Using [] on a non-array |
array index must be an integer | Non-integer array index |
index N out of bounds (array length M) | Index exceeds array size |
no main() found | Program has no let_him_cook main() |
'value' is not a function bro | Calling a non-function value |
function expects N args but got M | Wrong number of arguments |
function 'f' already defined at line N | Duplicate function definition |
not allowed outside main() | Statement outside a function or variable declaration |
Error Recovery
The parser implements error recovery by synchronizing on statement boundaries. When it encounters an unexpected token, it records the error and advances to the next statement start token (typically trust_me_bro, let_him_cook, chat_is_this_real, etc.) to continue parsing.
This means the parser reports all syntax errors in your program in a single run — you don't need to fix one error and re-run to discover the next one. Multiple errors are printed under a [PARSER ERRORS] header in red.