% This file was converted from HTML to LaTeX with Nathan Torkington's
% html2latex program
% Version 0.9b
\chapter{Language Concepts}

As a programming language, PostScript is particularly simple.  There 
are really only a few concepts that need to be sketched out.

\begin{description}
\item[{\bf Comment}]
A comment in PostScript is any text preceded by a `\%'.  The special 
comment `\%!' as the first two characters of a PostScript program is 
seen as a tag marking the file as PostScript code by many systems 
(including Unix's lpr command).  It is a good idea to start every 
PostScript document with a `\%!'...  doing so will ensure that every 
spooler and printer the document may encounter will recognize it as 
PostScript code.

\item[{\bf Stack}]
There are several stacks in a PostScript system, but only two are 
important for this guide: the operand stack, and the dictionary stack.  
The operand stack is where arguments to procedures (or operators, in 
PostScript jargon) are pushed prior to use.  The dictionary stack is 
for dictionaries, and it provides storage for variables.

\item[{\bf Dictionary}]
A dictionary is a collection of name-value pairs.  All named variables 
are stored in dictionaries.  Also, all available operators are stored 
in dictionaries along with their code.  The dictionary stack is a 
stack of all currently open dictionaries.  When a program refers to 
some key, the interpreter wanders down the stack looking for the first 
instance of that key in a dictionary.  In this manner, names may be 
associated with variables and a simple form of scoping is implemented.  
Conveniently, dictionaries may be given names and be stored in other 
dictionaries.

\item[{\bf Name}]
A name is any sequence of characters that can not be interpreted as a 
number.  With the exception of spaces and certain reserved characters 
(the characters `(', `)', `[', `]', `$<$', `$>$', `\{', `\}', `/', and 
`\%') any character may be part of a name.  The name may even start 
with digits (1Z is a name, for example), but you can get into problems 
with them (1E10 is a real number).  A name is seen as being a 
reference to some value in a dictionary on the dictionary stack.
 
If a name is preceded by a slash, PostScript will place the name on 
the stack as an operand.  If the name has no slash, the interpreter 
will look up its value in the dictionary stack and push the value on 
the operand stack.

\item[{\bf Number}]
PostScript supports integers and reals.  You can express numbers in 
two forms: radix form, and scientific notation.  Radix form is a 
number of the form {\it radix}\#{\it value} where {\it radix} 
specifies the base for {\it value}.  Scientific notation is the 
standard {\it mantissa}E{\it exponent} form used in most languages.

\item[{\bf String}]
Strings are, of course, just strings of characters.  There are two 
ways of expressing strings in Level 1 PostScript.  The most common way 
is to wrap your text in parentheses.  For example the string 
``This is a string'' would be written as \code{(This is a string)}.  
You can also express a string as hexidecimal codes in angle brackets.  
For example, the string ``ABC'' would be expressed as 
\code{<414243>}.  There are several escape codes that may be used in the 
parenthesis format of strings.

\item[{\bf Array}]
Arrays in PostScript are like arrays in any other language.  Arrays 
may contain objects of different type, and they are written as a list 
of objects surrounded by brackets.  For instance, \code{[12 /Foo 5]} 
is a three element array containing the number 12, the name Foo, and 
the number 5.

\item[{\bf Procedure}]
A procedure is your way of defining new operators.  A procedure is an 
array that is executable and is written with braces rather than 
brackets.  For example, a procedure to square the top element on the 
stack might be written as: \code{\{dup mul\}}.  We can define this 
procedure to be the square operator with: \code{/square \{dup mul\} 
def}.
\end{description}
