The piece argues that programming languages feel more trustworthy and empowering when their tools are small enough for one person to build. It demonstrates this idea by constructing a compact JavaScript interpreter for a useful subset of PostScript, treating the language as a general-purpose programming system rather than focusing on its graphics features. PostScript programs are sequences of tokens evaluated through an operand stack and a dictionary stack: literal names and values can be pushed, definitions bind names to values, and invoking a procedure runs its contents. Arrays, procedures, numbers, booleans, names, dictionaries, operators, and stack marks are represented with ordinary JavaScript values or small wrappers.
The implementation proceeds from tokenizing and parsing programs to executing them, with procedures grouped during parsing and names resolved through nested dictionaries. A concise set of primitives supplies arithmetic, comparisons, stack manipulation, arrays, loops, conditionals, and definitions; operators are mostly straightforward functions that consume operands and return results. The result can be extended into a REPL with a simple output operator, turning the interpreter into a desk calculator. Examples show array iteration, user-defined operations such as absolute value and minimum, and both recursive and iterative Fibonacci calculations. The emphasis is on how a small interpreter’s pieces fit together, and on experimenting with additional language operators using the machinery already in place.
Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.