A lightweight, cross-platform GW-BASIC / MSX-BASIC–inspired interpreter written in modern C++.
This project focuses on language compatibility, correctness, and clarity, not on emulating old hardware.
It is designed to run in a modern terminal while preserving the look & feel and semantics of classic BASIC.
- Line-numbered programs
- Immediate (REPL) mode
- Numeric (
Double) and string variables ($) - Expressions with correct precedence
- IF / THEN
- GOTO / GOSUB / RETURN
- FOR / NEXT (supports nested loops)
- DIM (1D arrays, implicit DIM 0..10)
- READ / DATA / RESTORE
- DEFINT
- REM comments
- Math:
SIN,COS,TAN,ATN,LOG,EXP,SQR,ABS,INT,SGN - Strings:
LEN,LEFT$,RIGHT$,MID$,CHR$,ASC,STR$,VAL - Random:
RND()(GW-BASIC–style behavior) - Time:
TIME/TIME() - Formatting:
TAB(n)
RND()→ next random numberRND(0)→ repeat last random numberRND(x > 0)→ next random numberRND(x < 0)→ reseed usingabs(x)RANDOMIZE [seed]supported
ON INTERVAL n GOSUB linenis in 1/60th second ticks (GW/MSX compatible)
INTERVAL ONINTERVAL OFFINTERVAL STOP- Safe interrupt handling with proper resume semantics
PRINTwith,and;INPUTCLSLOCATE row, col [, cursor]- cursor:
0 = hide,1 = show
- cursor:
COLOR f, b(ANSI-mapped, GW-BASIC color palette)- Cursor-aware printing (
TAB, column tracking)
- Built-in line editor
- Handles insertion, deletion, navigation
- Immediate execution
RUN,LIST,NEW,CLEAR,CONTQUIT/EXIT- Ctrl+C stops a running program (returns to REPL)
- UP arrow recalls last command
clang++ -std=c++20 -O2 *.cpp -o basic
./basic