Skip to content

Supported functions and statements

tt1542 edited this page Sep 4, 2026 · 17 revisions

BASCOMP 3.0 Supported Language Features

General notes

  • INTEGER values 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.

Supported statements

Comments

REM This is a comment
' This is also a comment

Assignment

LET is optional.

LET A = 10
A = A + 1
A$ = "HELLO"

INPUT

INPUT "NAME", N$
INPUT "VALUE", A
! A

Supported forms:

  • INPUT ["prompt",] variable
  • INPUT ["prompt",] variable$
  • ! variable as shorthand for INPUT variable

Ctrl+C and Ctrl+Break terminate the program with errorlevel 130 while console input is waiting.

LINE INPUT

LINE INPUT #1, A$

Syntax:

LINE INPUT #channel, stringVariable$

PRINT

PRINT "HELLO"
? A
PRINT #2, "VALUE="; A

Supported forms:

  • PRINT [item [,|; item] ...]
  • ? as shorthand for PRINT
  • 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.

Program control

Supported statements include:

  • IF ... THEN ... [ELSE ...]
  • multi-line IF ... THEN, ELSEIF ... THEN, ELSE, END IF
  • ENDIF as an alternative to END IF
  • GOTO
  • GOSUB and RETURN
  • ON expression GOTO ...
  • ON expression GOSUB ...
  • FOR ... TO ... [STEP ...], NEXT, END FOR, EXIT FOR
  • WHILE ..., WEND, EXIT WHILE
  • DO, LOOP, and EXIT DO
  • SELECT CASE, CASE, CASE ELSE, END SELECT, and EXIT SELECT
  • END [errorlevel]
  • STOP and . as aliases for END

Arrays and declarations

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.

File and directory operations

  • OPEN ... FOR INPUT AS #channel
  • OPEN ... FOR OUTPUT AS #channel
  • CLOSE #channel
  • KILL file$
  • GET #channel, [position,] variable
  • PUT #channel, [position,] variable
  • CHDIR path$
  • MKDIR path$
  • RMDIR path$
  • FILES [filespec$]

Screen, graphics, sound, and hardware access

  • CLS
  • LOCATE row, column
  • COLOR foreground, background
  • SCREEN mode
  • PSET x, y, color
  • LINE (x1,y1)-(x2,y2), color [,B|BF]
  • CIRCLE (x,y), radius [,color][,,,aspect]
  • BEEP
  • DEF SEG
  • DEF SEG = expression
  • POKE offset, value
  • POKE segment, offset, value
  • OUT port, value
  • CALLINT interruptNumber, registerArray

DATA and low-level code blocks

  • DATA value [,value ...]
  • READ variable
  • RESTORE
  • DATAB byte [,byte ...]
  • CALLDATA lineNumber

DATA and DATAB values may be pure integer constant expressions that BASCOMP can fold at compile time.

External string-array operations

  • XSET handle, index, stringExpression
  • XFREE handle

Control structures

IF / ELSE

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"
ENDIF

Boolean 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

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 SELECT
SELECT CASE NAME$
  CASE "ALICE", "BOB"
    PRINT "KNOWN"
  CASE ELSE
    PRINT "OTHER"
END SELECT

EXIT SELECT leaves the active selection block.

FOR / NEXT

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 I

END FOR is accepted as an explicit terminator for the innermost active FOR loop.

WHILE / WEND

A = 0
WHILE A < 10
  A = A + 1
  IF A = 5 THEN EXIT WHILE
WEND

DO / LOOP

Supported forms are:

DO
  statements
LOOP
DO WHILE condition
  statements
LOOP
DO UNTIL condition
  statements
LOOP
DO
  statements
LOOP WHILE condition
DO
  statements
LOOP UNTIL condition

EXIT DO leaves the innermost active DO loop.

ON GOTO / ON GOSUB

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, SUB2

END and STOP

END 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
.

Data types

INTEGER

Unadorned numeric variables store signed 16-bit values.

A = 123
B = -10

Strings

String identifiers end in $.

