You are browsing as a guest. Sign up (or log in) to start making projects!

Dartmouth BASIC Interpreter

  • 9 Devlogs
  • 22 Total hours

An interpreter for Dartmouth BASIC

Super Star

As a prize for your great work, look out for a bonus prize in the mail :)

Ship #1

I made a BASIC interpreter + old school recreation of the teletype to interface with it on the main server!
The most challenging part of making the interpreter was a pratt parser for doing math operatoins, but after a while i just gave up and used eval to do it for me
The most challenging part of the backend+frontend is getting the api.py to spawn in terminal.pys and talk with them
You SHOULD go look at the specified pages in the manual to know how to use the teletype, maybe a bit on what commands there are and to write a sample program, then also if you get errors look at the 2nd manual

  • 9 devlogs
  • 22h
  • 19.04x multiplier
  • 425 Stardust
Try project → See source code →
Open comments for this post

5h 4m 22s logged

DONE!!! Finally! (hopefully)

I’ve done a bunch of bug hunting and working on the frontend in the past 5 hrs of work,,, so here is the breakdown

Frontend website

I created the frontend for the BASIC interpreter in the “style” of the Dartmouth by adding a CRT effect in CSS
I also made an input thingie from scratch to take keyboard inputs and put them on the screen, all capital letters, and (ctrl+)backspace, spaces, and enter works!
The frontend also connected to the backend API.py via a websocket

Actual interpreter code

I basically just added a case for divide by zero, which results in +infinity (which is ~5.78960e76)

Backend

I took the basis of the communicate.py and turned it into a class and gave one to each client that connected to the websocket server, created using websocket_server

Thats about it I think, i just need to put the server on nest and then change the api url to the prod url and upload the website on netlify

0
0
12
Open comments for this post

2h 54m 50s logged

Over the course of yesterday night and this afternoon I created a python file that spawns terminal.py as a subprocess and it will communicate with it.
This is the first step in creating a websocket, connecting to it, and having an abstracted interface with terminal.py w/o needing to port the interpreter to javascript. I can connect to a websocket server and use the terminal.py from my browser client

0
0
10
Open comments for this post

1h 50m 21s logged

Terminal Done!

I have added a recreation of the original terminal interface, where you
type HELLO answer questions like your student number, problem number,
and then you can write the program in the terminal, run it, save it, etc!

Readme

I also created the readme

0
0
8
Open comments for this post

3h 25m 9s logged

Basically finished

I added a bunch of the orignal error messages from a 1964 manual, and now it is feature complete (minus DIM and DEF)

Next

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!

0
0
6
Open comments for this post

40m 34s logged

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

0
0
3
Open comments for this post

3h 13m 39s logged

It is like 90% complete, and like works REALLY well

Lexer

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!

Interpreter

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

Up Next

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

0
0
3
Open comments for this post

2h 42m 52s logged

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
0
0
3
Open comments for this post

2h 12m 41s logged

Lexer

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

Interpreter

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

Pratt Parser

Currently I am working on the a pratt parser to determine the value of math operations for PRINT and LET and possible other stuff

0
0
5

Delete project?

Are you sure you want to permanently delete this project? This action cannot be undone.

All devlogs, followers, and associated data will be removed.

Followers

Loading…