-
Notifications
You must be signed in to change notification settings - Fork 0
Supported functions and statements
The following list applies to the 2.0 version and will (hopefully) be updated in the future.
- REM and apostrophe comments (' comment)
- LET and implicit assignment without LET
- INPUT ["prompt"], var
- INPUT ["prompt"], var$
- ! var as shorthand for INPUT var
- LINE INPUT #channel, var$
- ? as shorthand for PRINT
- PRINT #channel, ...
- IF ... THEN ... ELSE ...
- multi-line IF ... THEN, ELSEIF ... THEN, ELSE, END IF
- GOTO
- GOSUB + RETURN
- FOR ... TO ... [STEP ...] / NEXT, END FOR
- WHILE ... / WEND
- DIM (for integer arrays)
- OPEN ... FOR INPUT AS #channel
- OPEN ... FOR OUTPUT AS #channel
- CLOSE #channel
- KILL
- GET #channel, [position,] variable
- PUT #channel, [position,] variable
- CLS
- LOCATE row, column
- COLOR foreground, background
- DEF SEG
- POKE address, value
- SELECT CASE, CASE, CASE ELSE, END SELECT
- RANDOMIZE
- RANDOMIZE TIMER / numeric-expression
- XSET handle, index, string-expression
- XFREE handle
- END / STOP / . as shorthand
BASCOMP supports single-line and multi-line IF forms in both the traditional line-numbering and the QB mode.
Single-line form:
IF A > 10 THEN PRINT "HIGH" ELSE PRINT "LOW"Multi-line form:
IF A > 10 THEN
PRINT "HIGH"
ELSEIF A = 10 THEN
PRINT "TEN"
ELSE
PRINT "LOW"
END IFBoolean IF expressions support AND, OR, and NOT in supported comparison contexts.
SELECT CASE supports numeric selection logic:
SELECT CASE A
CASE 1
PRINT "ONE"
CASE 2
PRINT "TWO"
CASE ELSE
PRINT "OTHER"
END SELECTCounted loops are supported, including nested loops and optional STEP values.
FOR I = 1 TO 10 STEP 2
PRINT I
NEXT IEND FOR is also recognized as an explicit loop terminator form.
WHILE A < 10
A = A + 1
WENDSubroutines are supported through GOSUB and RETURN.
Numeric variables store signed 16-bit integer-style values.
String identifiers end with $ and use counted string representation in the runtime.
DIM creates indexed numeric arrays using syntax such as A(I). Small arrays are stored internally; larger arrays can be backed by external DOS memory through the runtime array support.
DIM A(10)
LET A(1) = 5
LET X = A(1)External string arrays are available through:
- XALLOC(count)
- XALLOC(count, maxLength)
- XSET handle, index, string-expression
- XGET$(handle, index)
- XFREE handle
Numeric expressions support:
- decimal constants and variables
- hexadecimal constants with &H...
- numeric array elements such as A(I)
- parentheses
- unary + and unary -
- +, -, *, /, \
- MOD
- XOR
- AND
- OR
- exponentiation with ^
- numeric function calls
String expressions support:
- string variables
- string literals
- string concatenation with +
- string function calls
- DATE$, TIME$, INKEY$, and INPUT$
BASCOMP 2.0 continues the expanded internal string-expression handling introduced before version 2.0. The compiler uses a larger internal string context stack and additional temporary string buffers for nested string functions and concatenations.
The following comparison operators are supported in IF expressions: =, <>, <, >, <=, >=.
Comparisons work for both numeric values and supported string expressions, depending on context.
- LEN(string)
Returns the length of a string. - VAL(string)
Converts a string to a numeric value. - ASC(string)
Returns the character code of the first character. - EOF(channel)
Returns the end-of-file state for a file channel. - EXIST(string)
Tests whether a file exists. - INSTR(string, pattern)
Searches for a substring and returns its position. - INSTR(start, string, pattern)
Searches for a substring starting at a specific position. - ABS(number)
Returns the absolute value. - SGN(number)
Returns -1, 0, or 1 depending on the sign of the value. - RND(number)
Returns a pseudo-random number in the supported runtime range. - INT(number)
Returns the integer value. - SQR(number)
Returns the integer square root. - MIN(a, b)
Returns the smaller value. - MAX(a, b)
Returns the larger value. - TIMER()
Returns the number of seconds since midnight modulo 65536. - EXEC(program$, args$)
Starts a DOS child program and returns 0 on success or a DOS error code. - CPUID()
Detects the CPU class and returns the runtime CPU identifier. See the runtime for details. - PEEK(address)
Reads a byte from the active DEF SEG segment. - XALLOC(count) / XALLOC(count, maxLength)
Allocates an external string array and returns a handle.
- CHR$(number)
Builds a one-character string from a character code. - LEFT$(string, count)
Returns the left part of a string. - MID$(string, start, count)
Returns a substring. - RIGHT$(string, count)
Returns the right part of a string. - LTRIM$(string)
Removes leading spaces. - RTRIM$(string)
Removes trailing spaces. - TRIM$(string)
Removes leading and trailing spaces. - UCASE$(string)
Converts ASCII lowercase letters a to z to uppercase. - STR$(number)
Converts a numeric value to a string. - XGET$(handle, index)
Reads a string from an external string array. - DATE$
Returns the DOS date in mm-dd-yyyy format. - TIME$
Returns the DOS time in hh:mm:ss format. - INKEY$
Returns a non-blocking keyboard input string. - INPUT$
Reads a string from standard input.
Text file I/O is supported through:
- OPEN
- CLOSE
- PRINT #
- LINE INPUT #
Binary file I/O is supported through:
- GET
- PUT
File channels 1 to 9 are supported.
OPEN supports:
- FOR INPUT
- FOR OUTPUT
KILL deletes a file. EXIST() checks whether a file is present.
The runtime retains buffered byte output for PUT; buffered binary output is flushed when required by handle changes, seek operations, close operations, and mixed text/binary output paths.
Standard text output is supported through PRINT.
Additional screen control is provided by:
- CLS
- LOCATE
- COLOR
When screen output support is active, runtime text output to the console can use BIOS text output with the active COLOR attribute.
BASCOMP 2.0 supports a compact BASIC-style memory access subset:
- DEF SEG = expression sets the active segment used by PEEK and POKE.
- DEF SEG resets the active segment to the program segment.
- PEEK(address) returns the byte at the active segment and offset.
- POKE address, value writes a byte to the active segment and offset.
Values written by POKE must fit into a byte (0..255).
BASCOMP 2.0 includes runtime support for:
- DATE$ using DOS date services,
- TIME$ and TIMER() using DOS time services,
- INKEY$ using enhanced BIOS keyboard calls where available,
- EXEC() for launching DOS child programs,
- CPUID() for CPU-class detection.