Compaq BASIC for OpenVMS
Alpha and VAX Systems
Reference Manual


Previous Contents Index


1  1  1  1  1  1  1  1 

The result of -1% AND -1% is -1% because BASIC sets bits in the result for each corresponding bit that is set in the operands. The result tests as true because it is a nonzero value, as shown in the following example:


A% = -1% 
B% = -1% 
IF A% THEN PRINT 'A% IS TRUE' 
IF B% THEN PRINT 'B% IS TRUE' 
IF A% AND B% THEN PRINT 'A% AND B% IS TRUE' 
             ELSE PRINT 'A% AND B% IS FALSE' 
END 

Output


A% IS TRUE 
B% IS TRUE 
A% AND B% IS TRUE 

Your program may also return unanticipated results if you use the NOT operator with a nonzero operand that is not -1.

In the following example, BASIC evaluates both A% and B% as true because they are nonzero. NOT A% is evaluated as false (zero) because the binary complement of -1 is zero. NOT B% is evaluated as true because the binary complement of 2 has bits set and is therefore a nonzero value.


A%=-1% 
B%=2 
IF A% THEN PRINT 'A% IS TRUE' 
      ELSE PRINT 'A% IS FALSE' 
IF B% THEN PRINT 'B% IS TRUE' 
      ELSE PRINT 'B% IS FALSE' 
IF NOT A% THEN PRINT 'NOT A% IS TRUE' 
          ELSE PRINT 'NOT A% IS FALSE' 
IF NOT B% THEN PRINT 'NOT B% IS TRUE' 
          ELSE PRINT 'NOT B% IS FALSE' 
END 

Output


A% IS TRUE 
B% IS TRUE 
NOT A% IS FALSE 
NOT B% IS TRUE 

1.6.4 Evaluating Expressions

BASIC evaluates expressions according to operator precedence. Each arithmetic, relational, and string operator in an expression has a position in the hierarchy of operators. The operator's position informs BASIC of the order in which to perform the operation. Parentheses can change the order of precedence.

Table 1-13 lists all operators as BASIC evaluates them. Note the following:

Table 1-13 Numeric Operator Precedence
Operator Precedence
** or ^ 1
-- (unary minus) or + (unary plus) 2
* or / 3
+ or -- 4
+ (concatenation) 5
all relational operators 6
NOT 7
AND 8
OR, XOR 9
IMP 10
EQV 11

For example, BASIC evaluates the following expression in five steps:


A = 15^2 + 12^2 - (35 * 8) 
1. (35 * 8) = 280 Multiplication
2. 15^2 = 225 Exponentiation (leftmost expression)
3. 12^2 = 144 Exponentiation
4. 225 + 144 = 369 Addition
5. 369 -- 280 = 89 Subtraction

There is one exception to this order of precedence: when an operator that does not require operands on either side of it (such as NOT) immediately follows an operator that does require operands on both sides (such as the addition operator (+)), BASIC evaluates the second operator first. For example:


A% + NOT B% + C% 

This expression is evaluated as follows:


(A% + (NOT B%)) + C% 

BASIC evaluates the expression NOT B before it evaluates the expression A + NOT B. When the NOT expression does not follow the addition (+) expression, the normal order of precedence is followed. For example:


NOT A% + B% + C% 

This expression is evaluated as:


NOT ((A% + B%) + C %) 

BASIC evaluates the two expressions (A% + B%) and ((A% + B%) + C%) because the + operator has a higher precedence than the NOT operator.

BASIC evaluates nested parenthetical expressions from the inside out.

In the following example, BASIC evaluates the parenthetical expression A quite differently from expression B. For expression A, BASIC evaluates the innermost parenthetical expression (25 + 5) first, then the second inner expression (30 / 5), then (6 * 7), and finally (42 + 3). For expression B, BASIC evaluates (5 / 5) first, then (1 * 7), then (25 + 7 + 3) to obtain a different value.


A = ((((25 + 5) / 5) * 7) + 3) 
PRINT A 
B = 25 + 5 / 5 * 7 + 3 
PRINT B 

Output


45 
35 

1.7 Program Documentation

Documentation within a program clarifies and explains source program structure. These explanations, or comments, can be combined with code to create a more readable program without affecting program execution. Comments can appear in two forms:

1.7.1 Comment Fields

A comment field begins with an exclamation point (!) and ends with a carriage return. You supply text after the exclamation point to document your program. You can specify comment fields while creating BASIC programs at DCL level as well as in the VAX BASIC Environment. In both cases, BASIC does not execute text in a comment field. Example 1-6 shows how to specify a comment field.

