Start here
Building Interpreters Step by Step
A staged plan for building a working interpreter for a small grid language, from loading the program to testing, with the decisions to settle at each stage.
Theory and Tools
Practical steps and pitfalls when building interpreters.
Start here
A staged plan for building a working interpreter for a small grid language, from loading the program to testing, with the decisions to settle at each stage.
How to handle division by zero, negative remainders and integer size in a small interpreter, with worked examples and advice on choosing and documenting behavior.
What an interpreter can do when an instruction needs more values than the stack holds: default to zero, halt with an error, or warn, and how to test each choice.
How to print each step of a grid program with pointer position, current cell and stack so you can see a run, with a small Python sketch and formatting tips.
Compare nested arrays, flat arrays, hash maps and sparse storage for a two-dimensional program grid, and learn which fits fixed or growing playfields.
How a compiler can turn the pointer paths of a grid program into ordinary code blocks, and why self-modifying code and direction-dependent cells make it hard.
How to deal with output buffering, end of input, and the difference between reading a character and reading a number when building a grid-language interpreter.
How to read a source file into a two-dimensional grid: splitting lines, padding short rows, and handling tabs, carriage returns and unusual characters.
A general look at speeding up a grid-language interpreter: measure first, precompute jumps, cache decoded cells, and keep the cache correct when code changes.
Build a ladder of tiny test programs that each isolate one instruction, with expected outputs, so you can trust and safely change your grid-language interpreter.
How the core loop of a grid-language interpreter reads a cell, acts on it and moves the pointer, with a small Python example and the order-of-operations details.
Related topics