BBC BASIC Syntax, ordered by character/token code ================================================= Commands ======== 01 CIRCLE [FILL] ,, 02 ELLIPSE [FILL] ,,, 02 ELLIPSE [FILL] ,,,, 03 FILL [BY] , Sends to VDU 04 MOUSE ,, Read mouse state 05 ORIGIN , Sends VDU 29,x;y; 06 QUIT Exits BASIC 07 RECTANGLE 08 SWAP , Swap two variables 09 SYS [,...] [TO ...[;]] 0A TINT , 0B WAIT Wait for VSync 0B WAIT Wait for centisecond period 0C INSTALL Installs library file at top of memory 0D Step to next line 0E PRIVATE struct[,struct...] Declare structures private to function or procedure. 0E PRIVATE var[,var...] Declare variables private to function or procedure. 0F BY error 10 C7 EXIT WHILE Exit current WHILE loop 10 E3 EXIT FOR Exit current FOR loop 10 E3 EXIT FOR Exit specified FOR loop 10 F5 EXIT REPEAT Exit current REPEAT loop 20 Step to next character, checking for line cont. char 21 != 32-bit indirection 22 " error 23 # error 24 $$= null-terminated string indirection 24 24 $= cr-terminated string indirection 25 % error 26 & error 27 ' error 28 ( declare a label 29 ) error 2A * Pass on as operating system command 2B + error 2C , error 2D - error 2E . error 2F / error 30-39 0-9 error 3A : Step to next statement 3B ; error 3C < error 3D = Return from function 3E > error 3F ?= 8-bit indirection 40 @ Assign variable 41-5A A..Z Assign variable 5B [ Enter assembler 5C \ Step to next line 5D ] error 5E ^ error 5F _ Assign variable 60 ` Assign variable 61-7A a..z Assign variable 7B { error 7C |= Real indirection 7D } error 7E ~ error 7F error 7F OTHERWISE Part of CASE structure 80 AND error 81 DIV error 82 EOR error 83 MOD error 84 OR error 85 ERROR [EXT] , Generate an [external] error with error number n and text . 86 LINE ,,, Sends MOVE x1,y1:DRAW x2,y2 87 OFF Sends VDU 23,1,0,0,0,0,0,0,0,0 to the output stream. 88 STEP error 89 SPC error 8A TAB( error 8B ELSE Skip ELSE clause 8C THEN Continue to THEN clause 8D line number GOTO line number 8E OPENIN error 8F PTR (fn) error 90 PAGE (fn) error 91 TIME (fn) error 92 LOMEM (fn) error 93 HIMEM (fn) error 94 ABS error 95 ACS error 96 ADVAL error 97 ASC error 98 ASN error 99 ATN error 9A BGET error 9B COS error 9C COUNT error 9D DEG error 9E ERL error 9F ERR error A0 EVAL error A1 EXP error A2 EXT#= Sets the extent of an open file. A3 FALSE error A4 FN error A5 GET error A6 INKEY error A7 INSTR( error A8 INT error A9 LEN error AA LN error AB LOG error AC NOT error AD OPENUP error AE OPENOUT error AF PI error B0 POINT( error B1 POS error B2 RAD error B3 RND error B4 SGN error B5 SIN error B6 SQR error B7 TAN error B8 TO error B9 TRUE error BA USR error BB VAL error BC VPOS error BD CHR$ error BE GET$ error BF INKEY$ error C0 LEFT$(strvar)= Overwrites leftmost characters of . C0 LEFT$(strvar,)= Overwrites leftmost characters of . C1 MID$(strvar,)= Overwrites middle characters of C1 MID$(strvar,,)= Overwrites middle characters of C2 RIGHT$(strvar)= Overwrites rightmost characters of . C2 RIGHT$(strvar,)= Overwrites rightmost characters of . C3 STR$ error C4 STRING$ error C5 EOF error C6 AUTO Generate line numbers C6 AUTO Generate line numbers C6 AUTO , Generate line numbers C6 8E SUM error C6 8F BEAT error C7 DELETE , Delete program lines. C7 WHILE Start of WHILE structure C7 8E APPEND Appends the file to the current program C7 8F AUTO Generate line numbers C7 8F AUTO Generate line numbers C7 8F AUTO , Generate line numbers C7 90 CRUNCH Crunches the current program C7 91 DELETE , Delete program lines. C7 92 EDIT Calls the editor C7 93 HELP Displays help C7 94 LIST List all or part of program. C7 95 LOAD Load a program into memory C7 96 LVAR Lists currently defines variables C7 97 NEW C7 98 OLD C7 9A SAVE C7 9B TEXTLOAD C7 9C TEXTSAVE C7 9D TWIN Calls TWIN C7 9E TWINO Calls TWIN C7 9F INSTALL Installs library file at top of memory C8 CASE OF Start of CASE structure C8 LOAD Load a program into memory. C8 LOAD , Load data into memory. C8 8E CASE OF Start of CASE structure C8 8F CIRCLE [FILL] ,, Sends MOVE x,y:PLOT 145,r,0 [153,r,0] C8 90 FILL [BY] , Sends to VDU C8 91 ORIGIN , Sends VDU 29,x;y; C8 92 POINT C8 93 RECTANGLE SWAP ,, TO , C8 93 RECTANGLE SWAP ,,, TO , C8 93 RECTANGLE [FILL] ,, C8 93 RECTANGLE [FILL] ,,, C8 93 RECTANGLE [FILL] ,,, TO , C8 94 SWAP , Swap two variables C8 95 WHILE C8 96 WAIT Wait for centisecond period C8 97 MOUSE COLOUR ,,, C8 97 MOUSE OFF C8 97 MOUSE ON C8 97 MOUSE ON C8 97 MOUSE RECTANGLE ,,, C8 97 MOUSE RECTANGLE OFF C8 97 MOUSE STEP C8 97 MOUSE STEP , C8 97 MOUSE TO , C8 97 MOUSE var,var,var C8 97 MOUSE var,var,var,var C8 98 QUIT Exits BASIC C8 98 QUIT Exits BASIC, returning return value C8 99 SYS [,...] [TO ...[;]] C8 9A error C8 9B LIBRARY Loads library file to BASIC heap C8 9C TINT , C8 9D ELLIPSE [FILL] ,,, C8 9D ELLIPSE [FILL] ,,,, C8 9E BEATS Sets number of beats/bar C8 9F TEMPO C8 A0 VOICES C8 A1 VOICE error C8 A2 STEREO , Set stereo position C8 A3 OVERLAY array() C8 A4 MANDEL C8 A5 PRIVATE struct[,struct...] Declare structures local to function or procedure. C8 A5 PRIVATE var[,var...] Declare variables local to function or procedure. C8 A6 C7 EXIT WHILE Exit current WHILE loop C8 A6 E3 EXIT FOR Exit current FOR loop C8 A6 E3 EXIT FOR Exit specified FOR loop C8 A6 F5 EXIT REPEAT Exit current REPEAT loop C9 LIST List all or part of program. C9 LIST List all or part of program. C9 LIST , List all or part of program. C9 WHEN ... Part of CASE C9 4F LISTO Control indentation in LIST. CA NEW Delete current program & variables. CA OF Part of CASE structure CB ENDCASE End of CASE structure CB OLD Recover a program deleted by NEW. CC ELSE Part of IF/THEN/ELSE and IF/THEN/ELSE/ENDIF CC OTHERWISE Part of CASE structure CC RENUMBER Renumber the program lines. CC RENUMBER Renumber the program lines. CC RENUMBER , Renumber the program lines. CD ENDIF End of IF structure CD SAVE Save program using name in REM > CD SAVE Save program CD SAVE ,,[,[,]] Save data from memory CE EDIT Calls the editor CE ENDWHILE End if WHILE structure CE PUT , Output to port CF PTR#= Sets the current pointer for an open file. D0 PAGE= Set memory address of current user's program. D1 TIME= Sets system elapsed time counter. D1 24 TIME$= Sets the system real-time clock. D2 LOMEM= Set start address of dynamic variable storage. D3 HIMEM= Set top of memory used by BASIC. D4 SOUND ,,, Generates sounds. D4 SOUND OFF Turns off sound output. D4 SOUND ON Turns on sound output. D5 BPUT#, Write least-significant byte of to output stream. D5 BPUT#, Write to output stream followed by D5 BPUT#,; Write to output stream. D6 CALL [,arg list] Call assembly language routine. D6 CALL Call a BASIC program D7 CHAIN Load and run a program. D8 CLEAR Clear dynamic variables. D9 CLOSE# Closes the specified channel. DA CLG Sends VDU 16 to the output stream. DB CLS Sends VDU 12 to the output stream. DC DATA Data for READ statement. DD A4 DEF FNname[(arg list)] Define a function. DD F2 DEF PROCname[(arg list)] Define a procedure. DE DIM struct{} Define a structure DE DIM struct{}=struct{} Define with a prototype DE DIM var [LOCAL] [,var ...] Reserve space in heap [on stack] DE DIM var(sub1[,sub2...])[,..] Dimension one or more arrays. DF DRAW , Sends PLOT 5,x,y [PLOT 1,x,y]. DF 0F DRAW BY , Sends PLOT 5,x,y [PLOT 1,x,y]. DF 42 59 DRAW BY , Sends PLOT 5,x,y [PLOT 1,x,y]. E0 END Terminate program. E0 END= Sets top of BASIC workspace E1 ENDPROC Return from a procedure. E2 ENVELOPE a,b,c,d,e,f,g,h,i,j,k,l,m,n Defines an envelope E3 FOR var= TO Begin a FOR...NEXT loop. E3 FOR var= TO STEP Begin a FOR...NEXT loop. E4 GOSUB Call a BASIC subroutine. E5 GOTO Branch to specified line. E6 GCOL Sends VDU 18,0,c to the VDU. E6 GCOL , Sends VDU 18,m,c to the VDU. E6 GCOL TINT Sends VDU 18,0,c,23,... to the VDU. E6 GCOL , TINT Sends VDU 18,m,c,23,... to the VDU. E7 IF GOTO [ELSE ] E7 IF THEN Start of block IF structure E7 IF THEN [ELSE ] Branch if non-zero. E7 IF THEN [ELSE ] Do statement(s) if non-zero. E8 INPUT [LINE][[,]]var[,var] Request input from user. E8 INPUT#,var[,var...] Reads data from an opened file with multiple calls to BGET. E9 LET var = Assignment. EA LOCAL Null operation - optional EA LOCAL struct[,struct...] Declare structures local to function or procedure. EA LOCAL var[,var...] Declare variables local to function or procedure. EA 85 LOCAL ERROR Save error handler on stack. EA DC LOCAL DATA Save DATA pointer on stack EB MODE Sends VDU 22,n to the output stream. EC MOVE [BY] , Sends PLOT 4,x,y [PLOT 0,x,y]. ED NEXT [var[,var...]] End FOR...NEXT loop. EE ON Sends VDU 23,1,1,0,0,0,0,0,0,0 to the output stream. EE ON GOSUB line,line.. [ELSE line] Computed GOSUB. EE ON GOTO line,line.. [ELSE line] Computed GOTO. EE ON PROCname.. [ELSE PROCname] Computed PROC call. EE ON CLOSE [LOCAL] OFF EE ON CLOSE [LOCAL] stmts RETURN EE ON ERROR OFF Restore default error handling. EE ON ERROR [LOCAL] stmts Do statement(s) on error. EE ON MOUSE [LOCAL] OFF EE ON MOUSE [LOCAL] stmts RETURN EE ON MOVE [LOCAL] OFF EE ON MOVE [LOCAL] stmts RETURN EE ON SYS [LOCAL] OFF EE ON SYS [LOCAL] stmts RETURN EE ON TIME [LOCAL] OFF EE ON TIME [LOCAL] stmts RETURN EF VDU [,|;[...]][|] Sends a list of eric arguments to the VDU. A 16-bit value can be sent F0 PLOT , Sends VDU 25,69,x;y; F0 PLOT ,, Sends VDU 25,k,x;y; F0 PLOT BY , Sends VDU 25,65,x;y; F1 PRINT [TAB(x[,y])][SPC(n)]['][;][~][#][/][[,...][;] Print data to output stream. F1 PRINT#,[,...] Writes data to an opened file with multiple calls to BPUT. F2 PROC()[(parameter list)] Call a procedure indirectly. F2 PROCname[(parameter list)] Call a procedure. F3 READ var[,var...] Read data from DATA statement(s). F3 READ#,var[,var...] Reads data from an opened file with multiple calls to BGET. F4 REM any text Remark F5 REPEAT Begin a REPEAT...UNTIL loop. F6 REPORT Print error message for last error. F7 RESTORE Reset data pointer to start of program F7 RESTORE + Reset data pointer to relative line F7 RESTORE Reset data pointer to specified line. F7 DC RESTORE DATA Restore data pointer F7 85 RESTORE ERROR Restore error handler F8 RETURN Return from subroutine. F9 RUN Run the current program. F9 RUN Load and run the specified file FA STOP Stop program and print message. FB COLOUR Sends VDU 17,n to the output stream FB COLOUR , Sends VDU 19,l,p,0,0,0 to the output stream. FB COLOUR ,,, Sends VDU 19,l,16,r,g,b if l>=0 FB COLOUR ,,, Sends VDU 19,l,24,r,g,b if l<0 FB 87 COLOUR OFF ... FB EE COLOUR ON ... FC TRACE CLOSE Close trace file FC TRACE TO Open output to trace file FC TRACE [STEP] Trace lines less than . FC TRACE [STEP] OFF End trace mode. FC TRACE [STEP] ON Start trace mode. FC TRACE [STEP] PROC Trace PROC/FN calls FD UNTIL Terminate loop if is non-zero. FE WIDTH Set print output width. FF OSCLI Pass to operating system to execute a command. Functions ========= 01 CIRCLE error 02 ELLIPSE error 03 FILL error 04 MOUSE error 05 ORIGIN error 06 QUIT Returns FALSE if program run from BASIC editing mode 07 RECTANGLE error 08 SWAP error 09 SYS error 0A TINT(,) Reads tint at point 0B WAIT error 0C INSTALL error 10 EXIT error 20 Step to next character 21 ! 32-bit indirection 22 " constant string 23 # error, print operator 24 $$ null-terminated string indirection 24 $ cr-terminated string indirection 25 % binary number 26 & hex number 26 &o octal number 27 ' error, print operator 28 ( Bracketed expression 29 ) error 2A * error 2B + unary plus 2C , error, print operator 2D - Unary minus 2E . decimal number 2F / error, print operator 30-39 0..9 decimal number 3A : error, statement terminator 3B ; error, print operator 3C < error 3D = error 3E > error 3F ? 8-bit indirection 40 @ variable 41-5A A..Z variable 5B [ error 5C \ error, line continuation 5D ] error 5E ^ Address of identifier 5F _ variable 60 ` variable 61-7A a..z variable 7B { error 7C | Real indirection 7D } error 7E ~ error, print operator 7F 7F OTHERWISE error 80 AND error 81 DIV error 82 EOR error 83 MOD array Modulus of array 84 OR error 85 ERROR error 86 LINE line number 87 OFF error 88 STEP error 89 SPC error, print operator 8A TAB( error, print operator 8B ELSE error 8C THEN error 8D line number line number 8E OPENIN Opens a file for reading and returns handle. 8F PTR# Returns current pointer for an open file. 90 PAGE Returns address of program. 91 TIME Reads the elapsed 100Hz time clock. 91 24 TIME$ Reads the system real-time clock 92 LOMEM Returns start address of dynamic variable storage. 93 HIMEM Returns top of memory used by BASIC. 94 ABS Absolute value of . 95 ACS Arc-cosine of , in radians. 96 ADVAL Returns information about devices or buffers 97 ASC Returns ASCII value of first character of or -1 98 ASN Arc-sine of , in radians. 99 ATN Arc-tangent of , in radians. 9A BGET# Reads a byte from a channel 9B COS Cosine of radian . 9C COUNT Returns number of characters printed since last new line. 9D DEG Value in degrees of radian . 9E ERL Returns line number of last error. 9F ERR Returns error number of last error. A0 EVAL Evaluates as an expression. A1 EXP e raised to the power of . A2 EXT# Returns the length of the opened file. A3 FALSE Returns zero. A4 FNname[(parameter list)] User-defined numeric or string function. A5 GET Waits for keypress and returns ASCII value. A5 GET() Reads a value from the specified I/O port. A5 GET(,) Reads a character from the specified character position. A6 INKEY Waits for keypress or scans keyboard A7 INSTR(,) Returns position of string A7 INSTR(,,) Returns position of string, starting at position. A8 INT Largest integer less than . A9 LEN Returns length of . AA LN Natural logarithm of . AB LOG Base-ten logarithm of . AC NOT Bitwise inversion AD OPENUP Opens a file for update and handle. AE OPENOUT Opens a file for writing and returns handle. AF PI Returns 3.14159265. B0 POINT(,) Returns colour of the screen at the coordinates. B1 POS Returns horizontal text cursor position. B2 RAD Radian value of in degrees. B3 RND Returns random 32-bit integer B3 RND () RND(-n) seeds sequence. B3 RND () RND(0) repeats last value in RND(1) form. B3 RND () RND(1) returns number between 0 and 0.999999999 B3 RND () RND(n) returns random integer between 1 and n. B4 SGN 1 if >0, 0 if =0, -1 if <0. B5 SIN Sine of radian . B6 SQR Square root of . B7 TAN Tangent of radian . B8 TO error B8 50 TOP Returns first address after end of user's program. B9 TRUE Returns -1. BA USR Calls a machine code routine and returns integer. BB VAL Returns numeric value of or zero BC VPOS Returns the vertical position of the text cursor. BD CHR$ Returns one-character string with ASCII value of . BE GET$ Waits for keypress and returns one-character string. BE GET$# Read a - or -terminated string from open file. BE GET$(,) Reads a character from the specified character position. BF INKEY$ Waits for keypress or scans keyboard C0 LEFT$() Returns leftmost LEN()-1 characters of . C0 LEFT$(,) Returns leftmost characters of . C1 MID$(,) Returns sub-string from position to end. C1 MID$(,,) Returns sub-string from position of length. C2 RIGHT$() Returns rightmost one character of . C2 RIGHT$(,) Returns rightmost characters of . C3 STR$# Returns string representation in oct C3 STR$/ Returns string representation in binary C3 STR$ Returns string representation in decimal C3 STR$~ Returns string representation in hex C4 STRING$(,) Returns a string consisting of copies of . C5 EOF# Returns TRUE if at the end of the opened file specified by the handle. C6 AUTO error C6 SUM Sum of all elements in an array C6 8E SUM Sum of all elements in an array C6 8E A9 SUMLEN Sum of length of all strings in an array C6 8F BEAT Current beat number C6 A9 SUMLEN Sum of length of all strings in an array C7 DELETE error C7 WHILE error C7 8E APPEND error C7 8F AUTO error C7 90 CRUNCH error C7 91 DELETE error C7 92 EDIT error C7 93 HELP error C7 94 LIST error C7 95 LOAD error C7 96 LVAR error C7 97 NEW error C7 98 OLD error C7 99 RENUMBER error C7 9A SAVE error C7 9B TEXTLOAD error C7 9C TEXTSAVE error C7 9D TWIN error C7 9E TWINO error C7 9F INSTALL error C8 CASE error C8 LOAD error C8 8E CASE error C8 8F CIRCLE error C8 90 FILL error C8 91 ORIGIN error C8 92 POINT C8 93 RECTANGLE error C8 94 SWAP error C8 95 WHILE error C8 96 WAIT error C8 97 MOUSE error C8 98 QUIT Returns FALSE if program run from BASIC editing mode C8 99 SYS error C8 9A BAD INSTALL error C8 9B LIBRARY error C8 9C TINT(,) Reads tint at point C8 9D ELLIPSE error C8 9E BEATS error C8 9F TEMPO Current microbeat tempo C8 A0 VOICES error C8 A1 VOICE error C8 A2 STEREO error C8 A3 OVERLAY error C8 A4 MANDEL error C8 A5 PRIVATE error C8 A6 EXIT error C9 LIST error C9 WHEN error CA NEW error CA OF error CB ENDCASE error CB OLD error CC ELSE error CC OTHERWISE error CC RENUMBER error CD ENDIF error CD SAVE error CE EDIT error CE ENDWHILE error CF PTR= error D0 PAGE= error D1 TIME= error D2 LOMEM= error D3 HIMEM= error D4 SOUND error D5 BPUT error D6 CALL error D7 CHAIN error D8 CLEAR error D9 CLOSE error DA CLG error DB CLS error DC DATA error - though check extensions DD DEF error DE DIM(array()) Returns size of array DE DIM(array(),element) Returns size of array element DE DIM(struct{}) Returns size of structure DF DRAW error E0 END Returns end of BASIC's variable heap E1 ENDPROC error E2 ENVELOPE error E3 FOR error E4 GOSUB error E5 GOTO error E6 GCOL error - though check extensions E7 IF error E8 INPUT error E9 LET error EA LOCAL error EB MODE Returns current screen mode EC MOVE error ED NEXT error EE ON error EF VDU Returns the VDU variable at offset F0 PLOT error F1 PRINT error F2 PROC error F3 READ error F4 REM error F5 REPEAT error F6 REPORT error F6 24 REPORT$ Returns error message for last error F7 RESTORE error F8 RETURN error F9 RUN error FA STOP error FB COLOUR error - though check extensions FC TRACE Handle of current TRACE file FD UNTIL error FE WIDTH Returns print output width FF OSCLI Passes to operating system, returns return value Operators - = ================================== 21 ! 32-bit indirection 2A * Multiplication. 2B + Addition or string concatenation. 2C , print seperator 2D - Negation or subtraction. 2E . decimal number 2F / Division. 3C < Less than. 3C 3C << Shift left 3C 3D <= Less than or equal. 3D = Equality. 3D 3E <> Inequality. 3E > Greater than. 3E 3D >= Greater than or equal. 3E 3E >> Shift right signed 3E 3E 3E >>> Shift right unsigned 3F ? 8-bit indirection 5E ^ Raise to power. 80 AND Bitwise AND. 81 DIV Integer division. 82 EOR Bitwise exclusive-OR. 83 MOD Modulus. 84 OR Bitwise OR. Is there anything strictly stopping !, ? being operators? fred=1!2:jim=3?4:PRINT 5!6,7?8 Operators - = ================================== 2A 3D *= Multiplication. 2B 3D += Addition or string concatenation. 2D 3D -= Negation or subtraction. 2F 3D /= Division. 80 3D AND= Bitwise AND. 81 3D DIV= Integer division. 82 3D EOR= Bitwise exclusive-OR. 83 3D MOD= Modulus. 84 3D OR= Bitwise OR. Binary Indirection - = ================================================== 21 ! 32-bit indirection 3F ? 8-bit indirection 7C | 40-bit indirection SkipSpace subroutine deals with line continuation character BBFW: Shouldn't =QUIT return TRUE if compiled, FALSE if IDE? Within expression evaluator find_var scans for labels if variable not found.