RPN Loved Honk If (or, Write Your Own PostScript Interpreter)

Maybe you like old laser printers. Maybe you were a fan of [Don Lancaster]. Maybe you like Forth, HP calculators, and everything RPN. Whichever it is, why not write your own PostScript interpreter? That’s what [beyondloom] did (and we shamelessly stole their joke for the post title, too).

PostScript started out as a language to describe pages for laser printers but went on to have a life of its own, including a stripped-down version being at the core of PDF files. If you are a fan of RPN, you’ll love PostScript, which operates on several stacks.

The example interpreter is in JavaScript and handles a subset of PostScript with little error handling. Still, it manages an operand stack, a dictionary stack, and arrays. Of course, if you just want to try PostScript, there’s always Ghostscript. But there’s something charming about a practical interpreter that is tiny and understandable, even if it does gloss over a few deep features.

If you want to see the original PostScript, the source code is out there. If you don’t think PostScript is really a language, check out this chess program (the first link is dead, but the GitHub link remains). Or, perhaps you prefer Doom.

12 thoughts on “RPN Loved Honk If (or, Write Your Own PostScript Interpreter)”

  1. Years ago I got yelled at by a colleague who was struggling with my borrowerd 11c. I explained about RPN. They got angry and indignant because they thought I was making a slight about their Polish heritage. I wish I was making that up.

    1. Lukasiewicz (I think) invented it. Mathematics and Poland seem to go well together.

      We had to build interpreters for all three (prefix, postfix, and infix) methods in my Algorithms course.

  2. Postscript was an enhanced version of FORTH, originally developed for the IBM 1130. Being extremely lightweight, as well as simple to implement, it got a lot of use on 8-bit micros in the 70’s and 80’s. For fun, I once implemented a small FORTH interpreter in a few dozen lines of S/370 assembler.

  3. HP 41C emulator* (V41) on all my computers. SO much easier to use than the defaults. i41cx on my iPhone. The only thing I miss is the wonderful key feel. Back when HP was the undisputed quality leader.

    *I have a real one in my desk drawer

    1. +1

      V41 is a great emulator once your fingers learn the key positions.

      I bought an HP41C in 1981 (and XFUN, TIME, XMEM, and card reader modules). I still have it, it still works, but my 32SII is the daily driver. The “re-imagined” 15C Limited Edition is just a sad reminder of the company downfall.

  4. We built a scanner/printer with PostScript, and had it process hand checked forms and 2d bar codes using inverse imaging libraries. it went in a few MFD (copy/fax/scanners). About 20kloc PostScript, most of it written in PdB, which was shared source with the original Java compiler.

    1. i thought the same thing at first… in forth, IF and THEN are typically extremely simple “IMMEDIATE” words that work on a stack of pointers into the generated code, and they have the syntax you’re expecting. but forth is just one example of an RPN-oriented language…there’s another perspective that says RPN “IF” should be a regular word with signature ( bool then — ). it pops ‘bool’ and calls function ‘then’ if the bool was true. i’ve done it both ways, myself.

      and postscript happens to do the latter. though i’m not clear what kind of object the ‘then’ is. in my case it was a function pointer but it looks a little different in postscript.

  5. The original bumper sticker from Mountain View Press had a red heart for “love” and went

    FORTH LOVE IF HONK THEN

    I always explained the FORTH IF THEN as Condition IF truepart THEN Continue, Or as Condition IF truepart ELSE falsepart THEN Continue.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.