Computer Science · intermediate

Compile a Tiny Language to WebAssembly

A compiler for a small expression language — lexer, parser, type checker, and a code generator that emits real WebAssembly binaries that run in the browser and in Node. You will understand what happens between source code and the machine.

Project overview

WebAssembly is production-ready in 2026 across browsers, serverless runtimes, and plugin systems, and a compiler that targets it proves you understand language design, runtimes, and binary formats in one artifact. It is the project that makes interviewers stop and ask questions.

Real-world use case

A product wants users to write safe custom formulas that run at native speed in the browser. Your language compiles to Wasm and runs in a sandbox with no eval and no server round trip.

Tools and technologies

Skills you can demonstrate

Compiler Construction, Parsing and ASTs, Type Checking, Code Generation, WebAssembly

Build roadmap

  1. Define the language
    Write the grammar for expressions, variables, if/else, and while. Keep it small. Write ten example programs with expected outputs before writing any code.
  2. Build the lexer and parser
    Hand-write a tokenizer and a recursive-descent parser producing an AST. Test each grammar rule with a tiny program.
  3. Add a type checker
    Walk the AST and assign types. Reject programs that mix types or use undeclared variables, with line numbers in the error.
  4. Emit WebAssembly text first
    Generate WAT (the text format) from the AST and assemble it with WABT. Run it in Node. This proves your codegen logic before the binary work.
  5. Emit the binary directly
    Replace the WAT step with your own binary encoder — sections, LEB128 integers, opcodes. Validate with wasm-validate until it passes.
  6. Build the playground
    A single web page with an editor, a compile button, and output. Deploy it and link it from the README next to a diagram of the pipeline.

Ways to extend the project

Add functions and recursion, then a small standard library, then compile a recursive Fibonacci and benchmark it against JavaScript.

How to showcase your work

Open this project in BuildersBenchBrowse Computer Science projects