Dartmouth BASIC Interpreter
- 6 Devlogs
- 14 Total hours
An interpreter for Dartmouth BASIC
An interpreter for Dartmouth BASIC
I added a bunch of the orignal error messages from a 1964 manual, and now it is feature complete (minus DIM and DEF)
What i’d like to do next is create the terminal interface as described in this manual, on pages 16-18.
It would be cool to say HELLO and then type in a user id, program id, write the program and save it, and even run it. I think it would feel very fitting!
I implemented the skipping FOR loops if they are invalid. ex for i = 0 to 10 step -1
I also created a few test programs and ran then to see if they worked (they did)
Here is my pythagarian triangle finder:
10 FOR A = 1 TO 50 STEP 1
20 FOR B = 1 TO 50 STEP 1
30 LET C2 = A*A + B*B
40 LET C = SQR(C2)
50 IF INT(C)=C THEN 70
60 GOTO 80
70 GOSUB 500
80 NEXT B
90 NEXT A
100 STOP
500 PRINT "PYTHAGARIAN TRIANGLE FOUND";A;B;C
510 RETURN
1000 STOP
I’m highkey a lazy bum and dont want to implement DEF and DIM for my own sanity’s sake, and making better debug screens? goodness no! I’ll be making an interface to type in basic programs now
It is like 90% complete, and like works REALLY well
I updated this a little bit. I changed how the functions are called so instead of doing execute the interpreter calls __str__ on it and it will return the python function to do that operation inside of eval.
As well I updated the parsing so you can put as many spaces or as little between operations as you want and it will still read just fine. like before you could only do ( A * 3 ) / 5 but now things like (A*3)/ 5 work just fine!
I also made strings get read in entirely
Also print statements now can use semicolons to seperate parts of a message on 1 line. like you can do
10 PRINT "A = "; A; " B = ";B
and it will print out “A = {A} B = {B}” with {A} and {B} being replaced with their actual runtime values!
I added some error catching and the global DATA array so the DATA statement can put its data in there
It now catches when you try to NEXT from a for loop that doesnt exist
also it catches when you try to RETURN from a subroutine when you never called a subroutine, as well as making sure that setting the program counter, via things like IF/THEN and GOTO are an actual line defined in the program
I want to finish making sure all the functions and statements work as intended, as well as implementing DEF and DIM
I also REALLY want to get more details error reports, by also giving the line number where an error occurred, possible typo/solutions, etc
Interpreter is basically done, I’ve only got to implement data def dim and read instructions.
I’m highkey fearing making def since my current syntax parsing is fucking abysmal and this will only make it worse.
I’ve also got to work on reading strings in for print statement and highkey most of my syntax reading in ngl
But it does work for some programs like this Fibonacci sequence generator I made
10 LET A = 0
20 LET B = 1
30 LET C = A + B
40 IF C > 144 THEN 100
50 PRINT C
60 LET A = B
70 LET B = C
80 GOTO 30
100 STOP
I’ve got the lexer basically done, maybe a few tweaks a bit later but for the most part i can take in each line of Dartmouth Original BASIC and turn it into a list of lines and symbols to then parse
Currently it keeps track of all the variables and the program counter and runs through each line of BASIC executing it. Atm it looks fine, I just need to create and add the execute function to all of the BASIC statements like STOP, PRINT, IF, and LET
Currently I am working on the a pratt parser to determine the value of math operations for PRINT and LET and possible other stuff