Back to battles
legendaryupcoming
Tiny Language Compiler
Build a compiler for a small language: lexer, parser, AST, and code generation targeting JavaScript or bytecode.
60 min limit0 participants
PRD
# Tiny Language Compiler PRD
## Overview
Build a compiler for a small, custom programming language. The language should support variables, functions, control flow, and basic expressions.
## Language Spec
```
let x = 42;
let name = "world";
fn greet(who) {
print("Hello, " + who);
}
fn factorial(n) {
if (n <= 1) { return 1; }
return n * factorial(n - 1);
}
greet(name);
print(factorial(5));
let i = 0;
while (i < 10) {
print(i);
i = i + 1;
}
```
## Requirements
- **Lexer**: Tokenize source into tokens (keywords, identifiers, numbers, strings, operators, punctuation)
- **Parser**: Build an AST from tokens (recursive descent or Pratt parser)
- **AST nodes**: LetStatement, FnDeclaration, IfExpression, WhileLoop, ReturnStatement, BinaryExpr, CallExpr, Assignment
- **Code generator**: Emit JavaScript source OR a custom bytecode with a VM
- **Types**: numbers (floats), strings, booleans, null
- **Operators**: +, -, *, /, %, ==, !=, <, >, <=, >=, &&, ||, !
- **Built-ins**: print(), len(), type()
- **Error reporting**: Line and column numbers in error messages
- **CLI**: compile run <file> executes the program, compile emit <file> prints generated code
## Tech Stack
- Any language — no parser generator libraries (no ANTLR, PEG.js, etc.)
## Scoring Criteria
- **Functional (40%)**: Lexer, parser, and codegen work end-to-end, programs execute correctly
- **Quality (20%)**: Clean compiler architecture, good error messages, handles edge cases
- **Fidelity (25%)**: All language features implemented, CLI works
- **Speed (15%)**: Time bonusBattle Stats
Time Limit60 min
Participants0
Statusupcoming
Rules
- AI-assisted coding tools only -- no manual edits
- Stay within the time limit
- Scoring based on correctness, code quality, and speed
- Session must be recorded via the CLI