Example 1-6 Specifying a Comment Field

! FOR loop to initialize list Q 
FOR I = 1 TO 10 
    Q(I) = 0 ! This is a comment 
NEXT I 
! List now initialized 

BASIC executes only the FOR...NEXT loop. The comment fields, preceded by exclamation points, are not executed.

Example 1-7 shows how you can use comment fields to help make your program more readable and allow you to format your program into readily visible logical blocks. Example 1-7 also shows how comment fields can be used as target lines for GOTO and GOSUB statements.

Example 1-7 Using Comment Fields to Format a Program

! 
! Square root program 
! 
INPUT 'Enter a number';A 
PRINT 'SQR of ';A;'is ';SQR(A) 
! 
! More square roots? 
! 
INPUT 'Type "Y" to continue, press RETURN to quit';ANS$ 
GOTO 10 IF ANS$ = "Y" 
! 
END 

You can also use an exclamation point to terminate a comment field, but this practice is not recommended. You should make sure that there are no exclamation points in the comment field itself; otherwise, BASIC treats the text remaining on the line as source code.

Note

Comment fields in DATA statements are invalid; the compiler treats the comments as additional data.

1.7.2 REM Statements

A REM statement begins with the REM keyword and ends when BASIC encounters a new line number. The text you supply between the REM keyword and the next line number documents your program. Like comment fields, REM statements do not affect program execution. BASIC ignores all characters between the keyword REM and the next line number. Therefore, the REM statement can be continued without the ampersand continuation character and should be the only statement on the line or the last of several statements in a multistatement line. Example 1-8 shows the use of the REM statement.

Example 1-8 Using REM Statements in BASIC Programs

  5   REM This is an example 
      A=5 
      B=10 
      REM A equals 5 
          B equals 10 
 10   PRINT A, B 

Output


 
0       0 
 

Note that because line 5 began with a REM statement, all the statements in line 5 were ignored.

The REM statement is nonexecutable. When you transfer control to a REM statement, BASIC executes the next executable statement that lexically follows the referenced statement.

Note

Because BASIC treats all text between the REM statement and the next line number as commentary, REM should be used very carefully in programs that follow the implied continuation rules. REM statements are disallowed in programs without line numbers.

In the following example, the conditional GOTO statement in line 20 transfers program control to line 10. BASIC ignores the REM comment on line 10 and continues program execution at line 20.


10  REM ** Square root program 
20  INPUT 'Enter a number';A 
    PRINT 'SQR of ';A;'is ';SQR(A) 
    INPUT 'Type "Y" to continue, press RETURN to quit';ANS$ 
    GOTO 10 IF ANS$ = "Y" 
40  END 


Chapter 2
VAX BASIC Environment Commands

Note

The information in this chapter is specific to Compaq BASIC for OpenVMS VAX systems (referred to as VAX BASIC). The Environment commands are not supported by Compaq BASIC for OpenVMS Alpha systems (Alpha BASIC). For more information about the differences between Alpha BASIC and VAX BASIC, see Appendix C.

Environment commands are commands that you use in the VAX BASIC Environment. With Environment commands you can display, edit, and merge VAX BASIC programs, set compiler defaults, move VAX BASIC source programs to and from storage, and execute programs.

This chapter alphabetically lists all of the compiler commands that can be used within the VAX BASIC Environment. For information about immediate mode and calculator mode statements, see the Compaq BASIC for OpenVMS Alpha and VAX Systems User Manual.


! Your-comment

You can enter comments while in the VAX BASIC Environment by typing an exclamation point (!) and the comment.

Format



Syntax Rules

  1. The exclamation point must be the first character on the line.
  2. You cannot continue a comment over more than one line.

Remarks

None


Examples

Example 1


Ready 
 
! Comments here ... 

Example 2


$ TYPE BUILD_SPECIAL.COM 
 
$ SET VERIFY 
$ BASIC 
!+ 
! Set the compilation options by uncommenting 
! the appropriate ones. 
!- 
! SET LIST 
SET WORD 
SET DEBUG 
!+ 
! Get the source module. 
!- 
OLD SPECIAL 
!+ 
! Compile it. 
!- 
COMPILE 
!+ 
! All done. 
!- 
EXIT 


$ System-command

You can execute a DCL command while in the VAX BASIC Environment by typing a dollar sign ($) before the command. VAX BASIC passes the command to the operating system for execution. The context of the VAX BASIC Environment and the program currently in memory do not change.

Format



Syntax Rules

VAX BASIC passes system-command directly to the OpenVMS operating system without checking for validity.


