HP OpenVMS Systems Documentation
HP BASIC for OpenVMS
A single-statement line consists of one statement on one text line, or one statement continued over two or more text lines. For example:
30 PRINT B * C / 12
This single-statement line has a line number, the keyword (PRINT), the operators (*, /), and the operands (B, C, 12).
You can have a single statement span several text lines by typing an ampersand (&) and pressing the Return key. Note that only spaces or tabs are valid between the ampersand and the carriage return. For example:
OPEN "SAMPLE.DAT" AS FILE 2%, & SEQUENTIAL VARIABLE, & MAP ABC
The ampersand continuation character may be used but is not required for continued REM statements. The following example is valid:
REM This is a remark And this is also a remark
PRINT "IF-THEN-ELSE- & END-IF"
This example is valid:
PRINT "IF-"; & "THEN-"; & "ELSE-"; & "END-"; & "IF"
40 PRINT A \ PRINT V \ PRINT G
You can also write a multistatement program line that associates all statements with a single line number by placing each statement on a separate line. BASIC assumes that such an unnumbered line of text is either a new statement or an IF statement clause.
In the following example, each line of text begins with a BASIC statement and each statement is associated with line number 400:
400 PRINT A PRINT B PRINT "FINISHED"
100 REM Determine if the user's response was YES or NO. 200 IF (A$ = "YES") OR (A$ = "Y") THEN PRINT "You typed YES" ELSE PRINT "You typed NO" STOP END IF
You can use any BASIC statement in a multistatement line. Because the
compiler ignores all text following a REM keyword until it reaches a
new line number, a REM statement must be the last statement on a
multistatement line. REM statements are disallowed in programs without
1.2.4 Compiler Directives
By including compiler directives in a program, you can do the following:
Follow these rules when using compiler directives:
For more information about compiler directives, see the HP BASIC for OpenVMS User Manual.
1.3 BASIC Character Set
Appendix A lists the full ASCII character set and character values.
The compiler does not distinguish between uppercase and lowercase letters except in string literals or within a DATA statement. The compiler does not process characters in REM statements or comment fields, nor does it process nonprinting characters unless they are part of a string literal.
In string literals, BASIC processes:
You can use nonprinting characters in your program, for example, in string constants, but to do so you must use one of the following:
Each unit of data in a BASIC program has a specific data type that determines how that unit of data is to be interpreted and manipulated by the compiler. This data type also determines how many storage bits make up the unit of data.
BASIC recognizes the following primary data types:
Integer data is stored as binary values in a byte, word, longword, or quadword. These values correspond to the BASIC data type keywords BYTE, WORD, LONG, and QUAD; these are all subtypes of the type INTEGER.
Floating-point values are stored using a signed exponent and a binary fraction. BASIC allows the floating-point formats F_floating, D_floating, G_floating, S_floating, T_floating, and X_floating. These formats correspond to the BASIC data type keywords SINGLE, DOUBLE, GFLOAT, SFLOAT, TFLOAT, and XFLOAT. These are all subtypes of the type REAL. (See Section 1.4.3.)
Character data consists of strings of bytes containing ASCII code as binary data. The first character in the string is stored in the first byte, the second character is stored in the second byte, and so on. BASIC allows up to 65,535 characters for a STRING data element.
For the DECIMAL(d,s) data type, you can specify the total number of digits (d) in the data type and the number of digits to the right of the decimal point (s). For example, DECIMAL(10,3) specifies decimal data with a total of 10 digits, 3 of which are to the right of the decimal point.
BASIC also recognizes a special RFA data type to provide information about a record's file address. An RFA uniquely specifies a record in a file: you can access RMS files of any organization by a record's file address. By specifying the address of a record, RMS retrieves the record at that address. Accessing records by RFA is more efficient and faster than other forms of random record access. The RFA data type can only be used for the following:
You cannot declare a constant of the RFA data type, nor can you use RFA variables for any arithmetic operations.
BASIC packed decimal data is stored in a string of bytes. See the HP BASIC for OpenVMS User Manual for more information about the storage of packed decimal data.
Table 1-2 summarizes HP BASIC data types.
|Data Type Keyword||Size||Range||Precision
|BYTE||8 bits (1 byte)||-128 to +127||3|
|WORD||16 bits (2 bytes)||-32768 to +32767||5|
|LONG||32 bits (4 bytes)||
|QUAD||64 bits (8 bytes)||
|SINGLE||32 bits (4 bytes)||0.29E-38 to 1.70E38||6|
|DOUBLE||64 bits (8 bytes)||0.29E-38 to 1.70E38||16|
|GFLOAT||64 bits (8 bytes)||0.56E-308 to 0.90E308||15|
|SFLOAT||32 bits (4 bytes)||1.18E-38 to 3.40E38||6|
|TFLOAT||64 bits (8 bytes)||2.23E-308 to 1.80E308||15|
|XFLOAT||128 bits (16 bytes)||6.48E-4966 to 1.19E4932||33|
|DECIMAL(d,s)||0 to 16 bytes ((d+1)/2 bytes)||1 * 10 -31 to 1 *10 31||d|
|STRING||One character per byte (default is 16 bytes)||Max = 65535||NA|
In Table 1-2, REAL and INTEGER are generic data type keywords that specify floating-point and integer storage, respectively. If you use the REAL or INTEGER keywords to type data, the actual data type used (SINGLE, DOUBLE, GFLOAT, SFLOAT, TFLOAT, XFLOAT, BYTE, WORD, LONG, or QUAD) depends on the current default.
You can also specify whether program values are to be typed implicitly
or explicitly. The following sections discuss data type defaults and
implicit and explicit data typing.
1.4.1 Implicit Data Typing
You can implicitly assign a data type to program values by adding a suffix to the variable name or constant value. If you do not specify any suffix, the variable or constant is assigned the current default data type. The following rules apply for implicit data typing:
With implicit data typing, the range and precision for program values are determined by the following corresponding default data sizes or subtypes:
If you do not specify a value for the default data type, REAL will be assigned.
The qualifiers for the BASIC DCL command are listed in the HP BASIC for OpenVMS User Manual.
1.4.2 Explicit Data Typing
In the following example, the first DECLARE statement associates the string constant value 03060 and the STRING data type with a constant named zip_code. The second DECLARE statement associates the STRING data type with emp_name, the DOUBLE data type with with_tax, and the SINGLE data type with int_rate. No constant values are associated with identifiers in the second DECLARE statement because they are variable names.
DECLARE STRING CONSTANT zip_code = "03060" DECLARE STRING emp_name, DOUBLE with_tax, SINGLE int_rate
With explicit data typing, each program variable within a program can have a different data type. You can explicitly assign data types to variables, constants, arrays, parameters, and functions; therefore, integer data does not have to take the compilation default types. Explicit data typing gives you more control over your program.
Using the REAL and INTEGER keywords to explicitly type program values
allows you to write programs that are more flexible, because these data
type keywords specify that floating-point and integer data take the
current defaults for REAL and INTEGER. The data type INTEGER, for
example, specifies only that the constant or variable is an integer.
The actual subtype (BYTE, WORD, LONG, or QUAD) depends on the default
set with the BASIC DCL command or with the OPTION statement.
1.4.3 QUAD and IEEE Floating-Point Data Types for 64-Bit Support
For 64-bit support, HP BASIC provides the QUAD data type for 64-bit integers as well as three IEEE floating-point types: SFLOAT, TFLOAT, and XFLOAT, which correspond to the S_floating, T_floating, and X_floating formats, respectively. QUAD and the IEEE data types are available wherever the other HP BASIC formats are available, as detailed in the following sections.
The three formats S_floating, T_floating, and X_floating are for finite values with normal rounding and standard exception handling only.
The QUAD keyword is one of the allowed values of the /INTEGER_SIZE qualifier, and the SFLOAT, TFLOAT, and XFLOAT keywords are three of the allowed values of the /REAL_SIZE qualifier.
QUAD, SFLOAT, TFLOAT, and XFLOAT can be used in HP BASIC statements wherever a data type is supplied.
The INTEGER function, besides accepting either a numeric string or any numeric data type expression for the first argument, includes QUAD in the possible data types for the second argument. The REAL function has SFLOAT, TFLOAT, and XFLOAT added to possible data types for its second argument.
Array subscripts may be of any numeric data type, but must evaluate to
an integer value at run time.
A variable is a named quantity whose value can change during program execution. Each variable name refers to a location in the program's storage area. Each location can hold only one value at a time. Variables of all data types can have subscripts that indicate their position in an array. You can declare variables implicitly or explicitly.
Depending on the program operations specified, the value of a variable can change from statement to statement. HP BASIC uses the most recently assigned value when performing calculations. This value remains in effect until a new value is assigned to the variable.
HP BASIC accepts the following general types of variables:
All variable names must conform to the following rules:
HP BASIC accepts the following implicitly declared variables:
The name of an implicitly declared variable defines its data type. Integer variables end with a percent sign (%), string variables end with a dollar sign ($), and variables of the default type (usually floating-point) end with any allowable character except a percent sign or dollar sign. All three types of variables must conform to the rules listed in Section 1.5.1 for naming variables. The current data type default (INTEGER, REAL, or DECIMAL) determines the data type of implicitly declared variables that do not end in a percent sign or dollar sign.
A floating-point variable is a named location that stores a floating-point value. The current default size for floating-point numbers (SINGLE, DOUBLE, GFLOAT, SFLOAT, TFLOAT, or XFLOAT) determines the data type of the floating-point variable.
Following are some examples of valid floating_point variable names:
If a numeric value of a different data type is assigned to a floating-point variable, BASIC converts the value to a floating-point number.
Following are some examples of valid integer variable names:
If the default or explicitly declared data type is INTEGER, the percent suffix (%) is not necessary.
If you assign a floating-point or decimal value to an integer variable, BASIC truncates the fractional portion of the value. It does not round to the nearest integer. For example:
B% = -5.7
BASIC assigns the value -5 to the integer variable, not -6.
Following are some examples of valid string variable names:
If the default or explicitly declared data type is STRING, the dollar suffix ($) is not necessary.
Strings have both value and length. BASIC sets all string variables to a default length of zero before program execution begins, with the exception of those variables in a COMMON, MAP, virtual array, or record definition. See the COMMON statement and the MAP statement in Chapter 3 for information about string length in COMMON and MAP areas. See the HP BASIC for OpenVMS User Manual for information about default string length in virtual arrays.