-
Notifications
You must be signed in to change notification settings - Fork 0
Supported functions and statements
-
INTEGERvalues are signed 16-bit values in the range -32768 to 32767. - Strings are counted runtime strings with a maximum payload length of 255 bytes.
- File channels are numbered 1 through 9.
- Array indexes are 1-based.
- BASCOMP accepts traditional numbered source and QB-style unnumbered source with named labels.
- In numbered source, line numbers must be unique, strictly ascending, and in the range 1 through 32767. A space or tab may separate the line number from the statement.
REM This is a comment
' This is also a commentLET is optional.
LET A = 10
A = A + 1
A$ = "HELLO"INPUT "NAME", N$
INPUT "VALUE", A
! ASupported forms:
INPUT ["prompt",] variableINPUT ["prompt",] variable$-
! variableas shorthand forINPUT variable
Ctrl+C and Ctrl+Break terminate the program with errorlevel 130 while console input is waiting.
LINE INPUT #1, A$Syntax:
LINE INPUT #channel, stringVariable$PRINT "HELLO"
? A
PRINT #2, "VALUE="; ASupported forms:
PRINT [item [,|; item] ...]-
?as shorthand forPRINT PRINT #channel, ...
A trailing semicolon or comma suppresses the final line break. Screen PRINT sequences periodically check for Ctrl+C or Ctrl+Break. File output is not interrupted by that screen-output check.
Supported statements include:
IF ... THEN ... [ELSE ...]- multi-line
IF ... THEN,ELSEIF ... THEN,ELSE,END IF -
ENDIFas an alternative toEND IF GOTO-
GOSUBandRETURN ON expression GOTO ...ON expression GOSUB ...-
FOR ... TO ... [STEP ...],NEXT,END FOR,EXIT FOR -
WHILE ...,WEND,EXIT WHILE -
DO,LOOP, andEXIT DO -
SELECT CASE,CASE,CASE ELSE,END SELECT, andEXIT SELECT END [errorlevel]-
STOPand.as aliases forEND
DIM A(100)
DIM NAME$ AS STRING * 40
DIM NAMES$(10) AS STRING * 40
ERASE A
ERASE NAMES$ERASE releases external storage and invalidates the selected numeric or dynamic string array. An erased array must be dimensioned again before indexed access.
OPEN ... FOR INPUT AS #channelOPEN ... FOR OUTPUT AS #channelCLOSE #channelKILL file$GET #channel, [position,] variablePUT #channel, [position,] variableCHDIR path$MKDIR path$RMDIR path$FILES [filespec$]
CLSLOCATE row, columnCOLOR foreground, backgroundSCREEN modePSET x, y, colorLINE (x1,y1)-(x2,y2), color [,B|BF]CIRCLE (x,y), radius [,color][,,,aspect]BEEPDEF SEGDEF SEG = expressionPOKE offset, valuePOKE segment, offset, valueOUT port, valueCALLINT interruptNumber, registerArray
DATA value [,value ...]READ variableRESTOREDATAB byte [,byte ...]CALLDATA lineNumber
DATA and DATAB values may be pure integer constant expressions that BASCOMP can fold at compile time.
XSET handle, index, stringExpressionXFREE handle
Single-line and multi-line forms are supported in both source modes.
IF A > 10 THEN PRINT "HIGH" ELSE PRINT "LOW"IF A > 10 THEN
PRINT "HIGH"
ELSEIF A = 10 THEN
PRINT "TEN"
ELSE
PRINT "LOW"
ENDIFBoolean expressions support nested parentheses, AND, OR, repeated NOT, comparisons, and bare numeric truth expressions. Zero is false; nonzero is true.
IF (A > 0 AND B > 0) OR FORCE THEN PRINT "ACTIVE"
IF NOT NOT READY THEN PRINT "READY"SELECT CASE supports numeric and string selector expressions. A CASE may contain multiple comma-separated alternatives.
SELECT CASE A
CASE 1, 2, 3
PRINT "LOW"
CASE 4
PRINT "FOUR"
CASE ELSE
PRINT "OTHER"
END SELECTSELECT CASE NAME$
CASE "ALICE", "BOB"
PRINT "KNOWN"
CASE ELSE
PRINT "OTHER"
END SELECTEXIT SELECT leaves the active selection block.
The initial value and upper bound are numeric expressions. STEP must be a nonzero constant expression.
FOR I = 1 TO 10 STEP 2
IF I = 5 THEN EXIT FOR
PRINT I
NEXT IEND FOR is accepted as an explicit terminator for the innermost active FOR loop.
A = 0
WHILE A < 10
A = A + 1
IF A = 5 THEN EXIT WHILE
WENDSupported forms are:
DO
statements
LOOPDO WHILE condition
statements
LOOPDO UNTIL condition
statements
LOOPDO
statements
LOOP WHILE conditionDO
statements
LOOP UNTIL conditionEXIT DO leaves the innermost active DO loop.
The target index is 1-based. Values outside the target-list range continue after the statement.
ON A GOTO ONE, TWO, THREE
ON B GOSUB SUB1, SUB2END without an argument exits with errorlevel 0. With an argument, the low byte of the numeric result is passed to DOS as the program errorlevel.
END
END 1
STOP
.Unadorned numeric variables store signed 16-bit values.
A = 123
B = -10String identifiers end in $.
A$ = "HELLO"
B$ = A$ + " WORLD"
DIM NAME$ AS STRING * 40DIM A(10)
A(1) = 5
PRINT A(1)
ERASE ASmall arrays are stored in the generated program. Larger arrays use external DOS memory. Indexes start at 1, and invalid indexes cause ARRAY INDEX ERROR.
DIM NAMES$(10) AS STRING * 40
NAMES$(1) = "ALICE"
PRINT NAMES$(1)
ERASE NAMES$Handle-based access is also available:
H = XALLOC(10, 40)
XSET H, 1, "ALICE"
PRINT XGET$(H, 1)
XFREE HEach slot contains one length byte plus maxLength payload bytes. The total allocation must not exceed 65536 bytes:
(maxLength + 1) * elementCount <= 65536
maxLength is 1 through 255. XALLOC(count) uses 255. The runtime provides 16 handle slots.
Supported elements and operators include:
- decimal and
&Hhexadecimal constants - variables and numeric array elements
-
TRUE(-1) andFALSE(0) - parentheses
- unary
+,-, andNOT -
+,-,*,/,\,MOD,^ -
XOR,AND, andOR - numeric functions
A = 10 + 20 * 3
B = (A - 5) \ 2
C = A MOD 7
D = &HFF
E = TRUE AND NOT FALSE
F = 2 ^ 8/ and \ currently use signed integer division. Division by zero raises DIVISION BY ZERO. The special overflow -32768 / -1 raises INTEGER OVERFLOW. Negative exponents raise NEGATIVE EXPONENT. General integer overflow is otherwise not checked.
String expressions support literals, variables, indexed dynamic string arrays, concatenation, nested string functions, and these system values:
COMMAND$PROGDIR$DATE$TIME$INKEY$INPUT$
The operators =, <>, <, >, <=, and >= are supported for compatible numeric or string expressions.
IF A <= 10 THEN PRINT "SMALL"
IF A$ = "OK" THEN PRINT "MATCH"
IF LEFT$(A$, 1) = "Y" THEN PRINT "YES"Returns the string payload length, 0 through 255.
Converts leading signed decimal, hexadecimal (&H or 0x), octal (&O or 0o), or binary (&B or 0b) text to an INTEGER value. Parsing stops at the first unsupported character.
Returns the first byte as 0 through 255. An empty string returns 0.
Returns nonzero at end of file and zero otherwise.
Returns nonzero if the file can be opened for input, otherwise zero.
Returns the 1-based match position or 0. start is a full 16-bit value; values below 1 are treated as 1, and values beyond the source length return 0. An empty pattern returns the effective start position when it is within the source.
Returns an absolute value. ABS(-32768) cannot be represented as INTEGER and raises INTEGER OVERFLOW.
Returns -1, 0, or 1 according to the sign of the value.
Returns its INTEGER argument unchanged and is provided mainly for compatibility.
Returns the integer square root. A negative argument returns 0.
Return the smaller or larger INTEGER value.
Returns an INTEGER from 1 through n; returns 0 when n <= 0.
Returns seconds since midnight modulo 65536.
Runs a DOS child program. A missing filename extension is completed with .COM.
Return values:
-
0..255: normal child-process errorlevel - a negative DOS error code: the program could not be loaded or executed
-
-(256 + terminationType): abnormal child termination reported by DOS
Typical results are 86, 120, 186, 286, 386, 486, 586, 686, 1500, or 999, as described by the runtime CPU detection routine.
Read one byte and return 0 through 255.
Reads one byte from an I/O port.
Allocates an external string array and returns a handle. Allocation failure returns 0. Invalid access through the returned interface raises XARRAY ERROR.
Returns a one-byte string containing the low byte of the argument.
Returns signed decimal text without a leading space for positive values.
Return uppercase hexadecimal, octal, or binary text without unnecessary leading zeroes. Zero returns "0". Negative values are represented by their 16-bit two's-complement bit pattern.
Returns at most count bytes from the left. Counts larger than the source length are clamped.
Returns at most count bytes from the right. Counts larger than the source length are clamped.
Returns up to count bytes beginning at the 1-based start position. Starts below 1 are treated as 1; starts beyond the source return an empty string.
Returns count spaces. Counts below 0 produce an empty string; counts above 255 are clamped to 255.
Returns a repeated low-byte character. The count is clamped to 0 through 255.
Remove ASCII space characters from the selected edge or edges.
Converts ASCII a through z to uppercase and leaves all other bytes unchanged.
Returns an element from an external string array.
Returns the DOS command tail. Exactly one leading space is removed when present.
Returns the path prefix of the running COM program, including the final path separator when present. It may return an empty string when DOS supplies no usable program-path information.
Return DOS date and time as mm-dd-yyyy and hh:mm:ss.
Performs non-blocking BIOS keyboard input. No key returns an empty string. A normal key returns one byte. A special key returns two bytes: zero followed by the scan code. Ctrl+C terminates with errorlevel 130.
Performs line-oriented console input into a counted string. Input ends at Enter or 255 bytes. Backspace editing is supported. Ctrl+C and Ctrl+Break terminate with errorlevel 130.
DATA stores signed words read sequentially by READ. RESTORE resets the data pointer.
DATA 10, 20, 30
READ A
RESTOREDATAB emits raw bytes into the generated program. CALLDATA calls the block associated with a numbered source line as machine code.
100 DATAB 195
110 CALLDATA 100Opcode 195 is RET. A called byte block must return correctly. Ordinary DATA records are skipped during normal execution and are never executed as code.
Text I/O uses OPEN, CLOSE, PRINT #, and LINE INPUT #. Binary byte I/O uses GET and PUT.
GET and PUT positions are 1-based. Binary values must fit in 0 through 255. Runtime errors distinguish invalid channels, unopened channels, wrong channel modes, channel reuse, bad positions, read-past-EOF, and file read/write failures.
Buffered PUT output is flushed on buffer completion, handle changes, seeks, matching text output, and close operations.
Known SCREEN mappings are:
-
SCREEN 0: BIOS mode 03h -
SCREEN 1: BIOS mode 04h -
SCREEN 2: BIOS mode 06h - other values: low byte passed as the BIOS mode number
SCREEN 0 marks graphics mode as inactive. Program termination restores text mode only when a graphics mode remains active.
LINE uses integer Bresenham drawing. B draws an outline rectangle and BF a filled rectangle. CIRCLE uses an integer midpoint algorithm. The aspect value is scaled so 256 means 1.0.
- Numbered source lines: 1 through 32767, strictly ascending and unique.
- FOR, WHILE, and DO nesting share a maximum depth of 4.
- Block IF nesting depth is 4.
- Numeric parser context depth is 4.
- String parser context depth is 8.
- Nested boolean-parenthesis context depth is 4.
- Nested single-line THEN/ELSE context depth is 2.
- String payload length is at most 255 bytes.
- File channels are 1 through 9.
- Numeric and string array indexes are 1-based.
- External numeric arrays contain at most 32767 16-bit elements.
- One external string-array allocation is at most 65536 bytes.
- EMS and XMS are not supported.