Menu

basicref

Ekkehard Morgenstern

BASIC Interpreter Reference

Much on this page is probably still incomplete. I'll add more descriptions as time permits.

Commands / Statements

exit/quit - exit the interpreter (currently hardcoded)

EXIT - to be done (as a true BASIC statement)

QUIT - to be done (as a true BASIC statement)

WHY - gives detailed reason for last error (also in WHY$ variable) (useful for debugging interpreter)

PRINT - print a line of text; currently, the tab character is output as an undefined character, because it is not interpreted yet. Can be abbreviated by ?.

LET - (optional before assignment) an assignment expression, i.e. LET A = 5

LABEL - (optional before labels) defines a label, i.e. LABEL alpha

GOTO - goes to a label, i.e. GOTO alpha

GOSUB - goes to a label, remembering return position, i.e. GOSUB alpha

RETURN - returns from a GOSUB call

Expressions

alpha - a numeric variable name or statement label. Name must begin with a letter or underscore, and may contain letters, digits or underscores afterwards. The variable is considered to be a label if used alone in statement context.

alpha$ - a string variable; string length is limited only by memory.

var(n) - an array (string$ or numeric). No DIM required. Arrays are automatically resized. The maximum array size is 65536 elements (to avoid memory-related crashes due to a program running haywire).

1234.53 - a number. All numbers are floating-point, except in integer context. To convert them to an integer, numbers are truncated (rounded towards zero).

( e ) - sub expressions

+a - unary plus operator (does nothing)

-a - unary minus operator (negation)

NOT a - unary NOT operator (binary inversion of integral number)

a * b - multiplication

a / b - division

a MOD b - division remainder (modulo operation)

a ^ b - power operation

a + b - addition

a$ + b$ - string concatenation

a$ & b$ - string concatenation

a - b - subtraction

a SHL b - integral binary shift left operation

a SHR b - integral binary shift right operation

a = b - equality test

a <> b - inequality test

a <= b - less or equal test

a >= b - greater or equal test

a < b - less than test

a > b - greater than test

a AND b - binary integer AND operation

a OR b - binary integer OR operation

a XOR b - binary integer XOR operation

Functions

STR$(n) - converts number to string

DEC$(n) or DEC$(n,m) -- convert number to string (m = number of digits)

HEX$(n) or HEX$(n,m) -- convert number to string (m = number of digits)

OCT$(n) or OCT$(n,m) -- convert number to string (m = number of digits)

BIN$(n) or BIN$(n,m) -- convert number to string (m = number of digits)

VAL(a$) - converts string to number

ASC(a$) - returns ordinal number of first character in string

LEFT$(a$,n) -- returns left-hand sub string of a string (positions are 1-based)

RIGHT$(a$,n) -- returns right-hand sub string of a string (positions are 1-based)

MID$(a$,p,n) or MID$(a$,p) -- returns sub string of a string starting at position p and progressing for at most n characters (if omitted, all that remain)

RND(n) -- return random number in the range 0 to n, exclusively. A good value for n is 1.

Built-in Variables

WHY$ - last failure reason report

TI$ or TIME$ - a representation of the current time in HH:MM:SS format (24 hour)

DATE$ - a representation of the current date in YYYY-MM-DD format


Project Admins:


Related

Wiki: Home

MongoDB Logo MongoDB
Gen AI apps are built with MongoDB Atlas
Atlas offers built-in vector search and global availability across 125+ regions. Start building AI apps faster, all in one place.