Building compilers
Maxim Mozgovoy · 2026
This chapter demonstrates how the theoretical concepts of parsing are applied in practice by building a complete interpreter for a custom mini-language TinyCode. Using the compiler-compiler tool Coco/R, the chapter walks through the entire compiler pipeline: creating a scanner from token definitions (a regular language), building a parser from an EBNF specification (a context-free grammar), and implementing a code generator via embedded semantic actions. The compiler translates TinyCode source into a simple stack-based intermediate representation known as “threaded code,” which is then executed by a custom virtual machine, completing the journey from a declarative language specification to a working program.