>------!------!------!------!------!------!------!------!----------------------R >TM 3 >BM 3 >HM 3 >FM 1 >PL 66 >SM 10 >RJ ON >CP ON >HE Stross/BASIC-E MANUAL/% >LS 1 >FO____________________________________________________________________________ BASIC-E REFERENCE MANUAL MICRO-COMPUTER LABORATORY NAVAL POSTGRADUATE SCHOOL MONTEREY, CALIFORNIA GORDON E. EUBANKS, JR. 15 DECEMBER 1976 TABLE OF CONTENTS I. INTRODUCTION 3 II. DESCRIPTION OF THE BASIC-E LANGUAGE 4 III. OPERATNG INSTRUCTIONS FOR BASIC-E 63 APPENDIX A - COMPILER ERROR MESSAGES 68 APPENDIX B - RUN TIME MONITOR ERROR MESSAGES 69 APPENDIX C - BASIC-E GRAMMAR 70 APPENDIX D - COMPILER OPTIONS 75 BILIOGRAPHY 76 >PA I. INTRODUCTION This manual describes the naval Postgraduate School BASIC language (BASIC-E). BASIC-E is an extension of the BASIC language for the 8080 microprocessor. it consists of two subsystems, the compiler and the run-time monitor. The compiler syntax checks a BASIC-E source program producing an object file which may then be executed by the run-time monitor. BASIC-E is intended to be used in the interactive mode with a CRT or teletype terminal. It includes most features of the proposed ANSI standard BASIC (1) as well as extensive string manipulation and file input/output capabilities. BASIC-E requires a resident disk operating system to handle input/output operations and disk file management. The source program is assumed to reside on the disk. The BASIC-E compiler consists of a table-driven parser which checks statements for correct syntax and generates code for the BASIC-E machine. The code is executed by the run-time monitor. The machine is a zero address stack computer. Floating point arithmetic numbers are represented in 32 bits with an 98 bit exponent, one bit sign and twenty-four bits of fraction. This provides slightly more than seven decimal digits of significance. Variable length strings and dimensional arrays are both dynamically allocated. Section II of this manual describes the language elements. Section III provides operating instructions for BASIC-E. The appendices list compiler and run-time error messages, the formal grammar for BASIC-E, and compiler toggles. References are included in the bibliography. >PA II. DESCRIPTION OF THE BASIC-E LANGUAGE Elements of BASIC-E are listed in alphabetical order in this section of the manual. A synopsis of the element is shown, followed by a description and examples of its use. The intent is to provide a reference to the feature of this implementation of BASIC and not to teach the BASIC language. References (2,3) provide a good introduction to BASIC programming. A program consists of one or more properly formed BASIC-E statements. An END statement, if present, terminates the program and additional statements are ignored. The entire ASCII character set is accepted, but all statements may be written using the common 64-character subset. Section III provides information on source program format. In this section the synopsis presents the general form of the element. Square brackets [] denote an optional feature while braces () indicate that the enclosed section may be repeated zero or more times. Terms enclosed in <> are either non-terminal elements of the language, which are further defined in this section, or terminal symbols. All special characters and capitalized words are terminal symbols. >PA ELEMENT: ABS ABS predefined function SYNOPSIS: ABS () DESCRIPTION: The ABS function returns the absolute value of the . The argument must evaluate to a floating point number. EXAMPLES: ABS (X) ABS (X*Y) >PA ELEMENT: ASC ASC predefined function SYNOPSIS: ASC () DESCRIPTION: The ASC function returns the ASCII numeric value of the first character of the . The argument must evaluate to a string. If the length of the string is 0 (null string) an error will occur. EXAMPLES: ASC (A$) ASC ("X") ASC (RIGHT$(A$,7)) >PA ELEMENT: ATN ATN predefined function SYNOPSIS: ATN () DESCRIPTION: The ATN function returns the arctangent of the . The argument must evaluate to a floating point number. EXAMPLES: ATN (X) ATN (SQR(SIN(X))) PROGRAMMING NOTE: All other inverse trigonometric functions may be computed from the arctangent using simple identities. >PA ELEMENT: CHR$ CHR$ predefined function SYNOPSIS: CHR$ () DESCRIPTION: The CHR$ function returns a character string of length 1 consisting of the character whose ASCII equivalent is the converted to an integer modulo 128. The argument must evaluate to a floating point number. EXAMPLES: CHR$ (A) CHR$ (12) CHR$ ((A+B/C)*SIN(X)) PROGRAMMING NOTE: CHR$ can be used to send control characters such as a linefeed to the output device. The following statement would accomplish this: PRINT CHR$(10) >PA ELEMENT: CLOSE CLOSE statement SYNOPSIS: [] CLOSE expression {,} DESCRIPTION: The CLOSE statement causes the file specified by each to be closed. Before the file may be referenced again it must be reopened using a FILE statement. An error occurs if the specified file has not previously appeared in a FILE statement. EXAMPLES: CLOSE 1 150 CLOSE I,K, L*M-N PROGRAMMING NOTE: On normal completion of a program all open files are closed. If the program terminates abnormally it is possible that files created by the program will be lost. >PA ELEMENT: SYNOPSIS: [] . [] [E ] ["] ["] DESCRIPTION: A may be either a numeric constant or a string constant. All numeric constants are stored as floating point numbers. Strings may contain any ASCII character. Numeric constants may be either a signed or unsigned integer, decimal number, or expressed in scientific notation. Numbers up to 31 characters in length are accepted but the floating point representation of the number maintains approximately seven significant digits (1 part in 16,000,000). The largest magnitude that can be represented is approximately 2.7 times ten to the minus 39th power. String constants may be up to 255 characters in length. Strings entered from the console, in a data statement, or read from a disk file may be either enclosed in quotation marks or delimited by a comma. Strings used as constants in the program must be enclosed in quotation marks. EXAMPLES: 10 -100.75639E-19 "THIS IS THE ANSWER" >PA ELEMENT: COS COS predefined function SYNOPSIS: COS () DESCRIPTION: COS is a function which returns the cosine of the . The argument must evaluate to a floating point number expressed in radians. A floating point overflow occurs if the absolute value of the is greater than two raised to the 24th power times pi radians. EXAMPLES: COS(B) COS(SQR(X-Y)) >PA ELEMENT: COSH COSH predefined function SYNOPSIS: COSH () DESCRIPTION: COSH is a function which returns the hyperbolic cosine of the . The argument must evaluate to a floating point number. EXAMPLES: COSH(X) COSH(X^2+Y^2) >PA ELEMENT: DATA DATA statement SYNOPSIS: [] DATA constant {,} DESCRIPTION: DATA statements define string and floating point constants which are assigned to variables using a READ statement. Any number of DATA statements may occur in a program. The constants are stored consecutively in a data area as they appear in the program and are not syntax checked by the compiler. Strings maybe enclosed in quotation marks or optionally delimited by commas. EXAMPLES: 10 DATA 10.0,11.72,100 DATA "XYZ",11.,THIS IS A STRING >PA ELEMENT: DEF DEF statement SYNOPSIS: [] DEF () = DESCRIPTION: The DEF statement specifies a user defined function which returns a value of the same type as the. One or more are passed to the function and used in evaluating the expression. The passed values may be in string or floating point form but must match the type of the corresponding dummy argument. Recursive calls are not permitted. The in the define statement may reference other than the dummy arguments, in which case the current value of the is used in evaluating the . The type of the function must match the type of the . EXAMPLES: 10 DEF FNA(X,Y) = X + Y - A DEF FNB$(A$,B$) = A$ + B$ + C$ DEF FN.COMPUTE (A,B) = A + B - FNA(A,B) + D >PA ELEMENT: DIM DIM statement SYNOPSIS: [line number] DIM () {, ()} DESCRIPTION: The dimension statement dynamically allocates space for floating point or string arrays. String array elements may be of any length up to 255 bytes and change in length dynamically as they assume different values. Initially, all floating point arrays are set to zero and all string arrays are null strings. An array must be dimensioned explicity; no default options are provided. Arrays are stored in row major order. Expressions in subscript lists are evaluated as floating point numbers and rounded to the earnest integer when determining the size of the array. All subscripts have an implied lower bound of 0. When array elements are reference a check is make to ensure the element resides in the reference array. EXAMPLES: DIM A(10,20), B(10) DIM B$(2,5,10),C(I + 7.3,N),D(I) DIM X(A(I),M,N) PROGRAMMING NOTE: A is an executable statement, and each execution will allocate a new array. >PA ELEMENT: END END statement SYNOPSIS: [line number] END DESCRIPTION: An END statement indicates the end of the source program. It is optional and, if present, it terminates reading of the source program. If any statements follow the END statement they are ignored. EXAMPLES: 10 END END >PA ELEMENT: DESCRIPTION: Expressions consist of algebra in combinations of variables, constants, and operators. The heirarchy of operators is: 1) () 2) ^ 3) *,/ 4) +,-, concat (+), unary +, unary - 5) relational ops <,<=,>, =,=,<> LT, LE, GT, GE, EQ, NE 6) NOT 7) AND 8) OR, XOR Relational operators result in a 0 if false and -1 if true, NOT, and AND, and OR are performed on 32 bit two's complement binary representation of the integer portion of the variable. The result is then converted to a floating point number. String variables may be operated on by relational operators and concatenation only. Mixed string and numeric operations are not permitted. EXAMPLES: X + Y A$ + B$ (A <= B) OR (C$> D$) / (A - B AND D) >PA ELEMENT: FILE FILE statement SYNOPSIS: [] FILE ] FILE [()] {,[()]} DESCRIPTION: A file statement opens files used by the program. The order of the names determines the numbers used to reference the files in READ and PRINT statements. The value assigned to the first simple variable is file 1, the second is file 2, and so forth. There may be any number of FILE statement in a program, but there is a limit to the number of files which may be opened at one time. Currently this limit is set at 6 files. The optional designates the logical record length of the file. If no length is specified, the file is written as a continuous string of fields with carriage return linefeed characters separating each record. If the record length is present, a carriage return linefeed will be appended to each record. The must not be subscripted and it must be of type string. EXAMPLES: FILE INPUT$, OUTPUT$ FILE TABLE.INC$, TAX.INC$(160), PAY.AMT.DAY$(N*3-J) PROGRAMMING NOTE: The run-time monitor will always assign the lowest available (not previously assigned) number to the file being opened. this if files are closed and others opened it is possible that number assignment may vary with program flow. >PA ELEMENT: FOR FOR statement SYNOPSIS: [] FOR = TO [STEP ] DESCRIPTION: Execution of all statements between the FOR statement and its corresponding NEXT statement is repeated until the indexing variable, which is incremented by the STEP after each iteration, reaches the exit criteria. If the step is positive, the loop exit criteria is that the index exceeds the value of the TO . If the step is negative, the index must be less than the TO for the exit criteria to be met. The must be an unsubscripted variable and is initially set to the value of the first . Both the TO and STEP expressions are evaluated on each loop, and all variables associated with the FOR statement may change within the loop. If the STEP clause is omitted, a default value of 1 is assumed. a FOR loop is always executed at least once. A step of 0 may be used to loop indefinitely. EXAMPLES: FOR I = 1 TO 10 STEP 3 FOR INDEX = J*K-L TO 10*SIN(X) FOR I = 1 TO 2 STEP 0 PROGRAMMING NOTE: If a step of 1 is desired the step clause should be omitted The execution will be substantially faster since less run time checks must be made. >PA ELEMENT: FRE FRE predefined function SYNOPSIS: FRE DESCRIPTION: The FRE function returns the number of bytes of unused space in the free storage area. EXAMPLE: FRE >PA FUNCTION: SYNOPSIS: FN DESCRIPTION: Any starting with FN refers to a user defined function. The must appear in a DEF statement prior to being used in an . There may not be any spaces between the FN and the . EXAMPLES: FNA FN.BIGGER.$ >PA ELEMENT: GOSUB GOSUB statement SYNOPSIS: [] GOSUB [] GO SUB DESCRIPTION: The address of the next sequential instruction is saved on the run-time stack, and control is transferred to the subroutine labelled with the following the GOSUB or GO SUB. EXAMPLES: 10 GOSUB 300 GO SUB 100 PROGRAMMING NOTE: The max depth of GOSUB calls allowed is controlled by the size of the run-time stack which is currently set at 12. >PA ELEMENT: GOTO GOTO statement SYNOPSIS: [] GOTO [] GO TO DESCRIPTION: Execution continues at the statement labelled with the following the GOTO or GO TO. EXAMPLES: 100 GOTO 50 GO TO 10 >PA ELEMENT: SYNOPSIS: { or or.} ($) DESCRIPTION: An identifier begins with an alphabetic character followed by any number of alphanumeric characters, or periods. Only the first 31 characters are considered unique. If the last character is a dollar sign the associated variable is of type string. otherwise it is of type floating point. EXAMPLES: A B$ XYZ.ABC PAY.RECORD.FILE.NUMBER.76 PROGRAMMING NOTE: All lowercase letters appearing in an are converted to uppercase unless compiler toggle D is set to off. >PA ELEMENT: IF IF statement SYNOPSIS: [] IF THEN [] IF THEN [] IF THEN ELSE DESCRIPTION: If the value of the is not 0 the statements which make up the are executed. Otherwise the following the ELSE is executed, if present, or the next sequential statement is executed. In the first form of the statement if the is not equal to 0, an unconditional branch to the label occurs. EXAMPLES: IF A$ B$ THEN X=Y*Z IF (A$PA ELEMENT: IF END IF END statement SYNOPSIS: [] IF END # THEN DESCRIPTION: If during a read to the file specified by the , an end of file is detected control is transferred to the statement labelled with the line number following the THEN. EXAMPLES: IF END # 1 THEN 100 10 IF END # FILE.NUMBER - INDEX THEN 700 PROGRAMMING NOTE: On transfer to the line number followingthe THEN the stack is restored to the state prior to the execution of the READ statement which caused the end of file condition. >PA ELEMENT: INP INP predefined function SYNOPSIS: INP () DESCRIPTION: The INP function performs an input operation on the 8080 machine port represented by the value of the modulo 256 returning the resulting value. The argument must evaluate to a floating point number. EXAMPLES: INP (2) INP (CURRENT.INPUT.PORT) >PA ELEMENT: INPUT INPUT statement SYNOPSIS: [] INPUT [;] (, DESCRIPTION: The , if present, is printed on the console. A line of input data is read from the console and assigned to the variables as they appear in the variable list. The data items are separated by commas and/or blanks and terminated by a carriage return. Strings may be enclosed in quotation marks. If a string is not enclosed by quotes, the first comma terminates the string. If more data is requested than was entered, or if insufficient data items is entered, a warning is printed on the console and the entire line must be reentered. EXAMPLES: 10 INPUT A,B INPUT "SIZE OF ARRAY?"; N INPUT "VALUES?"; A(I),B(I),C(A(I)) PROGRAMMING NOTE: Trailing blanks in the are ignored. One blank is always supplied by the system. >PA ELEMENT: INT INT predefined function SYNOPSIS: INT (expression) DESCRIPTION: The INT function returns the largest integer less than or equal to the value of the . The argument must evaluate to a floating point point number. EXAMPLES: INT (AMOUNT / 100) INT (3^8/X*8*SIN(Y)) >PA ELEMENT: LEFT$ LEFT$ predefined function SYNOPSIS: LEFT$ (,) DESCRIPTION: The LEFT$ function returns the n leftmost characters of the first , where n is equal to the integer portion of the second . An error occurs if n is negative. If n is greater than the length of the first then the entire expression is returned. The first argument must evaluate to a string and the second to a floating point number. EXAMPLES: LEFT$ (A$,3) LEFT$(CS*DS,I-J) >PA ELEMENT: LEN LEN predefined function SYNOPSIS: LEN () DESCRIPTION: The LEN function returns the length of the string passed as an argument. Zero is returned if the argument is the null string. EXAMPLES: LEN (A$) LEN(CS + B$) LEN (LASTNAME$ + "," + FIRSTNAME$) >PA ELEMENT: LET LET statement SYNOPSIS: [] [LET] = DESCRIPTION: The is evaluated and assigned to the appearing on the left side of the equal sign. The type of the , either floating point or string, must match the type of the . EXAMPLES: 100 LET A = B + C X(3,A) = 7.32 * Y = X(2,3) 73 W = (AD$) AMOUNT$ = DOLLARS$ + "." + CENTS$ >PA ELEMENT: SYNOPSIS: {} DESCRIPTION: are optional on all statementsand are ignored by the compiler except when they appear in a GOTO, GOSUB, or ON statement. In these cases, the must appear as the label of one and only one in the program. may contain any number of digits but only the first 31 are considered significant by the compiler. EXAMPLES: 100 4635276353 >PA ELEMENT: LOG LOG predefined function SYNOPSIS: LOG () DESCRIPTION: The LOG function returns the natural logarithm of the absolute value of the . The argument must evaluate to a non-zero floating point number. EXAMPLES: LOG (X) LOG((A + B)/D) LOG10 = LOG(X)/LOG(10) >PA ELEMENT: MID$ MID$ predefined function SYNOPSIS: MID$ (,,) DESCRIPTION: The MID$ function returns a string consisting of the n characters of the first starting at the mth character. The value of m is equal to the integer portion of the second while n is the integer portion of the third . The first argument must evaluate to a string, and the second and third arguments must be floating point numbers. If m is greater than the length of the first a null string is returned. If n is greater than the number of character are returned. An error occurs if m or n is negative. EXAMPLES: MID$(A$,I,J) MID$(BS+C$,START,LENGTH) >PA ELEMENT: ON ON statement SYNOPSIS: (1) [] ON GOTO (, ) (2) [] ON GO TO (, ) (3) [] ON GOSUB (, ) (4) [] ON GO SUB (, ) DESCRIPTION: The , rounded to the nearest integer value, is used to select the evaluates to 1 the first is selected and so forth. In the case of an ON... GOSUB statement the address of the next instruction becomes the return address. An error occurs if the after rounding is less than one or greater than the number of in the list. EXAMPLES: 10 ON I GOTO 10, 20, 30, 40 ON J*K-M GO SUB 10, 1, 1, 10 >PA ELEMENT: NEXT NEXT statement SYNOPSIS: [] NEXT [ {}] DESCRIPTION: A NEXT statement denotes the end of the closest unmatched FOR statement. If the optional is present if must match the index variable of the FOR statement being terminated. The list of allows matching multiple FOR statements. The of a NEXT statement may appear in an ON or GOTO statement, which case execution of the FOR loop continues with the loop variables assuming their current values. EXAMPLES: 10 NEXT NEXT I NEXT I, J, K >PA ELEMENT: OUT OUT statement SYNOPSIS: [] OUT , DESCRIPTION: The low-order eight bits of the integer portion of the second is sent to the 8080 machine output port selected by the integer portion of the first expression modulo 256. Both arguments must evaluate to floating point numbers. EXAMPLES: 100 OUT 3,10 OUT PORT.NUM, NEXT.CHAR >PA ELEMENT: POS POS predefined function SYNOPSIS: POS DESCRIPTION: The POS function returns the current position of the output line buffer pointer. This value will range from 1 to the print buffer size. EXAMPLE: PRINT TAB(POS + 3);X >PA ELEMENT: PRINT PRINT statement SYNOPSIS: (1) [] PRINT #,; {,} (2) [] PRINT #; {,} (3) [] PRINT { } DESCRIPTION: A PRINT statement sends the value of the expressions in the expression list to either a disk file (type(1) and (2) or the console (type (3)). A type (1) PRINT statement sends a random record specified by the second to the disk file specified by the first . An error occurs if there is insufficient space in the record for all values. A type (2) PRINT statement outputs the next sequential record to the file specified by the following the #. A type (3) PRINT statement outputs the value of each to the console. A space is appended to all numeric values and if the numeric item exceeds the right margin then the print buffer is dumped before the item is printed. The between the may be either a comma or a semicolon. The comma causes automatic spacing to the next tab position (14,28,42,56). If the current print position is greater than 56 then the print buffer is printed and the print position is set to zero. A semicolon indicates no spacing between the printed values. if the last (expression> is not followed by a the print buffer is dumped and the print position set equal to zero. The buffer is automatically printed anytime the print position exceeds 71. EXAMPLES: 100 PRINT #1;A,B,A$+"*" PRINT # FILE, WHERE; A/B,D,"END" PRINT A, B, "THE ANSWER IS";x >PA ELEMENT: RANDOMIZE RANDOMIZE statement SYNOPSIS: [] RANDOMIZE DESCRIPTION: A RANDOMIZE statement initializes the random number generator. EXAMPLES: 10 RANDOMIZE RANDOMIZE >PA ELEMENT: READ READ statement SYNOPSIS: (1) [] READ , ; {,} (2) [] READ # ; {,} (3) [] READ # {,} DESCRIPTION: A READ statement assigns values to variables in the variable list from either a file (type (2) and (3)) or from a DATA statement (type (1)). Type (2) reads a random record specified by the second expression from the disk file specified by the first expression and assigns the fields in the record to the variables in the variable list. Fields may be floating point or string constants and are delimited by a blank or comma. Strings may optionally be enclosed in quotes. An error occurs if there are more variables than fields in the record. The type (3) READ statement reads the next sequential record from the file specified by the expression and assigns the fields to variables as described above. A type (2) READ statement assigns values from DATA statements to the variables in the list. DATA statements are processed sequentially as they appear in the program. An attempt to read past the end of the last data statement produces an error. EXAMPLES: 100 READ A,B,C$ 200 READ # 1,I; PAY.REG,PAY.OT,HOURS.REG,HOURS.OT READ # FILE.NO; NAMES,ADDRESS$,PHONE$,ZIP >PA ELEMENT: REM REM statement SYNOPSIS: [] REM [] [] REMARK [] DESCRIPTION: A REM statement is ignored by the compiler and compilation continues with the statement following the next carriage return. The REM statement may be used to document a program. REM statements do not affect the size of programs that may be compiled or executed. An unlabelled REM statement may follow any statement on the same line. And the may occur in a GOTO GOSUB, or ON statement. EXAMPLES: 10 REM THIS IS A REMARK REMARK THIS IS ALSO A REMARK LET X = 0 REM INITIAL VALUE OF X >PA ELEMENT: reserved word list reserved word list SYNOPSIS: {} [$] DESCRIPTION: The following words are reserved by BASIC-E and may not be used as : ABS AND ASC ATN CHR$ CLOSE COS COSH DATA DEF DIM ELSE END EQ EXP FILE FOR FRE GE GO GOSUB GOTO GT IF INP INPUT INT LE LEFT$ LEN LET LOG LT MID$ NE NEXT NOT ON OR OUT POS PRINT RANDOMIZE READ REM RESTORE RETURN RIGHT$ RND SGN SIN SINH SQR STEP STOP STR$ SUB TAB TAN THEN TO VAL Reserved words must be preceeded and followed by either a special character or a space Spaces may not be embedded within reserved words. Unless compiler toggle D is set, lower-case letters are converted to uppercase prior to checking to see if an is a reserved word. >PA ELEMENT: RESTORE RESTORE statement SYNOPSIS: [] RESTORE DESCRIPTION: A RESTORE statement repositions the pointer into the data area so that the next value read with a READ statement will be the first item in the first DATA statement. The effect of a RESTORE statement is to allow rereading the DATA statements. EXAMPLES: RESTORE 10 RESTORE >PA ELEMENT: RETURN RETURN statement SYNOPSIS: [] RETURN DESCRIPTION: Control is returned from a subroutine to the calling routine. The return address is maintained on the top of the run-time monitor stack. No check is made to insure that the RETURN follows a GOSUB statement. EXAMPLES: 130 RETURN RETURN >PA ELEMENT: RIGHT$ RIGHT$ predefined function SYNOPSIS: RIGHT$ (, DESCRIPTION: The RIGHT$ function returns the n rightmost characters of the first . The value of n is equal to the integer portion of the second . If n is negative an error occurs; if n is greater than the length of the first then the entire is returned. The first argument must produce a string and the second must produce a floating point number EXAMPLES: RIGHT$(X$,1) RIGHT$(NAME$,LNG.LAST) >PA ELEMENT: RND RND predefined function SYNOPSIS: RND DESCRIPTION: The RND function generates a uniformly distributed random number between 0 and 1. EXAMPLE: RND >PA ELEMENT: SGN SGN predefined function SYNOPSIS: SGN () DESCRIPTION: The SGN function returns 1 if the value of the is greater than 0, -1 if the value is less than 0 and 0 if the value of the is 0. The argument must evaluate to a floating point number. EXAMPLES: SGN(X) SGN(Z - B + C) >PA ELEMENT: SIN SIN predefined function SYNOPSIS: SIN () DESCRIPTION: SIN is a predefined function which returns the sine of the The argument must evaluate to a floating point number in radians. A floating point overflow occurs if the absolute value of the is greater than two raised to the 24th power times pi. EXAMPLES: X = SIN(Y) SIN(A - B/C) >PA ELEMENT: SINH SINH predefined function SYNOPSIS: SINH () DESCRIPTION: SINH is a function which returns the hyperbolic sine of the . The argument must evaluate to a floating pointer number. EXAMPLES: SINH(Y) SINH(BPA ELEMENT: special characters special characters DESCRIPTION: The following special characters are used by BASIC-E: ^ circumflex ( open parenthesis ) closed parenthesis * asterisk + plus - minus / slant : colon ; semicolon < less-than > greater-than = equal # number-sign , comma CR carriage return \ backslant Any special character in the ASCII character set may appear in a string. Special characters other than those listed above, if they appear outside a string will generate an IC error. >PA ELEMENT: SYNOPSIS: [] [] IF statement [] DIM statement [] DEF statement [] END statement DESCRIPTION: All BASIC-E statements are terminated by a carriage return (). >PA ELEMENT: SYNOPSIS: (: ) where a is one of the following: FOR statement NEXT statement FILE statement CLOSE statement GOSUB statement GOTO statement INPUT statement LET statement ON statement PRINT statement READ statement RESTORE statement RETURN statement RANDOMIZE statement OUT statement STOP statement statement DESCRIPTION: A allows more than one to occur on a single line. EXAMPLES: LET I = 0 : LET J = 0 : LET K - 0 X = Y+Z/W : RETURN :::::: PRINT "THIS IS OK TOO" >PA ELEMENT: STR$ STR$ predefined function SYNOPSIS: STR$ () DESCRIPTION: This STR$ function returns the ASCII string which represents the value of the . The argument must evaluate to a floating point number. EXAMPLES: STR$(X) STR$(3.141617) >PA ELEMENT: SYNOPSIS: {} DESCRIPTION: A may be used as part of a to specify the number of dimensions and extent of each dimension of the array being declared or as part of a to indicate which element of an array is being referenced. There may be any number of expressions but each must evaluate to a floating point number. A as part of a DIM statement may not contain a reference to the array being dimensioned. EXAMPLES: X(10,20,20) Y$(1,J) CUST(AMT(I),PRICE(I)) >PA ELEMENT: SQR SQR () DESCRIPTION: SQR returns the square root of the absolute value of the . The argument must evaluate to a floating point number. EXAMPLES: SQR (Y) SQR(X^2 + Y^2) >PA ELEMENT: TAB TAB predefined function SYNOPSIS: TAB () DESCRIPTION: The TAB function positions the output buffer pointer to the position specified by the integer value of the rounded to the nearest integer modulo 73. If the value of the rounded expression is less than or equal to the current print position, the print buffer is dumped and the buffer pointer is set as described above. The TAB function may occur only in PRINT statements. EXAMPLES: TAB(10) TAB(I + 1) >PA ELEMENT: STOP STOP statement SYNOPSIS: [] STOP DESCRIPTION: Upon encountering a program execution terminates an all open files are closed. The print buffer is emptied and control returns to the host system. Any number of STOP statements may appear in a program. A STOP statement is appended to all programs by the compiler. EXAMPLES: 10 STOP STOP >PA ELEMENT: TAB TAB predefined function SYNOPSIS: TAN () DESCRIPTION: TAN is a function which returns the tangent of the expression. The argument must be in radians. An error occurs if the is a multiple of pi/2 radians. EXAMPLES: 10 TAN(A) TAN(X - 3*COS(Y)) >PA ELEMENT: VAL VAL predefined function SYNOPSIS: VAL () DESCRIPTION: The VAL function converts the number in ASCII passed as a parameter into a floating point number. The must evaluate to a string. Conversion continues until a character is encountered that is not part of a valid number or until the end of the string is encountered. EXAMPLES: VAL(A$) VAL("3.789" + "E-07" + "THIS IS IGNORED") >PA ELEMENT: SYNOPSIS: [ () ] DESCRIPTION: A in BASIC-E may either represent a floating pint number or a string depending on the type of the . Subscripted variables must appear in a DIM statement before being used as a . EXAMPLES: X Y$(3,10) ABS.AMT(X(I),Y(I),S(I-1)) >PA III. OPERATING INSTRUCTIONS FOR BASIC-E The BASIC-E programs are written to operate with the CP/M Floppy Disk Operating System (4). Operation with a different system will require modification to the input/output routines in the compiler and run-time monitor. Execution of the program using BASIC-E consists of three steps. First the source program must be created on disk. Next the program is compiled by executing the BASIC-E compiler with the name of the source program provided as a parameter. Finally the intermediate (INT) file created by the compiler may be interpreted by executing the run-time monitor, again using the source program name as a parameter. Creation of the source program will normally be accomplished using CP/M's text editor, and must have a file type BAS. The BASIC-E statements are free from with the restriction that when a statement is not completed on a single line, a continuation character (\) must be that last character on the line. Spaces may precede statements and any number of spaces may appear wherever one space is permitted. Line numbers need only be used on statements to which control is passed. The line numbers do not have to be in ascending order. Using identifiers longer than two characters and indenting statements to enhance readability does not affect the size of the object file created by the compiler. The first statement of a source program may be used to specify certain compiler options. If present, this statement must begin with a dollar sign($) in column one and be followed by the letter or letters indicating the options which are desired.The letters may be separated by any number of blanks. Invalid letters or characters are ignores. Appendix D lists valid compiler options, and their initial settings. Toggle A is used for compiler debugging. Toggle B supresses listing of the source program except for statements with errors. Toggle C compiles the program but does not create a INT file. Normally the BASIC-E compiler converts all letters appearing in identifiers or reserved words to uppercase. If Toggle D is set this conversion is not performed. Letters appearing in strings are never converted to uppercase. Toggle E causes code to be generated by the compiler so that, upon detection of a run- time error, the source statements line which was being executed at the time the error occurred is listed along with the error message. The BASIC-E compiler is invoked as follows: BASIC The compiler begins execution by opening the source file specified as a parameter and compiles each BASIC-E statement producing an object file in the BASIC-E machine language with the same name as the source program but of type "INT". The source program may be listed on the output device with any error messages following each line of the program. Appendix A lists the compiler error messages. Errors SO, TO and VO indicate storage used by the compiler has been exceeded. These errors require recompilation of the BASIC-E compiler with more space allocated to the particular vector involved. Figures 1 and 2 show sample program listings. If no errors occur during compilation, the object file may be executed by the run-time monitor by typing the command: RUN The run-time monitor consists of two programs. The first program initializes the floating point package and then reads the intermediate language file specified as a parameter As the INT file is read, the floating point constants, BASIC-E machine code, and the data area are built. At this time branch addresses and references to floating point constanst and the program reference table (PRT) are relocated to reflect actual machine addresses. Control is then passed to the interpreter for execution of the BASIC-E machine language. The program which builds the machine resides in the free storage area and is overwritten as space is allocated by the interpreter. Appendix B lists run-time error messages. Figure 3 outlines the structure of the BASIC-E machine. The BASIC-E machine is divided into a static and varying area. The static section consists of the BASIC-E Run Time Monitor, constants, machine code and data statements. The varying area, which includes all the remaining memory, stores program variables, the stack and the free storage area. The stack is a circular queue and therefore it is not possible to overflow the stack. However, if the stack wraps around onto itself the results could be meaningless. The size of the stack is initially set at 12 but may be changed by recompiling the interpreter. The free storage area is used to dynamically allocate arrays and strings. Storage is freed as soon as it is no long required by the program. All requests for input from the console are prompted with question mark. If more information is entered than was requested, or if insufficient information is entered, a warning occurs and the entire line of data must be entered again. A program may be terminated by typing a control-Z followed by a carriage return in response to an input request. Disk files may be read, written or updated by the BASIC-E programmer using both sequential and random access. there are two basic types of files. Those with no declared record size, which are referred to as unblocked, and those with user-specified record size. The latter are blocked files. Blocked files may be processed either sequentially or randomly, while unblocked files must be accessed sequentially. All data in files is stored as ASCII characters. Either a comma or carriage return denotes the end of field. Blanks are ignored between fields. In unblocked files there is no concept of a record as such. Each reference to the file either reads from or writes to the next field. At the end of each a carriage return and a line feed are written to the file. This provides compatibility with the operating system utilities such as TYPE and also allows files to be created by the text editor. Blocked files consist of a series of fixed length records. The user specifies the logical record length with the . An error occurs if a line feed is encountered during a read from a blocked file or if the current record being built exceeds the block size during a write. At the end of a write statement any remaining area in the record is filled with blanks, and then a carriage return and linefeed are added. >PA REMARK PROGRAM TO COMPUTE THE FIRST N REMARK FIBONACCI NUMBERS PRINT "THIS PROGRAM COMPUTES THE FIRST N" PRINT "FIBONACCI NUMBERS" PRINT "AN INPUT OF 0 TERMINATES THE PROGRAM" FOR I = 1 TO 1 STEP 0 REMARK DO THIS FOREVER INPUT "ENTER THE VALUE OF N"; N IF N = 0 THEN \ PRINT "PROGRAM TERMINATES":\ STOP IF N 0 THEN \ PRINT "N MUST BE POSITIVE."; :\ PRINT "PLEASE REENTER"\ ELSE \ GOSUB 300 REMARK CALCULATE AND PRINT RESULTS NEXT 1 300 REMARK SUBROUTINE TO CALCULATE FIB NUMBERS F1 = 1 : F2 = 1 REMARK INITIAL VALUES NUM = F1 REMARK HANDLE FIRST TWO NUMBERS (IF REQ) AS REMARK SPECIAL CASES FOR J = 1 TO 2 GOSUB 400 IF N = 0 THEN \ RETURN NEXT J REMARK HANDLE REMAINING NUMBERS FOR J = 1 TO 1 STEP 0 NUM = F1 + F2 GOSUB 400 F2 = F1 F1 = NUM IF N - 0 THEN \ RETURN NEXT J RETURN 400 REMARK PRINT NEXT NUMBER AND REMARK DECREMENT N PRINT NUM, REMARK 5 TO A LINE N = N - 1 RETURN END >PA REMARK PROGRAM BUILDS A FILE OF MAILING LABELS REMARK FROM A FILE CONTAINING 100 BYTE RECORDS REMARK WHICH CONTAIN NAME AND ADDRESS INFORMATION INPUT "NAME OF COURSE FILE";SOURCE.FILE$ INPUT "NAME OF LABEL FILE";LABEL.FILE$ IF END # 1 THEN 100 FILE SOURCE.FILE$(100), LABEL.FILE REMARK LABEL.FILE IS NOT BLOCKED FOR INDEX = 1 TO 1 STEP 0 REM UNTIL END OF FILE READ # 1; FIRST$, LAST$, STREET$, CITY$, STATE$, ZIP REMARK LINES ARE TRUNCATED AT 60 CHARACTERS LINE1$ = LEFT$(FIRST$ + " " + LAST$,60) LINE2$ = LINE3$ + " " + SIR$(ZIP) REMARK INSURE ZIP NOT TRUNCATED LINE3$ = LEFT$(CITY$ + " , " + STATE$54) LINE3$ = LINE3$ + " " + SIR$(ZIP) PRINT # 2; LINE1$ PRINT # 2; LINE2$ PRINT # 2; LINE3$ NEXT INDEX 100 PRINT "JOB COMPLETE" STOP END >PA APPENDIX A - COMPILER ERROR MESSAGES CE Could not close file. DE Disk error DF Could not create INT file; disk or directory is full. DL Duplicate labels or synchronization error. DP Identifier in DIM statement previously defined. FC Identifier in FILE statement previously defined. FD Predefined function name previously defined. FI FOR loop index is not a simple floating point variable. FN Incorrect number of parameters in function reference. FP Invalid parameter type in function reference. FU Function is undefined. IC Invalid character in BASIC statement. IE Expression in IF statement is not of type floating point. IS Subscripted variable not previously dimensioned. IU Array name used as simple variable. MF Expression is of type string where only floating point is allowed. MM Expression contains string and floating point variables in mixed mode expression. NI Identifier following NEXT does not match FOR statement index. NP No applicable production exists. NS No BAS file found NU NEXT statement without corresponding FOR statement. SN Incorrect number of subscripts. SO Compiler stack overflow TO Symbol table overflow. UL Undefined label. VO VARC overflow. >PA APPENDIX B - RUN-TIME MONITOR ERROR MESSAGES AC Null string passed as parameter to ASC function. CE Error closing a file. DR Disk read error (reading unwritten data in random access). DW Error writing to a file. DZ Division by zero. EF EOF on disk file; no action specified ER Exceeded record size on block file. II Invalid record number in random access. FU Accessing an unopened file. ME Error attempting to create a file. MF File identifier too large or zero. NE Attempt to raise a number to a negative power. NI No INT file found in directory. OD Attempt to read past end of data area. OE Error attempting to open a file. OI Index in ON statement out of bounds. RE Attempt to read past end of record on blocked file. RU Unblocked file used with random access.d SB Array subscript out of bounds. SL String length exceeds 255. SS Second parameter of MID$ is negative. TZ Attempt to evaluate tangent of pi over two. >PA APPENDIX C - BASIC-E GRAMMAR 1 ::= 2 ::= 4 ::= 5 : 6 : 7 : 8 : 9 ::= < simple statement> 10 : : 10 : 11 ::= 12 : 13 : 14 : 15 : 16 : 17 : 18 : 19 : 20 : 21 : 22 : 23 : 24 : 25 : 26 : 27 : 28 : 29 ::= let 30 ::= 31 ::= = 32 ::= 33 : 34 ::= or 35 : xor 36 ::= 37 : and 37 38 ::= : not 40 ::= : 42 ::= 43 : + 43 44 : - 44 45 : + 46 : - 47 ::= 48 : * 49 : / 50 ::= 51 : ** 52 ::= 53 : 54 : 55 : ( ) 56 ::= 57 : ) 58 ::= ( 59 : < expression>, 60 ::= ) 61 : 62 ::= ( 63 : 63 64 ::= 65 : 66 ::= 67 : 68 ::= = 69 : >= 70 : ge 71 : <= 72 : le 73 : > 74 : < 75 : <> 76 : ne 77 ::= to 77 78 ::= 79 ::= for 80 ::= step 81 : 82 ::= 83 : 84 : if end # then 85 ::= 86 : 87 ::= else 88 ::= if then 89 ::= 89 = 90 ::= def 91 ::= 92 : 93 ::= ( 94 : 95 ::= 96 ::= file 97 : 98 ::= 99 ::= () 100 : 101 ::= dim 101 102 ::= 103 : 103 103 , 104 ::= ) 105 ::= ( 106 : , 107 ::= close 108 ::= 109 : , 110 ::= read 111 : read 112 ::= input 112 113 ::= ; 114 : 115 ::= 116 : , 117 : 118 ::= print 119 : print 120 ::= 121 : < print delim> 121 122 : 123 ::= , 125 ::= 126 : 127 ::= # 128 : # , ; 129 ::= ; 130 : 131 ::= 132 : 132 ::= < label list> 133 :