PS TEXT FORMAT Reference Manual
Expressions
5-16 11387 Tandem Computers Incorporated
Evaluation of
Expressions
In evaluating a compound expression, TFORM begins with entities that
already represent a single value each; these entities are called primaries.
TFORM next applies the effects of any unary operators (signed primaries,
or factors). Then it goes on to perform multiplication and division,
addition and subtraction, comparisons, and conjunctions (Boolean “and” ),
in that order. It reserves any Boolean “or” operations until the last.
Whenever TFORM finds more than one item of the same rank, it evaluates
them from left to right.
TFORM considers any expression enclosed in parentheses to be a primary;
this would include, for example, a function reference. TFORM evaluates all
primaries before going on to the next-ranking entity. Therefore, you can
use parentheses to alter the sequence of evaluation. Note the results of
different uses of parentheses:
1+2*3–4 = 3 1+2*(3–4) = –1
(1+2)*3–4 = 5 (1+2)*(3–4) = –3
You can also use parentheses to emphasize the existing sequence of
evaluation for ease in reading the expression. If you’re ever in doubt, go
ahead and use them, even if the parentheses are unnecessary.
Functions TFORM has a number of built-in functions to assist you in calculations and
the manipulation of strings and numbers. You may also create your own
by using the FUNCTION command. You call a function simply by using
the function reference in an expression; TFORM provides the value of the
function when formatting in your output. A function reference can be the
entire expression. In places where expressions aren’t acceptable, neither
are functions.
A function reference consists of the function name followed by a pair of
parentheses enclosing zero or more expressions, or arguments. Multiple
arguments are separated by commas. Like command names and macro
names, function names can be abbreviated to their first three or more
characters. The function performs its operations with the arguments you
provide, returning a single value that takes the place of the function
reference.