Language specific details

This page goes into some more detail about PostScript as a programming language. It discusses the use of operators, dictionaries and the stack.

Operators

Every computer language has a number of predefined commands.In PostScript, these are called operators. Here are a couple of examples of PostScript operators:

div – divide two numbers
lineto – draw a line
setlinewidth – defines the thickness of lines
showpage – print the currently processed page

There are hundreds of operators in the PostScript language and an application can even add its own. For example: PostScript does not contain a specific command to draw a rectangle but a drawing application might need such a command. Within PostScript, that application can define its own ‘box’ operator that combines four ‘lineto’ commands to draw a rectangle. This way the application can add the functionality it needs to the PostScript command set.

The fact that applications (or spoolers, OPI-systems or drivers) can create their own operators makes PostScript code difficult to debug. If something goes wrong with a specific operator, it can be difficult to find out which application added the buggy code.

Dictionaries

Groups of operators can be stored in a dictionary. A lot of applications as well as printer drivers use their own dictionaries. If you print a page from QuarkXPress to a printer, both the printer driver that is used as well as QuarkXPress itself add their dictionaries to the PostScript data that are send to the output device. Sometimes these extra data cause problems. That is why it is often a good idea to change drivers or omit any extra steps in the output process to troubleshoot PostScript errors.

A stack based language

PostScript is a stack based language which works similar to calculators that use Reverse Polish Notation. HP is famous for selling such calculators. Suppose you want to add 12 to 15. In PostScript this is done like this:

15 12 add

First both numbers are ‘push’ed on the stack. Then the interpreter reads the ‘add’ operator which tells it to ‘pop’ the two upper numbers from the stack, add them up and ‘push’ the resulting value back onto the stack.

Needless to say, RPN makes it much more difficult for us mere humans to look at PostScript code and make any sense of it.

4 thoughts on “Language specific details

  1. Thank you for making this site in real html, NOT pdf!! Yes, pdf is a necessary evil in the print world, but whenever I come across pdf online, I search for a better, more user-friendly format, like html or rtf.

    1. I have just modified this site’s CSS file so that it hopefully offers better print output. Generating PDF from a WordPress site still seems to be a fairly obscure art but by offering decent print output, hopefully creating your own PDF’s from these pages also isn’t that difficult.

    1. Thanks for the suggestion.
      Until recently that was simply impossible as the site was based on static HTML. With the new redesign, there is more flexibility to repurpose the content. I took a quick look and there are 2 WordPress plug-ins to generate PDF. My primary focus now is on extending the scope of the site but once that is finished, I’ll definately look into a PDF version of the content again.

      The best PDF about PostScript is of course the Adobe Red Book – http://partners.adobe.com/public/developer/ps/index_specs.html

Comments are closed.