>------!------!------!------!------!------!------!------!----------------------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 following�the� 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� statements�and� 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 :