Let's Write a PostScript Interpreter

(beyondloom.com)

63 points | by RebelPotato 2 days ago ago

11 comments

  • a4isms 37 minutes ago

    My very first professional gig in the mid-80s was on a classified ad-taking application for what were then called penny-savers, physical newspaper-like publications that were nearly 100% classifieds. Penny-savers would be distributed in boxes around urban centres and could be very profitable. Our app ran on MP/M, a multi-user CP/M variant. And when it was time to go to print, our code generated PS directly, there was no "printer driver" or abstraction of any kind.

    We sold our customers two Apple LaserWriters each, because if one went down just before going to print they'd be screwed. We would print on both in parallel for speed, but could fall back to just one. And the printed ads? Somebody over in the print shop would cut them out in strips and then paste those strips up to be photographed for the printing press. We didn't have full end-to-end digital yet.

    PS wasn't easy, but it was very grokkable.

  • fjfaase 13 minutes ago

    Nice page. In 2009, I wrote ('hacked together') a partial PostScript interpreter in C to debug some PostScript code I was writing to reproduce plate 13 from the Eléments de l'art arabe by Jules Bourgoin as reproduced in Arabic Geometrical Pattern & Design.

    Program: https://www.iwriteiam.nl/PostScript_c.txt

    PostScript file with first 31 plates: https://www.iwriteiam.nl/Bourgoin.ps

    I do not know why I stopped at that point. Maybe it was because I realized that I should have used another approach to describe the geometric patterns and did not want to refactor all the PostScript I already wrote. But it might also that I got obsessed with another problem.

  • glkindlmann 4 hours ago

    I tried to write (in C) a PostScript byte compiler for a grad school project. It is a very appealing language to work with, with the simplicity of stack machine. And like with this post, I didn't get into the graphical elements that make PostScript useful.

    Mainly I learned that Ghostscript is doing a lot to make its PostScript interpreter fast: with the non-graphical test programs I could think up, GhostScript was many times faster interpreting the program (even computationally intensive ones) than my runtime (called "egon") could execute the byte-compiled PostScript. So it was a computation fail but still a pedagogy win.

    I've always been meaning to learn more about how Ghostscript is engineered.

  • ptspts 3 hours ago

    Shameless self-promotion: I wrote a Deflate (gzip with a different header) decomressor in PostScript in the early 2000s. https://github.com/pts/pts-zcat/blob/master/zcattiny.ps . There are more readable versions of it in the same repo.

  • nedbat 2 hours ago

    I worked a ton with PostScript back in the day. A few years ago I implemented an interpreter in Python, including graphics with PyCairo: https://github.com/nedbat/stilted

    It was a really good vacation-week project! :)

  • tacostakohashi 3 hours ago

    I used ps / gs quite a bit for a few years as part of work early in my career... 20 years ago. I rather enjoyed it.

    I had always hoped I could work more in that area later on... like either writing printer drivers, printer firmware, work at artifex/ghostsript, etc. Unfortunately though, it seems like employers really don't hire for specific skills/domains like that, they just hire generic embedded / software developers and put them to work on postscript or whatever else they have after the fact. Oh well.

  • Renina a day ago

    Writing a tiny interpreter is one of those exercises that teaches you more about programming languages than months of just using them

  • TacticalCoder 4 hours ago

    I still mess with PostScript once in a while. For example I generate little puzzles for my daughter/nephews (words to find in an hexagonal grid, where each hexagon contains one letter): wrote that in Clojure but it generates PostScript (nowadays I could ask a LLM to write the whole thing for me though as the potential for disaster is limited).

    Then there's that one utility company who screws up my montly invoice and so, invariably, when I need to do KYC for whatever bullshit-state-surveillance reason (which, invariably, happens all the time), KYC fails for my official address doesn't match the technical address the utility company is using on my invoices.

    So the PDF gets converted to PostScript, I edit the PostScript, and convert back to PDF. Nowadays I take it I could also have a LLM do it all for me but the thing is: I don't want my PDF to look like a PDF which has been tempered with (which it definitely has been, but fuck KYC and screw that utility company for not using my proper official address). So I like the PDF to PostScript to edit back to PDF cycle.

  • throwaway81523 a day ago

    This is a yawner, Postscript (the language) is very simple, given run of the mill interpreter machinery. An actual working Postscript implementation is about graphics and font rendering, not the language interpreter. That stuff is still not trivial.

    • cmrx64 5 hours ago

      the amount of care to detail in the base language is great though. reading PLRM is a joy

    • viraptor 5 hours ago

      Yet, it's going to be novel fun for some people. Let's celebrate today's lucky 10000. https://xkcd.com/1053/