This page goes into some more detail about PostScript as a programming language. It discusses the use of operators, dictionaries and the stack.
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.
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.