contents.gifprev1.gifnext1.gif

Declarations

nu/TPU programs consist of a sequence of declarations and statements that follow the nu/TPU language syntax.

MODULE...ENDMODULE

The module statements allow a group of procedures, constants, variables, and executable statements to be considered one unit. Modules provide a means for groups of procedures to be executed with a single statement. When a module is compiled, two procedures are returned. The first module_name_MODULE_ IDENT contains the identification for the new module while the second module_ name_MODULE_INIT holds all of the executable statements for the module.

Syntax:

MODULE user_module_name IDENT string

[declarations]

[ON_ERROR...ENDON_ERROR]

statement;

statement;

ENDMODULE

Example

MODULE my_world IDENT ‘world1’

PROCEDURE hello_world

message (“HELLO World”);

ENDPROCEDURE

ON_ERROR

message (“No Hello to anyone”);

ENDON_ERROR;

my_world;

ENDMODULE

Any number of procedure declarations may be included in the [declarations] section of the MODULE syntax. The ON_ERROR statements must follow the last procedure in the module. The ON_ERROR block is optional. Module executable statements are located at the end of the module.

PROCEDURE...ENDPROCEDURE

Any group of commands which are to be processed as a group are placed between PROCEDURE statement and its closing ENDPROCEDURE statement. The general form is:

PROCEDURE name[(parameter_list,...)]

[LOCAL statements]

[CONSTANT statements]

[ON_ERROR...ENDON_ERROR]

Statements;

ENDPROCEDURE;

Procedures return values to their calling routines either by assigning a value to the procedure name, modifying the value of a program variable via the RETURN (value) statement, or through an expression which modifies a global variable which is accessed by the calling routine at some later point.

The procedure name may be any valid identifier.

The procedure parameters may be used for either input, output, or both. They may also be required or optional for the procedure. All parameters prior to the semicolon are required, those after are optional. If no semicolon is used, then all parameters are required. The maximum number of parameters that can be passed to a procedure is 1024.

ON_ERROR...ENDON_ERROR Statement

ON ERROR is truly a statement, but due to its use, it is best to locate its description next to Procedure Declarations in which ON_ERROR is used.

The ON_ERROR...ENDON_ERROR statement can be used in two forms.

The first form looks like the following block of code.

ON_ERROR

[statement [;...]]

ENDON_ERROR;

The above code block is identical in structure to a procedure and is event-driven. The particular event which drives this ON_ERROR code is an error. Because no specific error condition is expressed or implied, all errors are channeled through the procedure’s ON_ERROR code.

The second form of ON_ERROR...ENDON_ERROR is via the ON ERROR “CASE” statement syntax shown below. This form allows the user to trap specific error types for processing.

ON_ERROR

[condition1]: [statement [;...]]

[condition2]: [statement [;...]]

[condition]: [statement [;...]]

[OTHERWISE]: [statement [;...]]

ENDON_ERROR;

Note the similarity of the above to the CASE...ENDCASE syntax.

The ERROR value is passed to the ON_ERROR...ENDON_ERROR code block if nu/TPU knows one exists. When that is the case, the ERROR value is set to a keyword matching the encountered error condition. This can be quite useful when debugging, as the ERROR_LINE is set to the line number of the procedure where the error occurred, and ERROR_TEXT is set to the text string associated with the encountered error.

Note that all error handling (including exiting, aborting, etc., if necessary) should be handled inside the ON_ERROR...ENDON_ERROR code block. After processing the ON_ERROR...ENDON_ERROR code block, control returns to the statement generating the error, unless a RETURN statement is processed in the error handler.

Equivalence

VMS feature not supported in nu/TPU v5.0.

LOCAL Statement

There are three statements in nu/TPU by which values are assigned to variables. The statements are LOCAL, CONSTANT, and VARIABLE.

LOCAL statements are used to define a variable or constant for the current procedure. All LOCAL statements must be the first statements in a procedure, coming before any CONSTANT statements. A comma separates each local variable.

Syntax::

LOCAL variable_name [,...];

CONSTANT Declaration

Constant declarations are used to associate a fixed value with a variable. The value of the constant must be an integer, keyword, string, or unspecified. Constants may be defined globally or locally. Once a constant is defined, its value is unchangeable. Global constants are those declared outside the limits of a procedure. Local constants are declared inside a procedure, after any LOCAL definitions and prior to any ON_ERROR statements.

Syntax:

CONSTANT constant_name := constant_value [,...];

Changing a Numeric Constant’s Radix

Numeric value may be specified as binary, octal, decimal, or hexadecimal. The default radix for nu/TPU is decimal. To specify a different radix, the following prefixes must be used:

Radix Prefix Numeric value

Binary %B Digits from 0 to 1 inclusive

Octal %O Digits from 0 to 7 inclusive

Hexadecimal %X Digits 0-9 and letters A-F

Examples:

CONSTANT decimal_255 := 255;

CONSTANT binary_255 := %b11111111;

CONSTANT octal_255 := %0377;

CONSTANT hexdecimal_255 := %XOFF;

VARIABLE Declaration

The VARIABLE declaration defines and creates global variables in the nu/TPU system and must be used outside of a procedure.