Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Reid G.C.Thinking in PostScript.1990.pdf
Скачиваний:
17
Добавлен:
23.08.2013
Размер:
846.44 Кб
Скачать

Chapter 5

Understanding the Stack

The operand stack is the central mechanism in the PostScript language. All data are placed on the operand stack at one time or another during the execution of your program. The operand stack holds PostScript language objects, which are the basic representation for all data types in a PostScript program, including procedures and instructions.

A QUICK OVERVIEW OF DATA TYPES

All PostScript data types are represented by a single object. There are three varieties: simple objects like integers, reals, marks, and booleans; composite objects (like arrays and strings) that will not fit into an object; and some special types that behave like simple objects but which have some internal structure that you can’t see (these include save objects and FontID objects). For the purpose of this discussion, only simple and composite objects will be covered.

51

Data types are represented in the interpreter as objects, which are a fixed size and are easily manipulated by the interpreter, placed on the operand stack, or stored into arrays or dictionaries. For the most part, it is not necessary to know that data types are represented as objects, but it does affect some things. For a more complete discussion of PostScript language objects and data types, please refer to the PostScript Language

Reference Manual.

Probably the most important distinction to understand between the various data types is the difference between a simple object and a composite object. Composite objects can be thought of as pointers to the real data, whereas simple objects really are data themselves. Figure 5.1 shows the various data types available in PostScript.

Figure 5.1: PostScript Data Types, Simple and Composite

Simple Objects

Composite Objects

real

(string body)

string

integer

 

mark

array

boolean

 

 

dict

 

name

/name characters

PostScript objects are created in one of two ways: they are either created directly by the language interpreter when it reads the program from the input file, or they are created directly by the executing program itself through an explicit allocation. Some data types (the real number is an example) cannot be created explicitly by a program except by converting another data type (an integer). It must be created by the scanner, as it reads a number from the input stream (for instance, 103.46). Other data types cannot be created at all by the scanner. For example, the data types

52

Chapter 5: UNDERSTANDING THE STACK