📄 basic.1
字号:
.\" Copyright (c) 1991, 1992, 1993, 1994 Free Software Foundation -*-Text-*-.\" See section COPYING for conditions for redistribution.\".\" Set up \*(lq, \*(rq if -man hasn't already set it up..if @@\*(lq@ \{\. ds lq ". if t .ds lq ``. if !@@\(lq@ .ds lq "\(lq.\}.if @@\*(rq@ \{\. ds rq ". if t .ds rq ''. if !@@\(rq@ .ds rq "\(rq.\}.de Id.ds Rv \\$3.ds Dt \\$4...de Sp.if n .sp.if t .sp 0.4...Id $Id: gcc.1,v 1.4 2002/01/28 23:19:12 pesch Exp $.TH BASIC 1 "\*(Dt" "chipmunk-basic" "chipmunk-basic".SH NAME.B basicChipmunk BASIC - 'BASIC' language interpreter.SH SYNOPSIS ( UNIX ).B basic .RI "[ " filename " ]".SH DESCRIPTIONChipmunk basic is an interpreter for the BASIC programminglanguage.If a filename parameter is given on the command line,then the named program file is loaded into memory and run.Basic commands and statements can be entered and interpretedin immediate mode or executed as program statements when theBasic program is run. A built-in line number based editorallows program input from the console keyboard; but Basicprograms do not require line numbers when run from files.See below for the commands, statements and functions thatthe Basic interpreter recognizes..SH FLAGSnone.SH COMMANDSStandard mumbleSoft-like Basic Commands:.TP.B load STRINGEXPRLoad a program into memory from the named file. Theprogram previously in memory is erased. All files areclosed and all variables are cleared. Lines beginningwith the '#' character will be treated as comments. All other lines in the file must begin with a linenumber. Duplicate line numbers are not allowed..PP.TP.B save STRINGEXPRSave the current program to the named file..TP.B newErase the program in memory. All files are closed andall variables are cleared..TP.B clearAll variables are cleared. All arrays and stringvariables are deallocated..TP.B run { LINENUM }.TP.B run { STRINGEXPR { , LINENUM } }Begin execution of the program at the first line, or atthe specified line. All variables are cleared. If aSTRINGEXPR is given then the BASIC program with thatname file is loaded into memory first. Program linesare executed in line number order..TP.B cont CONTinue execution of the program on the next statementafter the statement on which the program stoppedexecution due to a STOP command or an error. See BUGSsection..TP.B LINENUM { TEXT }Enters a program line. If a program line withline number LINENUM exists, then it is replaced.If no TEXT is given, the the program line withline number LINENUM is deleted..TP.B listList the whole program.Line numbers above 999999999 will not list..TP.B list 1-3List lines 1 to 2.TP.B list -2List lines up to 1.TP.B list 1List line 1.TP.B list 2-List lines from 2 on.TP.B merge STRINGEXPRLoads a program into memory. The previous programremains in memory; variables are not cleared. If aline exists in both programs, the new merged lineoverwrites the old one..TP.B renum STRINGEXPR VAL { , VAL { , VAL { , VAL} } }Renumber program lines. By default, the new sequence is10,20,30,... The first argument is a new initial linenumber; the second argument is the increment betweenline numbers. The third and fourth arguments, ifpresent, specify a limiting range of old line numbersto renumber. RENUM can be used to move non-overlappingblocks of code. .TP.B edit LINENUMBrings up a very Old-style line editor.Edit a single line. Enter return to finish. If theexit from edit mode is via a cntrl-c or 'q', then donot change the line. i insert till ESC x delete one char A append to end of line.TP.B del LINENUM [ - LINENUM ]Delete a line or specified range of lines. If not foundthen no lines will be deleted..TP.B exit.TP.B exit ( VAL ).TP.B bye.TP.B quit Terminates the basic interpreter, ending programexecution and closing all files. Optionally returnexit status to OS shell..PP.SH STATEMENTS.PP{ let } VAR = EXPRAssign a value to a variable. Variable names can be upto 31 significant characters, consisting of letters,digits, underscores, and an ending dollar sign.Variable names are case insensitive. Variables canhold real numbers (IEEE double) or strings of up to 254characters. If the variable name ends with a "$" itholds strings, otherwise it holds numbers. If astatement starts with a variable name then an impliedLET is assumed..TP.B print VAL | STRINGVAL { [ , | ; ] VAL ... } { ; }.TP.B ? VAL | STRINGVAL { [ , | ; ] VAL ... } { ; }.TP.B print # FNUM, VAL ...This command will print its parameters tab delimited.If a semi-colon is used between parameters then no tabis inserted between the parameters. The printoutput is terminated with a carriage return unless theparameter list ends with a semi-colon. If a filedescriptor is given then output is redirected to thegiven file. If a tab(VAL); is found in a print statement, then print output willskip to the horizontal position specified by VAL..TP.B print { # FNUM, } using STRINGVAL ; VAR { [ , | ; ] VAR ... }Prints formatted numbers. Legal characters for theformat string STRINGVAL are: + * $ # . E+ and trailingspaces.Examples: print using "**$###.##"; 1.23 :' ****$1.23 print using "###.##"; 2.12345 :' 2.12 print using "#.##E+##"; 2345.6 :' 2.35E+03 .TP.B input STRINGVAR | VAR { , VAR }.TP.B input "prompt"; { STRINGVAR | VAR { , VAR } }.TP.B input { # FNUM , } { STRINGVAR | VAR { , VAR } }Input from the console or from the file specified byFNUM. If the input is from the console then a promptstring can optionally be printed.*** NOTE ***All input to string variables is "line input"; a wholeinput line will be read into one string variable. Thenumber of comma seperated numeric values in the inputdata must be less than or equal to the number ofnumeric variables in the INPUT statement. This INPUTusage is different from other versions Basic..TP.B get STRINGVARGets one character from the console keyboard. Blocking..TP.B fputbyte VAL, # FNUMWrites one byte to the file specified by FNUM..TP.B get # FNUM, VAL, TYPED-VARReads one record from a random access file into VAR..TP.B put # FNUM, VAL, TYPED-VARWrite one record to a random access file from VAR..TP.B clsClear the terminals screen. Leaves the cursor in theupper left corner. For Applesoft BASIC fans, the"home" command will also do this..TP.B endTerminates program execution and returns to the commandprompt. Not required..TP.B stopStops the execution of the program and returns tothe command prompt. Prints a "Break..." message..TP.B if EXPR then STATEMENT { : STATEMENT } { : else STATEMENT }.TP.B if EXPR then LINENUM.TP.B if EXPRThe IF statement. If the condition is true then theSTATEMENTS after the THEN are executed and thestatements after the ELSE are skipped. If thecondition is false then the statements after the "else"are executed instead. If the item after "then" is aline number then a goto is executed.If the condition is true and there is no THEN on thesame line, statements are executed until a linewith an ENDIF is found. (block IF() ... ENDIF).TP.B for VAR = EXPR to EXPR { step EXPR }Beginning of a FOR-NEXT loop. It takes a startingvalue, a limit and an optional step argument. If thestep value is negative, the variable counts down. Thebody of the loop is not executed if the end conditionis true initially.Example: for i=1 to 10 : print i, : next i rem prints the numbers from 1 through 10.TP.B next { VAR }End of a FOR-NEXT loop. If the termination conditionsare met then execution falls through to the followingstatement, otherwise execution returns to the statementfollowing the FOR statement with the correspondingindex variable. If there no index variable parameter,the innermost FOR loop is used..TP.B exit forExits the current FOR-NEXT loop..TP.B while { EXPR }Start of a WHILE loop. The loop is repeated until EXPRis false. If EXPR is false at loop entry, then the loopis not executed . A WHILE loop must be terminated by abalancing WEND statement..TP.B wend { EXPR }Terminating statement of a WHILE loop. If EXPR is truethen exit the loop. Only one WEND is allowed for eachWHILE. A WHILE-WEND loop without a condition will loopforever..TP.B exit whileExits the current WHILE-WEND loop..TP.B gosub LINENUMTransfer command to a line number. Save return addressso that the program can resume execution at thestatement after the "gosub" command. The recursiondepth is limited only by available memory..TP.B returnReturns from the most recently activated subroutinecall (which must have been called by GOSUB)..TP.B goto LINENUMThis statement will transfer control to the line numberspecified. If the program is not running, then thiscommand will begin execution at the specified linewithout clearing the variables. An "Undefined line"error will occur if LINENUM doesn't exist in theprogram..TP.B on EXPR goto LINENUM { , LINENUM ... }.TP.B on EXPR gosub LINENUM { , LINENUM ... }This command will execute either a goto or a gosub tothe specified line number indexed by the value of EXPR.If EXPR is larger than the number of LINENUMs, thencontrol passes to the next statement..TP.B on error goto LINENUMIf the error form is used, only one linenumber isallowed. LINENUM is the line to which control istransferred if an error occurs. A GOTO or CONTstatement can be used to resume execution. An errorinside a named SUB subroutine cannot be resumed fromor CONTinued..TP.B sub NAME ( VAR { , VAR ... } }Subroutine entry. May be called by a CALL statement orby NAME. A SUB subroutine must be exited by a RETURN orEND SUB statement. There should be only one RETURN orEND SUB statement per SUB definition. The variables inthe VAR list become local variables. String and numericarguments are passed by value; array arguments must bepre-dimensioned and are passed by reference.Example: 110 x = foo (7, j) : rem Pass 7 and j by value. ... 2000 sub foo (x,y,z) : rem z is a local variable 2010 print x : rem prints 7 ... 2080 foo = y+1 : rem return value 2090 end subSubroutine definitions may not be nested..PP.TP.B select case EXPRMulti-way branch. Executes the statements afterthe CASE statement which matches the SELECT CASEexpression, then skips to the END SELECT statement.If there is no match, and a CASE ELSE statement ispresent, then execution defaults to the statementsfollowing the CASE ELSE.Example: 200 select case x 210 case 2 ... 230 case 3, 4 ... 270 case else ... 290 end select.PP.TP.B dim VAR( d { , d { , d } } ) { , VAR( d { , d { , d } } ) }Dimension an array or list of arrays (string or numeric). A maximum of 4 dimensions can be used. The maximumdimension size is limited by available memory. Legalarray subscripts are from 0 up and including thedimension specified; d+1 elements are allocated. Allarrays must be dimensioned before use.Example: 10 dim a(10) 20 for i=0 to 10 30 a(i) = i^2
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -