RGC-BASIC (Retro Game Coders BASIC) is a modern interpreter with classic Commodore-style syntax. This page walks through the basics. Each box below is a real interpreter running in your browser (WebAssembly).
make basic-wasm-modular, then serve the
web/ folder over HTTP (WASM does not load from file:// in most browsers).
Example: cd web && python3 -m http.server 8080 — then open this file’s URL.
Programs use line numbers (like 10, 20) or can be written without them — the interpreter accepts both.
PRINT writes to the screen. END stops the program. Press Run to execute.
Use a semicolon (;) to print items without a newline between them. Commas (,) move to the next print “zone” (tab-like).
Arithmetic uses + - * / with normal precedence.
Numeric variables are letters or words (e.g. A, SCORE). String variables end with $.
LET is optional: LET X = 1 and X = 1 are the same.
INPUT reads what the user types. After you click Run, a prompt appears under the output — type a value and press Enter.
String variables end with $; numeric variables do not.
IF condition THEN … runs the rest of the line when the condition is true. Here, one INPUT is followed by several one-line IFs.
(RGC-BASIC also supports multi-line IF … THEN … ELSE … END IF — see the examples in the repo.)
FOR repeats a block until NEXT. The loop variable counts from the start value through the limit. The step is 1 unless you add
STEP n (which can be negative to count down).
WHILE condition tests before each iteration. The lines between WHILE and WEND run only while the condition is true.
If it is false at the start, the body never runs. Use this when you do not know in advance how many times you need to loop.
DO … LOOP UNTIL condition runs the body, then repeats until the condition is true (so the body always runs at least once).
A plain DO … LOOP with no UNTIL repeats forever unless you use EXIT — execution continues on the line after LOOP.
EXIT only leaves the innermost DO loop (see tests/do_exit.bas in the repo).
String variables end with $. RGC-BASIC includes C64-style MID$, LEFT$, RIGHT$ (1-based positions),
LEN, VAL, STR$, CHR$, ASC, INSTR (optional third argument: start position),
REPLACE, TRIM$ / LTRIM$ / RTRIM$, UCASE$ / LCASE$, and FIELD$ (delimited “columns”).
SPLIT string$, delim$ INTO array$ fills a pre-DIMed string array; JOIN array$, delim$ INTO result$ [, count] builds a string back.
HEX$ and DEC convert to/from hex; STR$ formats a number as text. For searching inside arrays, use INDEXOF / LASTINDEXOF (see README.md). JSON$ extracts values from JSON text.
Declare arrays with DIM name(size) or DIM name(rows, cols) for two dimensions. Indices are 0-based:
DIM A(10) allows A(0) through A(10). Likewise DIM M(2,3) is a 3×4 grid — row indices 0..2, column indices 0..3.
Use nested FOR loops to walk a table. String arrays use a $ name, e.g. DIM T$(20).
Multi-line functions use FUNCTION name (a, b, …) … RETURN expr … END FUNCTION. Call with parentheses: add(2, 3).
Parameters are local; recursion is allowed. For a small formula on one line, classic DEF FN still works: DEF FNSQ(X) = X*X then FNSQ(5).
Larger examples with #INCLUDE live under examples/tutorial_functions.bas and examples/tutorial_lib.bas.
REM starts a comment (everything after it on that line is ignored). An apostrophe ' also starts a comment.
Always finish interactive examples with END or STOP when you are done.
On your computer, install the release or build from source, then run ./basic examples/hello.bas (or any .bas under examples/).
The repository README.md lists statements, functions, PETSCII colour tokens in strings, file I/O, and more.
For embedding interpreters in your own pages, see docs/tutorial-embedding.md.
Edit the program below and experiment — for example, add a second PRINT or change the message.
After you stop typing for about half a second, the run updates automatically (you can still use Run anytime).
With the editor focused, Ctrl+Enter (Windows/Linux) or Cmd+Enter (macOS) runs immediately.