Remarks

  1. The terminal displays any error messages or output that the command generates.
  2. Control returns to the VAX BASIC Environment after the command executes. The context (source file status, loaded modules, and so on) of the VAX BASIC Environment and the program currently in memory do not change unless the command causes the operating system to end VAX BASIC or log you out.
  3. The command you specify executes within the context of a subprocess. Consequently, commands such as the DCL command SET, execute only within the subprocess and do not affect the process running VAX BASIC.

Example


Ready 
 
$ SHOW PROTECTION 
  SYSTEM=RWED, OWNER=RWED, GROUP=RWED, WORLD=RE 
 
Ready 


APPEND

The APPEND command merges an existing VAX BASIC source program with the program currently in memory.

Format



Syntax Rules

File-spec is the name of the VAX BASIC program you want to merge with the program currently in memory. The default file type is .BAS.


Remarks

  1. You cannot specify the APPEND command on programs that do not contain line numbers.
  2. If you type APPEND without specifying a file name, VAX BASIC prompts with the following:


    Append file name-- 
    

    You should respond with a file name. If you respond by pressing Return and no file name, VAX BASIC searches for a file named NONAME.BAS. If the VAX BASIC compiler cannot find NONAME.BAS, VAX BASIC signals the error "Can't find file or account" (ERR=5).

  3. You can append the contents of file-spec to a source program that is either called into memory with the OLD command or created in the VAX BASIC Environment. If there is no program in memory, VAX BASIC appends the file to an empty program with the default file name NONAME.
  4. If file-spec contains a VAX BASIC line with the same line number as a line of the program in memory, the line in the appended file replaces the line of the program in memory. Otherwise, VAX BASIC inserts appended lines into the program in memory in sequential, ascending line number order.
  5. The APPEND command does not change the name of the program in memory.
  6. If you have not saved the appended version of the program, VAX BASIC signals the warning "Unsaved change has been made, Ctrl/Z or EXIT to exit" the first time you try to leave the VAX BASIC Environment.

Example


Ready 
 
New FIRST_TRY.BAS 
 
Ready 
10  PRINT "First program" 
 
APPEND NEW_PROG.BAS 
 
Ready 
 
LIST 
 
10  PRINT "First Program" 
 
20  PRINT "This section has been appended" 
 
   .
   .
   .


ASSIGN

The ASSIGN command equates a logical name to a complete file specification, a device, or another logical name within the context of the VAX BASIC Environment.

Format



Syntax Rules

  1. Equiv-name specifies the file specification, device, or logical name to be assigned a logical name. If you specify a physical device name, you must terminate it with a colon (:).
  2. Log-name is the 1- to 63-character logical name to be associated with equiv-name. You can specify a logical name for any portion of a file specification. If the logical name translates to a device name, and will be used in place of a device name in a file specification, you must terminate it with a colon (:).
  3. If log-name has more than 63 characters, VAX BASIC signals the error "Invalid logical name."

Remarks

  1. When the logical name assignment supersedes another logical name previously assigned, VAX BASIC displays the message "Previous logical name assignment replaced."
  2. Logical names assigned with the ASSIGN command are placed in the process logical name table and remain there until you exit the VAX BASIC Environment.

Example


ASSIGN [HENRY.BAS] PRO: 


COMPILE

The COMPILE command converts a VAX BASIC source program to an object module and writes the object file to disk.

Format



Syntax Rules

  1. File-spec specifies a name for the output file or files. If you do not provide a file-spec, the VAX BASIC compiler uses the name of the program currently in memory for the file name, a default file type of .OBJ for the object file, and a default file type of .LIS for the listing file, if a listing file is requested.
  2. File-spec can precede or follow any qualifier.
  3. Qualifier specifies a qualifier keyword that sets a VAX BASIC default.
  4. You can abbreviate all positive qualifiers to the first three letters of the qualifier keyword. You can abbreviate a negative qualifier to NO and the first three letters of the qualifier keyword.
  5. In cases of ambiguous or erroneous qualifiers, VAX BASIC signals "Unknown qualifier," and the program does not compile. When qualifiers conflict, VAX BASIC compiles the program using the last specified conflicting qualifier. For example, the following command line causes VAX BASIC to compile the program currently in memory but does not cause VAX BASIC to create an .OBJ file:


    COMPILE/OBJ/NOOBJ 
    

  6. There must be a program in memory, or the COMPILE command does not execute; VAX BASIC does not signal an error or warning.

Remarks

The following qualifiers cannot be used within the VAX BASIC Environment with the COMPILE command:

