⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basic.1

📁 比较早的一款BASIC解释器 可作为学习BASIC解释器的一个参考
💻 1
📖 第 1 页 / 共 3 页
字号:
        40 next i        50 print a(5)        60 rem should print 25.TP.B data ITEM { , ITEM }DATA statements contain the data used in the READstatements. Items must be separated by commas.  Theitems may be either numeric or string expressions,corresponding to the type of variable being read.Reading the wrong kind of object produces a "Typemismatch" error.  Strings must be encapsulated withquote marks..TP.B read VAR { , VAR }Read data from the DATA statements contained in theprogram. List items can be either string or numericvariables. Reading past the end the last DATA statementgenerates an error..TP.B restore { LINENUM }The RESTORE statement causes the next READ to use thefirst DATA statement in the program.  If a LINENUM isgiven then the DATA statement on or after thatparticular line is used next..TP.B rem or "`"A remark or comment statement.  Ignored by the programduring execution, however a REM statement can be thetarget of a GOTO or GOSUB..TP.B open STRINGEXPR for { input|output|append } as # FNUMOpen a file. The { input|output|append } parameterspecifies whether the file is to be read, written orappended.  If STRINGEXPR is "stdin" for input or"stdout" for output then the console will be usedinstead of a file.  A "file not found" error willoccur if a non-existant file is specified in an OPENfor input statement.  FNUM must be an integer valuebetween 0 and 8..TP.B open STRINGEXPR for random as # FNUM len = VALOpens a random access file.  Only GET and PUT statementare allowed to read and write random access files..TP.B open ... else goto LINENUMSee OPEN command.LINENUM is the line to which control is transferred ifan error in opening a file occurs.  The variable ERL isset to the line number on which the file open erroroccured..TP.B close # FNUMClose a file. Releases the file descriptor and flushesout all stored data..TP.B def fnNAME ( VAR { , VAR } ) = EXPRDefine a user definable function.  Obsolete.Example:        10 def fnplus(x,y) = x+y        20 print fnplus(3,5)        30 rem - should print 8.TP.B mat ARRAY-VAR = EXPRFills a 1 or 2 dimensional array with a constantvalue given by EXPR..TP.B mat ARRAY-VAR = ARRAY-VARCopys a 2 dimensional array.  The dimensionsmust match..TP.B mat ARRAY-VAR = transpose ARRAY-VARTransposes a 2 dimensional array.  The dimensions ofthe first array must correspond to the transpose ofthe dimensions of the second array..TP.B mat ARRAY-VAR = ARRAY-VAR { + | * } { EXPR | ARRAY-VAR }Adds or multiplies a 2 dimensional array by eitheran expression or another array.  The dimensions mustbe appropriate for matrix addition or matrixmultiplication..TP.B mat origin { 0 | 1 }Sets the matrix index origin to either 0 or 1 for allMAT statements, including fill.  Defaults to 1..TP.B type CLASSNAMECreates a structure definition type.  Each fieldrequires a separate line.  Legal types are string,integer, longint and double.  The definition mustconclude with an END TYPE statement.  Use theDIM AS NEW statement to create records containingthe structure specified by a TYPE statement.Example:        300 type person        310   name as string * 32        311     rem  31 chars in length        320   age as integer        312     rem  2 byte integers        330   weight as double        331     rem  8 byte doubles        340 end type        400 dim friend1 as new person        410 friend1.name = "Mark"        420 friend1.age = 13        430 print friend1.name, friend1.age.PP.TP.B class CLASSNAME { extends SUPERCLASSNAME }Creates a class definition.  Class definitions can thenbe used to create objects with member functions (alsocalled methods.)  Classes inherit members fromsuperclasses (single inheritance.)Example:    CLASS bar        y AS integer        z AS PRIVATE double   ' private data        s AS PUBLIC string    ' public keyword optional        SUB blah(v)           ' public member function            this.y = v + 7        END SUB    END CLASS    DIM b AS NEW bar        ' create object b    CALL b.blah(1)          ' send message "blah(1)" to bCLASS and TYPE definitions are global, and cannot benested inside other class definitions or subroutines..TP.B dim VAR { ( INT ) } as new CLASSNAMECreate a record (TYPED-VAR) or object using apreviously defined structure definition type createdby TYPE...END TYPE or CLASS..END CLASS.  Optionallycreates an array of records or objects..TP.B erase VARUn-dimensions a dimensioned array.  Frees memory..TP.B option degreesChanges the trigonometric functions to take parametersand return results in degrees instead of radians..TP{ let } mid$( STRINGVAR, EXPR1, EXPR2 ) = STRINGEXPRReplace the sub-string in STRINGVAR, starting atcharacter position EXPR1, with character length EXPR2,with the (EXPR2 in length) string STRINGEXPR..TP{ let } field$( STRINGVAR, VAL { ,STRINGVAL } ) = STRINGEXPRReplace the N-th field of STRINGVAR with STRINGEXPR..TP.B poke ADDR_EXPR, DATA_EXPRPoke a byte into a memory location. Unreasonableaddresses can cause bus or segmentation errors..TP.B push VAR { , VAR ... }Pushes one or more expressions or variables onto aninternal stack.  Expressions can be returned using thePOP function; variables can be returned by using thePOP statement..TP.B pop VALPOP statement (see also POP function). Pops VALvariables off the internal stack, restoring the valueof those variables to their pushed values..TP.B exec(STRINGEXPR)Executes STRINGEXPR as a statement or command. e.g. exec("print " + "x") will print the value of x..PP.SH NUMERIC FUNCTIONS.PP.TP.B sgn(VAL)Returns the sign of the parameter value.  Returns 1 ifthe value is greater than zero , zero if equal to zero.-1 if negative..TP.B abs(x)Returns the absolute value of x..TP.B int(x)Returns the integer value of x.  Truncates toward negative infinity.The absolute value of x must be less than 2^31-1.The usage int(x, 0) truncates towards zero..TP.B floor(x)Returns the integer value of x.Truncates toward negative infinity..TP.B sqr(x)Returns the square root of x..TP.B log(x)Returns the natural logarithm of x..TP.B log10(x)Returns the logarithm base 10 of x..TP.B exp(x)Returns e^x. e=2.7182818....TP.B sin(x).TP.B cos(x).TP.B atn(x).TP.B atn(x,y)Trigonometric functions: sin, cosine and arctangent. .TP.B piReturns pi, 3.141592653589793... .TP.B rnd ( EXPR )Returns an integer pseudo-random number between 0 andint(EXPR)-1 inclusive. If EXPR is 1, then returns arational number between 0 (inclusive) and 1.  If EXPRis negative then EXPR seeds the random number generator..TP.B randomize EXPRSeeds the random number generator with the integerEXPR. The pseudo-random number generator should returnthe same sequence when seeded with the same startvalue.  The actual sequence may be system dependant..TP.B len( STRINGEXPR )Returns the length of the string STRINGEXPR..TP.B len( TYPED-VAR )Returns the length, in bytes, of a typed record(one created by DIM AS)..TP.B val( STRINGEXPR | EXPR )Value of the expression contained in a STRINGEXPR orEXPR.  STRINGEXPR may be a string literal, variable,function, or expression.For example, VAL("1 + sqr(4)") yields 3..TP.B asc( STRINGEXPR )Returns the ascii code for the first character ofSTRINGEXPR.  A null string returns zero..TP.B instr(a$, b$ { , VAL } )Returns the position of the substring b$ in thestring a$ or returns a zero if b$ is not a substring.VAL is an optional starting position in a$.TP.B ubound( VAR [, EXPR ] )If VAR is a dimensioned array, returns the maximumlegal subscript of the first dimension of that array,else returns 0.  Use EXPR to return other dimensions..TP.B isarray( VAR )If VAR is a dimensioned array, returns the numberof dimensions, otherwise returns 0..TP.B fgetbyte( FILENUM )Reads one byte from the open file specified by FILENUMand returns an unsigned numeric value [0..255]..TP.B eof(FILENUM)Returns true if the the last INPUT statement, INPUT$or FGETBYTE function call which referenced the textfile specified by FILENUM tried to read past the endof file. (Note that reading the last line of a filewill not read past the eof mark.  A subsequent read isneeded to set the EOF flag to true.  Reading past theend-of-file will not report an error.).TP.B popPOP function (see also POP statement). Pops one variablevalue off the stack and returns that value (string ornumeric).(POP can be used as either a statement (with aparameter) or a function (no parameter). Note that thePOP function, unlike the POP statement, does notrestore the value of the variable pushed, but onlyreturns the pushed value.  This use of the POPstatement is different from the Applesoft usage.).TP.B peek( ADDR { , SIZE_VAL } )Returns the value of the byte in memory at address ADDR.If SIZE_VAL is 2 or 4, returns the value of the 16-bitor 32-bit word respectively (if correctly aligned).If SIZE_VAL is 8, returns the value of the numericvariable located at ADDR.  (peek(varptr(x),8) == x).TP.B varptr( VAR | STRINGVAR )Returns the memory address of a variable..TP.B erlReturns the line number of the last error.  Zero if theerror was in immediate mode.  The variable errorstatus$gives the error type..TP.B timerReturns a numeric value of elapsed of seconds from thecomputers internal clock..PP.SH STRING FUNCTIONS.PP.TP.B x$ + y$String concatenation.String concatenation (and the MID$, LEN and INSTRfunctions) can handle strings of up to 32766 charactersin length (if the memory available to the programpermits)..TP.B chr$(VAL)Returns the ascii character corresponding to the valueof VAL..TP.B str$( VAL { , EXPR } )Returns a string representation corresponding to VAL.If EXPR is present then the string is padded to thatlength..TP.B format$( VAL , STREXPR )Returns the string representation of VAL formattedaccording to the format string STREXPR. The formatstring STREXPR uses the same formatting syntax as thePRINT USING statement..TP.B inkey$Return one character from the keyboard if input isavailable. Returns a zero length string { "" } if nokeyboard input is available.  Non-blocking.  Can beused for keyboard polling..TP.B input$( EXPR { , FILENUM } )Returns EXPR characters from file FILENUM. If f is notpresent then get input from the console keyboard..TP.B mid$( a$, i { , j } )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -