A BASIC interpreter written in Python. Reads .bas files, tokenises them, parses the commands, and runs them. No classes, no external libraries. Just functions calling functions.
Python 3
Pass a test file and run it:
python3 src/main.py tests/test_print.basYou'll see the output right in your terminal. The interpreter prints RUN, executes your program line by line, then prints END when it finishes or hits an END statement.
The usual BASIC stuff. Nothing fancy.
10 LET X = 5
20 LET Y = X * 2 + 1
30 PRINT Y10 PRINT "Hello"
20 PRINT "The value is "; XSemicolons keep output on the same line. Without them you get a newline. Strings go in double quotes.
10 PRINT "Enter a number"
20 INPUT X
30 PRINT "Twice that is "; X * 210 FOR I = 1 TO 10
20 PRINT I
30 NEXT IFOR loops count up. The loop variable increments by 1 each time. NEXT jumps back to the line after the FOR statement.
10 IF X > 5 THEN PRINT "Big"
20 IF Y = 0 THEN GOTO 100
THEN can run a PRINT, a GOTO, or a LET. Simple comparisons only: =, >, <, >=, <=.10 GOTO 50
20 PRINT "Skipped"
50 PRINT "Here"Every line needs a line number. GOTO jumps to that number. Labels aren't supported, use line numbers instead.
10 REM This does nothing
REM lines get ignored. Useful for leaving notes.cd tests
./run_tests.shThis will print a pass/fail for each test.