This page documents statements, functions, directives, and system variables as implemented in the current interpreter. Behaviour can change between releases — confirm edge cases in the CHANGELOG and README on GitHub.
If the first non-blank line has no leading digits, the loader assigns internal line numbers; labels and structured blocks still work.
Shebang
#!/usr/bin/env basic on line 1 is ignored.
Compact CBM syntax
At load time, forms like IFX<0THEN, FORI=1TO9, GOTO410 are normalized with spaces so the parser accepts them.
Statement separator
: runs multiple statements on one line: A=1 : B=2 : PRINT A+B.
Operators and expressions
Kind
Operators
Relational
<, >, =, <=, >=, <>
Arithmetic
+, -, *, /, ^ (power), MOD (floored modulo)
Bitwise
<<, >>, AND, OR, XOR (integer parts of operands)
Strings
Concatenation with +; string/numeric comparisons where applicable
RND(x) — Returns a value in 0..1 (uniform via rand()). If x < 0, the generator is reseeded (C64-style negative seed); the implementation uses time so runs differ, similar in spirit to RND(-TI) on a C64.
Variables
Kind
Rules
Numeric
Names up to 31 significant characters; _ allowed.
String
Name ends with $.
Arrays
DIM A(10), DIM B(2,3) — indices are 0-based: DIM A(10) allows 0..10; DIM C(2,3) is a 3×4 matrix.
Reserved words
Identifiers that match keywords (IF, FOR, PRINT, …) cannot be variable names. Labels may still use names that look like keywords in some cases (e.g. CLR:).
Meta directives (# prefix)
Processed at load time. #OPTION values in the file override the same CLI flag.
Directive
Purpose
#INCLUDE "path"
Splice another file at this line. Avoid duplicate line numbers across includes; mixed numbered/numberless rules apply — errors are load-time.
#OPTION petscii
Same as -petscii.
#OPTION petscii-plain
Same as -petscii-plain.
#OPTION charset upper / #OPTION charset lower
PETSCII letter set.
#OPTION palette ansi / #OPTION palette c64
PETSCII colour mapping.
#OPTION maxstr N
String length limit (1–4096; default large).
#OPTION columns N
Print width (1–255; default 40).
#OPTION nowrap
Do not wrap at column width.
#OPTION memory c64 / pet / default
basic-gfx / canvas WASM only — virtual memory layout for POKE/PEEK.
Expressions; ; suppresses newline; , advances to comma zones (width scales with -columns).
INPUT
Read into variables; optional "prompt"; form. In basic-gfx, reads from the window queue. With stdin (terminal), supports pipes.
GET
Non-blocking single-character read into a string variable. If nothing waiting, result is "". Enter is CHR$(13) so ASC(K$)=13 works.
Assignment and control
Statement
Summary
LET
Optional; A=1 is fine without LET.
IF … THEN
Inline (IF X THEN 100, IF X THEN PRINT "Y") or block: IF … [ELSE] … END IF. Nested blocks supported.
WHILE … WEND
Pre-test loop.
DO … LOOP
Infinite until EXIT; or LOOP UNTIL expr. EXIT exits the innermostDO.
FOR … NEXT
Numeric FOR with optional STEP (positive or negative).
GOTO
Target is a line number or label.
GOSUB / RETURN
Subroutine stack; target line or label.
ON expr GOTO / ON expr GOSUB
Multi-way branch (e.g. ON N GOTO 100,200,300).
Data and comments
Statement
Summary
READ / DATA
Read literals into variables.
RESTORE
Reset DATA pointer; RESTORE line positions to first DATA at or after line.
REM / '
Comment to end of line.
END / STOP
Stop execution.
Arrays and structured data
Statement
Summary
DIM
Declare numeric or string arrays (1-D or multi-D).
SORT arr [, mode]
In-place 1-D sort. mode: 1 or "asc" (default) ascending; -1 or "desc" descending; numeric or string arrays.
SPLIT str$, delim$ INTO arr$
Split into a pre-DIMmed 1-D string array.
JOIN arr$, delim$ INTO result$ [, count]
Join; if count omitted, uses count from last SPLIT.
Simple functions (DEF FN)
Form
Example
DEF FNname(params) = expr
One-line numeric function, e.g. DEF FNY(X)=SIN(X).
User-defined procedures (FUNCTION)
Form
Rules
FUNCTION name [(p1, p2, …)] … RETURN [expr] … END FUNCTION
Call with parentheses: n = add(3,5), sayhi(). Parameters are local; recursion supported. RETURN expr returns a value; bare RETURN / END FUNCTION without a prior return yields 0 / "" in expression context.
basic-gfx / canvas:60 Hz jiffy counter (wraps per README). Native terminal:not jiffies — implementation uses Unix time (seconds) as a fallback so RND(-TI) still reseeds. Canvas WASM (gfx): derived from monotonic clock when per-frame ticks are not used.
TI$
Gfx: string HHMMSS from jiffy clock. Terminal:wall-clockHHMMSS from local time.
Identifiers starting with TI are resolved with CBM-style rules ( TI vs TI$ ).
Where features work
Feature
basic (terminal)
basic-gfx
Browser WASM
File I/O, ARG$, SYSTEM, EXEC$
Yes
Yes
SYSTEM/EXEC$ stubbed; HTTP$ for network
HTTP$ / HTTPSTATUS
Returns "" / 0
Same
Yes (CORS)
POKE / PEEK
No-op / 0
Virtual memory
Canvas host
Sprites, bitmap, SCROLL, gamepad
Error / stub
Yes
Canvas parity (see upstream)
INKEY$()
"" (no key queue)
Yes
Yes (hosted input)
Reserved words (identifiers)
The interpreter keeps a fixed reserved_words[] table in basic.c: every keyword for statements and intrinsics (PRINT, FUNCTION, SPRITECOLLIDE, HTTPSTATUS, LOOP, EXIT, …) plus tokens such as INK, DOWN, JOIN, XOR, etc. Do not use those spellings as variable names. (Exact rules for labels vs identifiers are described in the upstream README.)
github.com/omiq/rgc-basic — source, examples/, tests (many examples also open in the Web IDE via ?file=<name>.bas&platform=rgc-basic when bundled in the IDE preset)