MiniLang
MiniLang is a from-scratch compiler, static analyzer, and bytecode interpreter for a small imperative programming language, built in C++17, with an in-browser playground powered by WebAssembly.
THE APP CAN BE ACCESED AND TEST AT: https://minilang.bhalla.info
What's here
- A hand-written lexer and recursive-descent parser (no parser
generator in the shipped build — see
docs/design-log.md) - A type checker that catches type mismatches, undefined references, and argument/return errors with precise source locations
- A static analyzer that flags use-before-initialization, unreachable code, unused variables, and literal overflow risk as Clang-Tidy-style warnings
- A stack-based bytecode compiler and VM
- A WebAssembly build of the whole pipeline, driving a browser playground with a code editor, AST viewer, diagnostics panel, and bytecode disassembly view
Quick start
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build
./build/src/cli/minilangc examples/fibonacci.ml
Language at a glance
// Compute the nth Fibonacci number iteratively.
func fib(n: int) -> int {
int a = 0;
int b = 1;
while (n > 0) {
int next = a + b;
a = b;
b = next;
n = n - 1;
}
return a;
}
func main() -> void {
print(fib(10));
}
The full grammar is specified in docs/grammar.md.
Architecture
source (.ml)
|
v
+--------+ +--------+ +--------------+ +-----------------+
| Lexer | --> | Parser | --> | Type Checker | --> | Static Analyzer |
+--------+ +--------+ +--------------+ +-----------------+
| |
v v
AST (shared) ------------------------> diagnostics
|
v
+------------------+ +----+
| Bytecode Compiler| --> | VM | --> program output
+------------------+ +----+
The CLI (minilangc), the GoogleTest suite, and the WebAssembly bridge all
drive this same compiler core in include/minilang/ and src/minilang/ —
the browser playground is a thin client, not a reimplementation.
Playground
The web/ directory contains a CodeMirror-based playground that compiles
and runs MiniLang entirely client-side via WebAssembly — no server round
trip. See web/README.md to run it locally.
Design decisions
Key trade-offs (hand-written parser vs. generator, stack-based vs.
register-based bytecode, why type checking and static analysis are separate
passes) are documented as they were made in docs/design-log.md.
License
MIT — see LICENSE.
Log in or sign up for Devpost to join the conversation.