basic101 is a circa 1980 BASIC interpreter written in Ruby. It supports a modified subset of Microsoft's BASIC-80 v. 5 and runs the games published in Basic Computer Games, Microcomputer Edition by David H. Ahl
Compilers and interpreters are great fun. I wanted to experiment with a modern parser, but needed a target language. The target language of "something that properly runs the programs in Basic Computer Games, Microcomputer Edition is perfect because:
-
BASIC is a relatively simple language.
-
The book's programs are all for the same dialect of BASIC.
-
The book's programs are available in electronic form.
-
The book contains short transcripts of each program running.
This interpreter uses Parslet, a Ruby library for Parsing Expression Grammars (PEG). Parslet has several attractive properties:
-
Parse and transform rules are expressed in an internal DSL. This makes possible the dynamic generation of parse and transform rules.
-
It has an elegant mechanism for transforming the parse tree into an abstract syntax tree.
gem install basic101
First, download a BASIC program such as one of those from Classic Basic Games or Vintage BASIC's archive. Then simply run the interpreter with the path of the program:
basic101 superstartrek.bas
Most of these programs are included with this gem, in the directory:
test/integration/test/basic_computer_games
A few of these programs have had minor changes to work with basic101. This is not unusual in the world of BASIC. Because Microcomputer BASICs were not written to any single specification, they all vary in small details. It was usual, in the day, to have to change a BASIC program to get it to run on the interpreter you were using.
The basic101 interpreter is released under the MIT License.
The BASIC programs which originally appeared in Basic Computer Games, Microcomputer Edition are not under the MIT license. They are included with the kind permission of David H. Ahl. David makes these programs "available to people who want to reprint them, convert them to other languages or forms of Basic, or analyze the code."
basic101 requires Ruby 2.5 or greater.
basic101 was developed in Linux. While it does not knowingly use any Unix-only features, it has not been tested under Windows. I would be grateful for any reports of success or failure running basic101 under Windows (or any other operating system).
To run all tests:
rake test
or just:
rake
To run the rspec (unit) tests:
rake test:spec
To run the integration tests:
rake test:integration
The integration tests are driven by
tests/integration/integration_test.rb
. During development, you
often want to run just one test, not all of them; to do so, bypass the
rake task and run integration_test.rb
directly.
To run only the print test:
integration_test.rb print
To run only the fast tests:
integration_test.rb fast
If you change how the interpreter behaves, the tests will notice. If you want the new behavior to become the expected behavior, then train the test or tests that are affected. Training causes the current behavior to become the expected behavior in the future. To train the print test:
integration_test.rb -t print
To train all tests:
integration_test.rb -t
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
- Basic Computer Games, Microcomputer Edition
- Basic-80 Reference Manual, v. 5
- Vintage BASIC and its source
- Classic Basic Games
This program was inspired by Basic Computer Games, Microcomputer Edition by David H. Ahl. David, Thank you for inspiring us to tinker, learn, and have fun with these wonderful machines.
Lyle Kopnicky wrote Vintage BASIC, an open source BASIC written in Haskell. Vintage BASIC is a valuable resource for any vintage-BASIC author, even if you don't know Haskell. It is a good reference model when you are wondering how some ambiguous part of the language behaves. Be sure to check out the interpreter test for examples in the form of "this program produces that output". You don't have to know Haskell to understand them.
Vintage BASIC's archive of programs for "Basic Computer Games" is similar to that of Classic Basic Games, except that Lyle's archive has two additional programs:
That's a lot of typing. Thank you, Lyle.
Most of the programs from "Basic Computer Games" are available at Classic Basic Games, a wonderful resource for aspiring interpreter writers.
Wayne Conrad [email protected]