beautypg.com

AMT Datasouth PAL User Manual

Page 22

background image

16

PAL Language Reference

Unlike most other programming languages, PAL does not treat the "[" and "]" operators as special
language syntax symbols. PAL does not treat the operators and data it encounters between the "["
and "]" operator any different than if it had not encountered the "[" operator. In fact, once PAL
places the mark object onto the stack in response to the "[" operator, PAL totally forgets that it
ever saw the "[" operator.

PAL creates the array object in response to encountering the "]" operator. PAL creates the array
from all the objects located on the operand stack above the top-most mark object. Normally, the
top-most mark object will result from the previous "[" operator.

Therefore, the programmer need only push all the objects for the array onto the operand stack
following the mark object pushed by the "[" operator. PAL does not care how the programmer
pushes the objects onto the stack. In the most simple case, the programmer may simply list all the
objects. PAL will push the objects onto the stack as part of PAL's normal duties. In a more
complex case, the programmer may execute any combination of procedures and PAL operators to
generate the data for the array.

For example, the following simple PAL sequence creates an array containing the integer object
123, the string object "hello," and the literal name object "MyName."

[123 (hello) /MyName]

PAL treats this sequence in a very straight-forward manner. When PAL encounters the "["
operator, it pushes a mark object onto the operand stack. PAL then encounters the integer object
"123" and pushes it onto the stack. Next PAL encounters the string object "(hello)" and pushes it
onto the stack. After the string, PAL encounters the literal name object "/MyName" and pushes it
onto the stack.

Finally, PAL encounters the "]" operator. This instructs PAL to create an array object from all of
the objects on the stack above the top-most mark object. As a result, PAL creates an array
containing the integer, string, and name objects. PAL then removes the objects, as well as the mark
object, from the operand stack and places the array object onto the stack.

The following diagram shows the organization of the above array within the printer's memory.

Index

Object

0

123

1

(hello)

2

/MyName

Like string and name objects, array objects actually consist of two parts — the object part and the
value part. The array object itself contains only a reference to the array data (value). Therefore,
when the programmer instructs PAL to duplicate an array object, PAL only creates a new reference
to the array data. PAL does not duplicate the data itself. This conserves memory and allows the
programmer to manipulate the array data in various ways.

The programmer may access the individual objects within the array by specifying the index of the
object. The first object in the array has an index of zero, the next object has an index of one, with
the indexes continuing through N-1, where N represents the number of objects in the array.
Therefore, an array has the following general appearance.

[

obj0 obj1 obj2 obj3 ... objN-1

]