A comprehensive (and small) BASIC language interpreter implementation in C that supports classic BASIC programming features and syntax.
- Variables: Numeric and string variables with automatic type detection
- Data Types: Numbers (double precision) and strings
- Operators: Arithmetic (
+
,-
,*
,/
,^
,MOD
), comparison (=
,<>
,<
,<=
,>
,>=
), and logical (AND
,OR
,NOT
) - String Operations: Concatenation and comparison
- Conditional Statements:
IF-THEN
with support for both statement execution and line jumps - Loops:
FOR-NEXT
loops with optionalSTEP
values (including negative steps) - Jumps:
GOTO
for unconditional jumps to line numbers - Subroutines:
GOSUB
andRETURN
for subroutine calls
- Mathematical:
ABS()
,SIN()
,COS()
,TAN()
,SQR()
,INT()
,RND()
- String Functions:
LEN()
,VAL()
,STR$()
,CHR$()
,ASC()
- Output:
PRINT
with support for expressions, separators (,
for tabs,;
for no separation) - Input:
INPUT
with optional prompts for user data entry - Comments:
REM
for program documentation
- Line Numbers: Traditional BASIC line numbering system
- Program Loading: Load and execute BASIC programs from files
- Interactive Mode: Direct command execution and program development
# Run a BASIC program from file
basic.exe program.bas
# Start interactive mode
basic.exe
RUN
- Execute the loaded programLIST
- Display program linesVARS
- Show variables in memoryNEW
- Clear program and variablesHELP
- Show available commandsQUIT
orEXIT
- Exit the interpreter
10 LET A = 10
20 LET B = 5
30 PRINT "A + B = "; A + B
40 PRINT "A ^ B = "; A ^ B
10 LET NAME$ = "World"
20 PRINT "Hello " + NAME$ + "!\n"
30 PRINT "Length: "; LEN(NAME$)
10 FOR I = 1 TO 10 STEP 2
20 PRINT I; " ";
30 NEXT I
40 PRINT "\n"
50 IF A > B THEN PRINT "A is greater\n"
60 IF A < B THEN GOTO 100
10 GOSUB 1000
20 PRINT "Back from subroutine\n"
30 END
1000 PRINT "Inside subroutine\n"
1010 RETURN