A$ = "HELLO"
B$ = A$ + " WORLD"
DIM NAME$ AS STRING * 40

Numeric arrays

DIM A(10)
A(1) = 5
PRINT A(1)
ERASE A

Small arrays are stored in the generated program. Larger arrays use external DOS memory. Indexes start at 1, and invalid indexes cause ARRAY INDEX ERROR.

External string arrays

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 H

Each 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.


Expressions

Integer expressions

Supported elements and operators include:

  • decimal and &H hexadecimal constants
  • variables and numeric array elements
  • TRUE (-1) and FALSE (0)
  • parentheses
  • unary +, -, and NOT
  • +, -, *, /, \, MOD, ^
  • XOR, AND, and OR
  • 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

String expressions support literals, variables, indexed dynamic string arrays, concatenation, nested string functions, and these system values:

  • COMMAND$
  • PROGDIR$
  • DATE$
  • TIME$
  • INKEY$
  • INPUT$

Comparisons

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"

Numeric and conversion functions

LEN(string)

Returns the string payload length, 0 through 255.

VAL(string)

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.

ASC(string)

Returns the first byte as 0 through 255. An empty string returns 0.

EOF(channel)

Returns nonzero at end of file and zero otherwise.

EXIST(string)

Returns nonzero if the file can be opened for input, otherwise zero.

INSTR(string, pattern)

INSTR(start, string, pattern)

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.

ABS(number)

Returns an absolute value. ABS(-32768) cannot be represented as INTEGER and raises INTEGER OVERFLOW.

SGN(number)

Returns -1, 0, or 1 according to the sign of the value.

INT(number)

Returns its INTEGER argument unchanged and is provided mainly for compatibility.

SQR(number)

Returns the integer square root. A negative argument returns 0.

MIN(a, b) and MAX(a, b)

Return the smaller or larger INTEGER value.

RND(n)

Returns an INTEGER from 1 through n; returns 0 when n <= 0.

TIMER()

Returns seconds since midnight modulo 65536.

EXEC(program$, args$)

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

CPUID()

Typical results are 86, 120, 186, 286, 386, 486, 586, 686, 1500, or 999, as described by the runtime CPU detection routine.

PEEK(offset) and PEEK(segment, offset)

Read one byte and return 0 through 255.

INP(port)

Reads one byte from an I/O port.

XALLOC(count [, maxLength])

Allocates an external string array and returns a handle. Allocation failure returns 0. Invalid access through the returned interface raises XARRAY ERROR.

CHR$(number)

Returns a one-byte string containing the low byte of the argument.

STR$(number)

Returns signed decimal text without a leading space for positive values.

HEX$(number), OCT$(number), and BIN$(number)

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.

LEFT$(string, count)

Returns at most count bytes from the left. Counts larger than the source length are clamped.

RIGHT$(string, count)

Returns at most count bytes from the right. Counts larger than the source length are clamped.

MID$(string, start, count)

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.

SPACE$(count)

Returns count spaces. Counts below 0 produce an empty string; counts above 255 are clamped to 255.

STRING$(count, charCode)

Returns a repeated low-byte character. The count is clamped to 0 through 255.

LTRIM$(string), RTRIM$(string), and TRIM$(string)

Remove ASCII space characters from the selected edge or edges.

UCASE$(string)

Converts ASCII a through z to uppercase and leaves all other bytes unchanged.

XGET$(handle, index)

Returns an element from an external string array.

COMMAND$

Returns the DOS command tail. Exactly one leading space is removed when present.

PROGDIR$

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.

DATE$ and TIME$

Return DOS date and time as mm-dd-yyyy and hh:mm:ss.

INKEY$

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.

INPUT$

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, DATAB, and CALLDATA

DATA stores signed words read sequentially by READ. RESTORE resets the data pointer.

DATA 10, 20, 30
READ A
RESTORE

DATAB 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 100

Opcode 195 is RET. A called byte block must return correctly. Ordinary DATA records are skipped during normal execution and are never executed as code.


File I/O semantics

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.


Graphics semantics

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.


Limits and compatibility notes

  • 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.

Clone this wiki locally