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
10LET A =1020LET B =530PRINT"A + B = "; A + B
40PRINT"A ^ B = "; A ^ B10LETNAME$ ="World"20PRINT"Hello "+NAME$ +"!\n"30PRINT"Length: "; LEN(NAME$)10FOR I =1TO10 STEP 220PRINT I; " ";
30NEXT I
40PRINT"\n"50IF A > B THENPRINT"A is greater\n"60IF A < B THENGOTO10010GOSUB100020PRINT"Back from subroutine\n"30END1000PRINT"Inside subroutine\n"1010RETURN