Let's Write a PostScript Interpreter
Web page · https://beyondloom.com/blog/postscript.html
First seen by Oriel on .
AI summary
This article builds a concise JavaScript interpreter for a practical subset of PostScript, explaining its tokenization, stack-based execution model, primitive operators, REPL, and programming trade-offs.
- PostScript uses operand and dictionary stacks: names resolve through dictionaries, procedures execute retrieved tokens, and operators consume and produce stack values.
- The interpreter represents PostScript values with JavaScript primitives, parses procedures and arrays, and executes them through concise global-stack routines.
- Primitive operators implement arithmetic, comparisons, control flow, arrays, dictionaries, stack manipulation, and iteration, while user definitions extend the language with PostScript procedures.
- Node.js and QuickJS REPLs provide interactive calculation, including examples for Fibonacci, array reversal, concatenation, and Forth-inspired stack words.
- The subset omits strings, graphics, robust error handling, several datatypes, and lexical scope; dynamic dictionary scopes complicate higher-order functions and local state.
#postscript #javascript #interpreters #concatenative programming
Generated by gpt-5.6-sol. Check the original for details.
Metric trends
Last 30 days · Up to 120 recorded samples per source and metric, with reposts kept separate · First and latest retained
Points
Score reported by the source.
- Hacker News: 130, latest observation ; +120 over observed period since
- Lobsters: 28, latest observation ; +26 over observed period since
Comments
Comment count reported by the source.
- Hacker News: 22, latest observation ; +18 over observed period since
- Lobsters: 4, latest observation ; +4 over observed period since
Aliases
| Source | External ID | URL |
|---|---|---|
| Hacker News | 50478632 | https://beyondloom.com/blog/postscript.html Read discussion |
| Lobsters | 8kdcdd | https://beyondloom.com/blog/postscript.html Read discussion |