I built a PostScript interpreter from scratch in Python
I've been working on PostForge, a PostScript Level 2 interpreter written in Python. It parses and executes PostScript programs and renders output to PNG, PDF, SVG, TIFF, or an interactive Qt display window.
PostScript is a fascinating language from a CS perspective — it's a stack-based, dynamically-typed, Turing-complete programming language that also happens to be a page description language. Building an interpreter meant working across a surprising number of domains: \- **Interpreter** **design** — operand stack, execution stack, dictionary stack, save/restore VM with dual global/local memory allocation \- **Path** **geometry** — Bezier curve flattening, arc-to-curve conversion, stroke-to-path conversion, fill rule insideness testing \- **Font** **rendering** — Type 1 charstring interpretation (a second stack-based bytecode language inside the language), Type 3 font execution, CID/TrueType glyph extraction \- **Color** **science** — CIE-based color spaces, ICC profile integration, CMYK/RGB/Gray conversions \- **Image** **processing** — multiple filter pipelines (Flate, LZW, DCT/JPEG, CCITTFax, ASCII85, RunLength), inline and file-based image decoding \- **PDF** **generation** — native PDF output with font embedding and subsetting, preserving color spaces through to the output The PostScript Language Reference Manual is one of the best-documented language specs I've ever worked with — Adobe published everything down to the exact error conditions for each operator.