Specifications
4-18
Guide to Printers and Printing
Relational and Logical Operators:
%= %> %< %! Pushes a value of 1 if true, or 0 if false, onto the stack.
%= Are the first two values that are popped off the stack equal? For
example, %{2}%{2}%= pushes a value of 1 (true) onto the stack,
and %{2}%{3}%= pushes a value of 0 (false) onto the stack.
%> Is the second value popped off the stack greater than the first value
popped off the stack? For example, %{2}%{3}%> pushes a value
of 0 (false) onto the stack.
%< Is the second value popped off the stack less than the first value
popped off the stack? For example, %{2}%{3}%< pushes a value
of 1 (true) onto the stack.
%! Negate the value popped off the stack and push the result onto the
stack: nonzero value to 0; 0 value to 1. For example, %{0}%!
pushes a value of 1 (true) onto the stack, %{1}%! pushes a value
of 0 (false) onto the stack, and %{2}%! pushes a value of 0 (false)
onto the stack.
Note: The first value to be popped off the stack is the last one to be pushed onto the
stack, and the second value to be popped off the stack is the one that was pushed onto
the stack first.
Bitwise Logical Operators:
%& %| %^ %~ Pushes the result onto the stack.
%& ANDs the first two values popped off the stack. For example,
%{6}%{3}%& pushes a value of 2 onto the stack.
%| ORs the first two values popped off the stack. For example,
%{6}%{3}%| pushes a value of 7 onto the stack.
%^ EXCLUSIVE ORs the first two values popped off the stack. For
example, %{6}%{3}%^ pushes a value of 5 onto the stack.
%~ ONE’S COMPLEMENTs the first value popped off the stack and
inverts the value of each bit. For example, %{–1}%~ pushes a
value of 0 (all bits off) onto the stack (assumes two’s complement
notation for –1).
Conditional (if–then–else) Operators:
%? expr %t thenpart %e elsepart %; %t pops a value off the stack and tests it. If
the value is TRUE (nonzero), thenpart is
run. Otherwise, elsepart (if present) is run.
else–if construct
%? c1 %t b1 %e c2 %t b2 %e c3 %t b3 %e b4 %;
where c1, c2, c3 denote conditions and b1, b2, b3, b4 denote bodies. For example,
%?%{1}%t%{2}%e%{3}%; pushes a value of 2 onto the stack, and
%gx%{6}%?%=%t%{2}%e%{3}%;%d outputs a value of 2 if the value of the internal
variable x is 6. If value of x is not 6, a value of 3 is output.
When developing complex logic, it is sometimes useful to show it in structured form. The
preceding example, in structured form, might look like this:
%gx Pushes the value of x onto the stack
%{6} Pushes a value of 6 onto the stack
%?%=%t If the stack values are equal then