HP OpenVMS Systems Documentation
Guide to the DEC Text Processing Utility
In DECTPU, identifiers are used to name programs, procedures, keywords, and variables. An identifier is a combination of alphabetic characters, digits, dollar signs, and underscores, and it must conform to the following restrictions:
DECTPU identifiers for built-in procedures, constants, keywords, and global variables are reserved words.
You can create your own identifiers to name programs, procedures,
constants, and variables. Any symbol that is neither declared nor used
as the target of an assignment statement is assumed to be an undefined
Variables are names given to DECTPU storage locations that hold values. A variable name can be any valid DECTPU identifier that is not a DECTPU reserved word or the name of a DECTPU procedure. You assign a value to a variable by using a valid identifier as the left-hand side of an assignment statement. Following is an example of a variable assignment:
Compaq suggests that you establish some convention for naming variables so that you can distinguish your variables from the variables in the section file that you are using.
DECTPU allows two kinds of variables: global and local. Global variables are in effect throughout a DECTPU environment. Local variables are evaluated only within the procedure or unbound code in which they are declared. A variable is implicitly global unless you use the LOCAL declaration. You can also declare global variables with the VARIABLE declaration.
Example 4-1 shows a global variable declaration and a procedure that contains a local variable declaration.
The global variable user_tab_char is assigned a value when the procedure user_tab is executing. Since the variable is a global variable, it could have been assigned a value outside the procedure user_tab.
The local variable this_mode has the value established in the
procedure user_tab only when this procedure is executing. You
can have a variable also named this_mode in another procedure.
The two variables are not the same and may have different values. You
can also have a global variable named this_mode. However,
using this_mode as a global variable when you are also using
it as a local variable is likely to confuse people who read your code.
DECTPU will return an informational message during compilation if a
local variable has the same name as a global variable.
DECTPU has three types of constants:
Integer constants can be any integer value that is valid in DECTPU. See the DEC Text Processing Utility Reference Manual for more information on the integer data type.
String constants can be one character or a combination of characters delimited by apostrophes or quotation marks. See the DEC Text Processing Utility Reference Manual for a complete description of how to quote strings in DECTPU.
Keywords are reserved words that have special meaning to the DECTPU compiler. See Chapter 3 for a complete description of keywords.
With the CONSTANT declaration, you can associate a name with a constant expression. User-defined constants can be locally or globally defined.
A local constant is a constant declared within a procedure declaration. The scope of the constant is limited to the procedure in which it is defined.
A global constant is a constant declared outside a procedure. Once a global constant has been defined, it is set for the life of the DECTPU session. You can reassign to a constant the same value it was assigned previously, but you cannot redefine a constant during a DECTPU session.
See Section 184.108.40.206 for a complete description of the CONSTANT declaration.
Example 4-2 shows a global constant declaration and a procedure that contains a local constant declaration.
DECTPU uses symbols and characters as language operators. There are five types of operators:
Table 4-5 lists the symbols and language elements that DECTPU uses as operators.
You can use the + operator to concatenate strings. You can also use the relational operators to compare a string with a string, a marker with a marker, or a range with a range.
The precedence of the operators in an expression determines the order in which the operands are evaluated. Table 4-6 lists the order of precedence for DECTPU operators. Operators of equal precedence are listed on the same line.
Expressions enclosed in parentheses are evaluated first. You must use parentheses for correct evaluation of an expression that combines relational operators.
You can use parentheses in an expression to force a particular order for combining operands. For example:
An expression can be a constant, a variable, a procedure, or a combination of these separated by operators. You can use expressions in a DECTPU procedure where an identifier or constant is required. Expressions are frequently used within DECTPU conditional language statements.
The data types of all elements of a DECTPU expression must be the same. The following are exceptions to this rule:
Except for these cases, DECTPU does not perform implicit type conversions to allow for the mixing of data types within an expression. If you mix data types, DECTPU issues an error message.
In the following example, the elements (J > 4) and (my_string = "this is my string") each evaluate to an integer type (odd integers are true; even integers are false) so that they can be used following the DECTPU IF statement:
With the exception of patterns and the relational operators, the result of an expression is the same data type as the elements that make up the expression.
The following example shows a pattern expression that uses a string data type on the right-hand side of the expression. The LINE_BEGIN and REMAIN pattern keywords are used with the string constant "the" to create a pattern data type that is stored in the variable pat1:
Whenever possible, the DECTPU compiler evaluates constant expressions at compile time. DECTPU built-in procedures that can return a constant value given constant input are evaluated at compile time.
In the following example, the variable fubar has a single string assigned to it:
To avoid the need to rewrite code, you should write as if this compiler optimization were already implemented. If you need the compiler to evaluate an expression in a particular order, you should force the compiler to evaluate each operand in order before using the expression. To do so, use each operand in an assignment statement before using it in an expression. For example, suppose you want to use ROUTINE_1 and ROUTINE_2 in an expression. Suppose, too, that ROUTINE_1 must be evaluated first because it prompts for user input. To get this result, you could use the following code:
You could then use a statement in which the order of evaluation was important, such as the following:
The following sections discuss each of these expression types.
You can use any of the arithmetic operators (+, --, *, / ) with integer data types to form arithmetic expressions. DECTPU performs only integer arithmetic. The following are examples of valid DECTPU expressions:
The following is not a valid DECTPU expression because it mixes data types:
When performing integer division, DECTPU truncates the remainder; it does not round. The following examples show the results of division operations:
4.8.2 Relational Expressions
A relational expression tests the relationship between items of the same data type and returns an integer result. If the relationship is true, the result is integer 1; if the relationship is false, the result is integer 0.
Use the following relational operators with any of the DECTPU data types:
For example, the following code fragment tests whether string1 starts with a letter that occurs later in the alphabet than the starting letter of string2:
Use the following relational operators for comparisons of integers, strings, or markers:
When used with markers, these operators test whether one marker is closer to (or farther from) the top of the buffer than another marker. (If markers are in different buffers, they will return as false.) For example, the procedure in Example 4-3 uses relational operators to determine which half of the buffer the cursor is located in.
4.8.3 Pattern Expressions
A pattern expression consists of the pattern operators (+, &, |, @) combined with string constants, string variables, pattern variables, pattern procedures, pattern keywords, or parentheses. The following are valid pattern expressions:
DECTPU performs bitwise logical operations on Boolean expressions. This means that the logical operation is performed on the individual bits of the operands to produce the individual bits of the result. In the following example, the value of user_variable is set to 3.
As another example, if user_var were %X7777 (30583), then you would use the following statement to set user_var to %x0077 (119):
A true value in DECTPU is any odd integer; a false value is any even integer. Use the logical operators (AND, NOT, OR, XOR) to combine one or more expressions. DECTPU evaluates Boolean expressions enclosed in parentheses before other elements. The following example shows the use of parentheses to ensure that the Boolean expression is evaluated correctly:
4.9 Reserved Words
Reserved words are words that are defined by DECTPU and that have a special meaning for the compiler.
DECTPU reserved words can be divided into the following categories:
The following sections describe the categories of reserved words.
Keywords are a DECTPU data type. They are reserved words that have
special meaning to the compiler. You can redefine DECTPU keywords only
in local declarations (local constants, local variables, and parameters
in a parameter list). If you give a local constant, local variable, or
parameter the same name as that of a keyword, the compiler issues a
message notifying you that the local declaration or parameter
temporarily supersedes the keyword. In such a circumstance, the keyword
is said to be occluded.
See Chapter 3 and the DEC Text Processing Utility Reference
Manual for more information on keywords.
The DECTPU language has many built-in procedures that perform functions
such as screen management, key definition, text manipulation, and
program execution. You can redefine DECTPU built-in procedures only in
local declarations (local constants, local variables, and parameters in
a parameter list). If you give a local constant, local variable, or
parameter the same name as that of a built-in procedure, the compiler
issues a message notifying you that the local declaration or parameter
temporarily supersedes the built-in. In such a circumstance, the
built-in is said to be occluded.
See the DEC Text Processing Utility Reference Manual for a
complete description of the DECTPU built-in procedures.
The following is a list of predefined global constants that DECTPU sets up. You cannot redefine these constants.