/ANALYSIS_DATA
/CHECK
/DEPENDENCY_DATA
/DESIGN
/DIAGNOSTICS
/INTEGER_SIZE
/OLD_VERSION=CDD_ARRAY
/OPTIMIZE
/REAL_SIZE
/SCALE

If an object file for the program already exists in your directory, VAX BASIC creates a new version of the .OBJ file.

You should not specify both a file name and file type. For example, if you enter the following command line, VAX BASIC creates two versions of NEWOBJ.FIL:


COMPILE NEWOBJ.FIL/LIS/OBJ 

The first version, NEWOBJ.FIL;1, is the listing file; the second version, NEWOBJ.FIL;2, is the object file. If you specify only a file name, VAX BASIC uses the .OBJ and .LIS file type defaults when creating these files. Use the COMPILE/NOOBJECT command to check your program for errors without producing an object file.

When you exit from the VAX BASIC Environment, all options set with qualifiers return to the system default values. Use the SHOW command to display your system defaults before setting any qualifiers.

Command Qualifiers


The /ANSI_STANDARD qualifier causes VAX BASIC to compile programs according to the ANSI Minimal BASIC standard and to flag syntax that does not conform to the standard. The /NOANSI_STANDARD qualifier causes VAX BASIC not to compile the program according to the ANSI Minimal BASIC standard. The default is /NOANSI_STANDARD.


The /AUDIT qualifier causes VAX BASIC to include a history list entry in the Commond Data Dictionary (CDD) data base when a CDD definition is extracted. Str-lit is a quoted string. File-spec is a text file. The history entry includes the following:

If you specify /NOAUDIT, VAX BASIC does not include a history list entry. The default is /NOAUDIT.


The /BOUNDS_CHECK qualifier causes VAX BASIC to perform range checks on array subscripts. With bounds checking enabled, VAX BASIC checks that all subscript references are within the array boundaries set when the array was declared. If the subscript bounds are not within the bounds initially declared for the array, VAX BASIC signals an error message. If you specify /NOBOUNDS_CHECK, VAX BASIC does not check that all subscript references are within the array bounds set. The default is /BOUNDS_CHECK.


The /BYTE qualifier causes VAX BASIC to allocate 8 bits of storage as the default for all integer data not explicitly typed in the program. Untyped integer values are treated as BYTE values and must be in the BYTE range or VAX BASIC signals the error "Integer error or overflow." Table 1-2 lists VAX BASIC data types and ranges. By default, the VAX BASIC compiler allocates 32 bits of storage.


If you use the /CROSS_REFERENCE qualifier with the /LIST qualifier when you compile your program, the VAX BASIC compiler includes cross-reference information in the program listing file. If you specify /CROSS_REFERENCE=KEYWORDS, VAX BASIC also cross-references VAX BASIC keywords used in the program. If you specify /NOCROSS_REFERENCE, VAX BASIC does not include a cross reference section in the compiler listing. The default is /NOCROSS_REFERENCE.


The /DEBUG qualifier appends to the object file information about symbolic references and line numbers. This information is used by the OpenVMS Debugger when you debug your program. When you specify the /DEBUG qualifier on the COMPILE command, you cause the debugger to be invoked automatically when the program is run at DCL level (unless you specify RUN/NODEBUG). If you specify COMPILE/NODEBUG, information about program symbols and line numbers is not included in the object file. The default is /NODEBUG.

See the Compaq BASIC for OpenVMS Alpha and VAX Systems User Manual for more information about using the OpenVMS Debugger.


The /DECIMAL_SIZE qualifier allows you to specify the default size and precision for all DECIMAL data not explicitly assigned size and precision in the program. You specify the total number of digits (d) and the number of digits to the right of the decimal point (s). VAX BASIC signals the error "Decimal error or overflow" (ERR=181) when DECIMAL values are outside the range specified with this qualifier. See Table 1-2 for more information about the storage and range of packed decimal data. The default is /DECIMAL_SIZE=(15,2).


The /DOUBLE qualifier causes VAX BASIC to allocate 64 bits of storage in D_floating format as the default size for all floating-point data not explicitly typed in the program. Untyped floating-point values are treated as DOUBLE values and must be in the DOUBLE range or VAX BASIC signals the error "Floating-point error or overflow." Table 1-2 lists VAX BASIC data types and ranges. The default is /SINGLE.


The /FLAG qualifier causes VAX BASIC to provide compile-time information about program elements that are not compatible with Alpha BASIC or BASIC-PLUS-2 or that Compaq designates as not recommended for new program development. For more information about the differences between Alpha BASIC and VAX BASIC, see Appendix C.


Previous Next Contents Index