Stupid Python Trick #5: BASIC

This is the place to post any code that you want to share with the community. Only completed scripts should be posted here.

Stupid Python Trick #5: BASIC

Postby ichabod801 » Mon Mar 04, 2013 4:15 pm

The first programming language I learned was BASIC. Not Visual Basic, kids. We're talking old fashioned Beginner's All-Purpose Symbolic Instruction Code, with line numbers and everything. When I was working on the first Stupid Python Trick (Hunt the Wumpus), I realized that the original Dartmouth BASIC isn't that complicated a language. So I decided to write my own BASIC interpreter in Python.

It's not exactly Dartmouth BASIC, but it's reasonably close. The link above points to a zip folder with three files in it. First is basic.py, which is a cmd based BASIC interpreter, including features for writing programs. I guess you could call it an IDE, but that would sort of be stretching it. The second file is wumpus.bsc, which is the original Hunt the Wumpus program, with slight modifications to fit with Ichabod BASIC. The third file is BF.bsc, which is a brainfuck interpreter. It just seemed perfectly silly to run a brainfuck interpreter in a BASIC interpreter in a Python interpreter. Note that BF.bsc uses integers instead of symbols for all of the commands.

WARNING: Ichabod BASIC uses eval and exec, so read over any third party BASIC programs before running them to make sure there isn't any embedded Python code.
Craig "Ichabod" O'Brien
Minimalist, buddhist, theist, and programmer
Current languages: Python, SAS, and C++
Previous serious languages: R, Java, VBA, Lisp, HyperTalk, BASIC
ichabod801
 
Posts: 84
Joined: Sat Feb 09, 2013 12:54 pm
Location: Outside Washington DC

Re: Stupid Python Trick #5: BASIC

Postby sheffieldlad » Mon Mar 04, 2013 7:34 pm

I'm really looking forward to trying this when I get home.
I have fond memories of sitting in front of my Atari 800xl as a kid hacking out little programs in basic.

Thanks for posting it. :)
Python 2.7
Windows XP
sheffieldlad
 
Posts: 37
Joined: Sat Feb 09, 2013 3:03 pm
Location: UK

Re: Stupid Python Trick #5: BASIC

Postby ichabod801 » Mon Mar 04, 2013 8:10 pm

Cool, let me know if you have any problems. Two things of note: First, you can extend the functions allowed pretty easily by writing a Python function and then putting it in the variables dict attribute of the cmd instance (take a look at the end of the program to see what I'm talking about). Second, the main deviation from BASIC is that DATA statements have to come before the associated READ statement. There is only one pass through the program, so there is no initial pass to parse the DATA statements.
Craig "Ichabod" O'Brien
Minimalist, buddhist, theist, and programmer
Current languages: Python, SAS, and C++
Previous serious languages: R, Java, VBA, Lisp, HyperTalk, BASIC
ichabod801
 
Posts: 84
Joined: Sat Feb 09, 2013 12:54 pm
Location: Outside Washington DC


Return to Completed Scripts

Who is online

Users browsing this forum: Google [Bot] and 1 guest