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-THENwith support for both statement execution and line jumps - Loops:
FOR-NEXTloops with optionalSTEPvalues (including negative steps) - Jumps:
GOTOfor unconditional jumps to line numbers - Subroutines:
GOSUBandRETURNfor subroutine calls
- Mathematical:
ABS(),SIN(),COS(),TAN(),SQR(),INT(),RND() - String Functions:
LEN(),VAL(),STR$(),CHR$(),ASC()
- Output:
PRINTwith support for expressions, separators (,for tabs,;for no separation) - Input:
INPUTwith optional prompts for user data entry - Comments:
REMfor 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.exeRUN- Execute the loaded programLIST- Display program linesVARS- Show variables in memoryNEW- Clear program and variablesHELP- Show available commandsQUITorEXIT- Exit the interpreter
10 LET A = 10
20 LET B = 5
30 PRINT "A + B = "; A + B
40 PRINT "A ^ B = "; A ^ B10 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 10010 GOSUB 1000
20 PRINT "Back from subroutine\n"
30 END
1000 PRINT "Inside subroutine\n"
1010 RETURN