HP 3000 Manuals

Statements and Their Elements [ HP Business BASIC/XL Reference Manual ] MPE/iX 5.0 Documentation


HP Business BASIC/XL Reference Manual

Statements and Their Elements 

This section contains the following information:

 *  Gives the syntax of the general statement and briefly explains each
    statement element.
 *  Explains the different types of statements.
 *  Provides further information on the statement elements keyword and
    identifier.
 *  Lists the places in a program where spaces are required or are
    illegal.
 *  Compares remarks and comments.
 *  Explains how statements form a program.

Statement Syntax 

Every HP Business BASIC/XL statement has the following syntax, although
not every statement can have all of the optional elements shown.  See
"Statement Types" in this chapter for restrictions on the general syntax.

Syntax 

{line_num [line_label:]} [Statement_body] [comment]

Parameters 

line_num         Integer in the range[1, 999999].  Leading zeros are not
                 significant.  Each program line in a program must have a
                 unique line number.  Program lines are executed in line
                 number order unless control statements specify
                 otherwise.

line_label       Identifier.  For a description of an identifier, see
                 "Identifiers".  If a program line has a label, it can be
                 referenced by either its label or line number.

statement_body   The part of the statement that is specified by its
                 syntax specification.  Syntax specifications for
                 individual statements appear in chapter 4.  The
                 statement-body is composed of the following statement
                 elements:

          Table 3-2.  Statement Elements 

---------------------------------------------------------------------------------------------
|                                             |                                             |
|              Statement Element              |                Explained in                 |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| Keyword                                     | "Keywords".                                 |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| Variable name                               | "Variable Names".                           |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| Spaces                                      | "Spaces".                                   |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| Literal                                     | "Numeric Literals" and "String Literals".   |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| Expression                                  | "Operators" or "Subunits".                  |
|                                             |                                             |
---------------------------------------------------------------------------------------------

comment          Any character string, including the null string.  A
                 comment cannot follow a HELP command or an IMAGE or DATA
                 statement.

Statement Types 

The HP Business BASIC/XL statement types and their relations are shown in
Figure 3-1.  Figure 3-1 also lists the characteristics of each statement
type.

