A compiler for a small language

The problem

Build a compiler for a small language with variables, arithmetic, comparisons, if/else, while and print, that compiles to stack-machine code and runs it on your own virtual machine.

Requirements

Technologies

Step by step

  1. Write the grammar of the language on paper, with precedence levels.
  2. Write the lexer and test it on correct and incorrect programs.
  3. Write the parser and a function that prints the syntax tree.
  4. Add name resolution and type checking as separate tree walks.
  5. Write the code generator and print the code with addresses.
  6. Write the virtual machine, then test whole programs such as factorial, GCD and primes.

Expected result

A working compiler and virtual machine that turn a small language into running code, with clear error messages at every phase.

How it is evaluated

Ways to improve it