Skip to content
Back to the catalog
Project mini-compilerLanguagesExpertBeta

A mini compiler to bytecode

From source code to runnable bytecode. Lexing, AST, semantic analysis, code generation and a VM that runs it.

Build it in your language

The tester treats your program as a black box: any language works. These are just the most convenient ones for this project.

Guide language

The stage guides read in this language. Only languages this project is fully translated into show up here; the interface language does not change.

What this project is about

This is the longest challenge in the catalog and the one that brings the most together: your own language, with its compiler and its virtual machine, built end to end.

You'll go from text to tokens, from tokens to a tree, from the tree to a type-checked representation, from there to bytecode and, finally, to a stack machine that executes it. You'll finish running programs written in a language you designed yourself.

Roadmap

16 stages across 4 phases. Every stage comes with its guide and its tests: you move on when they pass.

  1. Phase 15 stages

    The frontend

    Lexer, a parser with precedence, and the language's syntax tree.

    1. 01Tokens
    2. 02Expressions
    3. 03Statements
    4. 04Control flow
    5. 05Functions in the AST
  2. Phase 24 stages

    Understanding the program

    Name resolution, scopes, type checking and useful errors.

    1. 01Symbol table
    2. 02Type checking
    3. 03Flow analysis
    4. 04Useful diagnostics
  3. Phase 34 stages

    Generating bytecode

    Instruction set, constants, jumps, and compiling the tree.

    1. 01Instruction set
    2. 02Compile expressions
    3. 03Jumps and patching
    4. 04Compile functions
  4. Phase 43 stages

    Running it

    Stack virtual machine, call frames, functions and optimisations.

    1. 01Stack VM
    2. 02Call frames
    3. 03Optimisations

Before you start

A complete compiler and its runtime: a lexer, a parser with operator precedence, a syntax tree, name resolution and type checking, bytecode generation, a stack virtual machine with call frames, first-class functions, and a couple of measurable optimisations.

  • lisp-interpreter
    Beta

    A Lisp interpreter

    Tokenizer, parser, evaluator and closures. Discover how a language runs your code, step by step.

    Advanced11 stages~16 hLanguages
    parsingastclosures+1

    Python · JavaScript · TypeScript

  • json-parser
    Beta

    A JSON parser

    Your first contact with lexers and grammars. Tokenize, build the tree and fail with useful errors.

    Beginner7 stages~6 hLanguages
    tokenizerparsingrecursión

    TypeScript · Python · Go · Java

  • regex-engine
    Beta

    A regular expression engine

    From the expression to the automaton. Backtracking, groups and character classes without your language's regex.

    Advanced8 stages~11 hLanguages
    autómatasparsingbacktracking

    TypeScript · Python · Rust