[]
Figure 3-1. Statement Types The following are command-only statements: ANALYST CONTINUE HOP NAME AUTO COPY INFO REDO CALLS CWARNINGS LIST RENUMBER CHANGE EXIT(or ::) LIST SUBS RUN COMPGO FILES MODIFY STEP COMPILE FIND MOVE VERIFY COMPLINK HELP XREF A command-only statement cannot be a program line. Every other Business BASIC\XL statement can be a command or a program line. There are also some statements that cannot be a command. That is, they can only appear in program lines. The following are statements that can appear as part of a program line, but can not be issued as a command: ACCEPT END WHILE IF THEN ELSE OPEN FORM SUBEND CASE END IF IMAGE OPTION SUBEXIT CLEAR FORM ENTER IN DATASET PACKFMT SUBPROGRAM CLOSE FORM EXIT IF INPUT PAUSE THREAD IS COPTION EXTERNAL INTEGER READ TINPUT DATA FLUSH INPUT INTRINSIC READ FORM WHILE DECIMAL FNEND LENTER REAL WORKFILE IS DEF FN FOR LINPUT REPEAT WRITE FORM DIM GLOBAL COPTION LOOP SELECT UNTIL ELSE GLOBAL EXTERNAL MAT INPUT SHORT DECIMAL END LOOP GLOBAL INTRINSIC MAT READ SHORT INTEGER END SELECT GLOBAL OPTION NEXT SHORT REAL All other statements can be issued as a command, and can appear in a program line. Keywords Keywords are the basis of statements. A keyword can be entered in the following ways: * All uppercase letters (for example, PRINT). * All lowercase letters (for example, print). A keyword cannot be entered using a combination of uppercase and lowercase letters; for example, PrINt, or Print. Regardless of how keywords are entered, HP Business BASIC/XL lists them in uppercase. Examples 10 LET B$="Chocolate" !LET is a keyword 20 PRINT X !PRINT is a keyword 30 ON I GOTO 100,200,300 !ON and GOTO are keywords Identifiers An identifier is a character string that has the following characteristics: * Begins with a letter. * Contains any combination of letters, digits, and underscores (_). * Has 63 or fewer characters. HP Business BASIC/XL uses identifiers for several purposes. Table 3-3 shows those uses. Table 3-3. Identifier Uses ---------------------------------------------------------------------------------------------- | | | | | Use of Identifier | Required Modifier | Example | | | | | ---------------------------------------------------------------------------------------------- | | | | | Numeric variable name | None | Total | | | | | ---------------------------------------------------------------------------------------------- | | | | | Line label | None | Return_point: | | | | | ---------------------------------------------------------------------------------------------- | | | | | User-defined subprogram name | None | Routine | | | | | ---------------------------------------------------------------------------------------------- | | | | | User-defined function name | Prefix FN | FNAdd | | | | | ---------------------------------------------------------------------------------------------- | | | | | String variable name | Suffix $ | Name$ | | | | | ---------------------------------------------------------------------------------------------- An identifier can be entered in the following ways: * All uppercase letters; for example, NAMES (See note below). * All lowercase letters; for example, names. * A combination of uppercase and lowercase letters; for example NaMeS.
NOTE If an identifier has the same spelling as a keyword, it must be typed in a combination of uppercase and lowercase letters. For example, "Print" or "pRiNt" is an identifier, but "print" or "PRINT" is a keyword. If such an identifier appears where the keyword is illegal, Business BASIC\XL recognizes it as an identifier. For example, HP Business BASIC/XL interprets "PRINT IF" as "PRINT If", where If is an identifier. In general, identifiers should not have the same name and spelling as keywords. This can be very confusing, especially when attempting to debug a program.
Regardless of how an identifier is entered, HP Business BASIC/XL prints it with the first character upshifted and the others downshifted. For example, "NAMes" and "NAMES" become "Names", and both refer to the same entity. Examples Table 3-4. Legal Identifiers -------------------------------------------------------------------------------------------- | | | | Legal Identifier | Printed | | | | -------------------------------------------------------------------------------------------- | | | | X | X | | | | -------------------------------------------------------------------------------------------- | | | | grand_total | Grand_total | | | | -------------------------------------------------------------------------------------------- | | | | Sub_total_123 | Sub_total_123 | | | | -------------------------------------------------------------------------------------------- | | | | i | I | | | | -------------------------------------------------------------------------------------------- | | | | A_ | A_ | | | | -------------------------------------------------------------------------------------------- | | | | variablename | Variablename | | | | -------------------------------------------------------------------------------------------- | | | | LEGAL_IDENTIFIER | Legal_identifier | | | | -------------------------------------------------------------------------------------------- Table 3-5. Illegal Identifier -------------------------------------------------------------------------------------------- | | | | Illegal Identifier | Reason It Is Illegal | | | | -------------------------------------------------------------------------------------------- | | | | 1XYZ | First character is not a letter. | | | | -------------------------------------------------------------------------------------------- | | | | #illegal | First character is not a letter. | | | | -------------------------------------------------------------------------------------------- | | | | sub'total | Contains a character that is not a letter, digit or underscore. | | | | -------------------------------------------------------------------------------------------- Spaces One of the following must separate a keyword and an identifier: * Space. * Comma. * Parenthesis. * Operator. With few exceptions, spaces can appear anywhere in a program. Table 3-6 lists the places where spaces cannot appear and gives examples. Table 3-6. Places Where Spaces Are Not Allowed ----------------------------------------------------------------------------------------------- | | | | | Space Is Not Allowed | Correct Example | Incorrect Example | | | | | ----------------------------------------------------------------------------------------------- | | | | | Within a line number. | 1020 | 10 20 | | | | | ----------------------------------------------------------------------------------------------- | | | | | Within a keyword. | PRINT | PR INT | | | | | ----------------------------------------------------------------------------------------------- | | | | | Within an identifier. | Grandtotal | Grand total | | | | | ----------------------------------------------------------------------------------------------- | | | | | Within a numeric literal. | 10000 | 10 000 | | | | | ----------------------------------------------------------------------------------------------- | | | | | Within a multicharacter relational operator | <> | < > | | symbol. | | | | | | | ----------------------------------------------------------------------------------------------- | | | | | Between the identifier and $ in a string | Astring$ | Astring $ | | variable name. | | | | | | | ----------------------------------------------------------------------------------------------- | | | | | Between the FN and the identifier in a | FNAdd | FN Add | | function name. | | | | | | | ----------------------------------------------------------------------------------------------- When a keyword has an alternate spelling that contains an embedded space, the two parts can be separated by more than one space. The keywords in the left column below can also be initially spelled as shown in the right column. The space in the second column can be replaced with more than one space. HP Business BASIC/XL prints these keywords as shown in the left column. Table 3-7. Keywords with Alternate Spellings --------------------------------------------------------------------------------------------- | | | | Keyword | Alternate Spelling | | | | --------------------------------------------------------------------------------------------- | | | | ENDIF | END IF | | | | --------------------------------------------------------------------------------------------- | | | | ENDLOOP | END LOOP | | | | --------------------------------------------------------------------------------------------- | | | | ENDSELECT | END SELECT | | | | --------------------------------------------------------------------------------------------- | | | | ENDWHILE | END WHILE | | | | --------------------------------------------------------------------------------------------- | | | | FNEND | FN END | | | | --------------------------------------------------------------------------------------------- | | | | GOSUB | GO SUB | | | | --------------------------------------------------------------------------------------------- | | | | GOT0 | GO TO | | | | --------------------------------------------------------------------------------------------- | | | | SUBEND | SUB END | | | | --------------------------------------------------------------------------------------------- | | | | SUBEXIT | SUB EXIT | | | | --------------------------------------------------------------------------------------------- Comments versus Remarks Both comments and remarks are used for documentation only. Table 3-8 summarizes their similarities and differences. Table 3-8. Comments vs Remarks -------------------------------------------------------------------------------------------------- | | | | | | | Relationship to | How Recognized | Effect on Run-time Efficiency | | | Program | | | | | | | | -------------------------------------------------------------------------------------------------- | | | | | | Comment | Optional part of | Follows ! on | None (HP Business BASIC/XL ignores | | | program line. | program line. | everything after !). | | | | | | -------------------------------------------------------------------------------------------------- | | | | | | Remark | Nonexecutable | Begins with the | Slight (HP Business BASIC/XL must | | | program line. | keyword REM. | read the word REM to determine | | | | | that it does not need to do | | | | | anything else for that line). | | | | | | -------------------------------------------------------------------------------------------------- A comment can follow an empty statement as shown in line 400: 300 REM This is a remark. 400 !This comment follows an empty statement. 500 PRINT "Hello" !This comment is part of an executable program line. HP Business BASIC/XL lists a remark with one blank between the keyword REM and the text of the remark, as in line 300 above. HP Business BASIC/XL lists a comment with one space before the exclamation point, as in line 400 above. A comment cannot follow a HELP command. Program Structure A program is a sequence of program lines. It is good programming practice to end a program with an END statement and use STOP statements within the program if the program must be stopped before it ends. However, the END statement can appear more than once in a program, and it need not be the last line. Syntax program_line [program_line]...[END] [program_line]... Parameters program_line Any statement except a command (that is, any statement with a line number). The order that program lines are executed in is determined by line numbers and control statements. Program lines are executed in line number order unless control statements specify otherwise. Control statements are in chapter 4. The lines of a program can be entered in any order. HP Business BASIC/XL arranges them in line number order before listing them or executing the program. Chapter 2 explains how to enter program lines. A program can be divided into program units, one main program and one or more subunits. Execution begins with the first line of the main program unit. Subunits are covered later in this chapter.


MPE/iX 5.0 Documentation