Tiny BASIC


Tiny BASIC is a family of dialects of the BASIC programming language that can fit into 4 or fewer KBs of memory. Tiny BASIC was designed by Dennis Allison and the People's Computer Company in response to the open letter published by Bill Gates complaining about users pirating Altair BASIC, which sold for $150. Tiny BASIC was intended to be a completely free version of BASIC that would run on the same early microcomputers.
Tiny BASIC was released as a specification, not an implementation, published in the September 1975 issue of the PCC newsletter. The article invited programmers to implement it on their machines and send the resulting assembler language implementation back for inclusion in a series of three planned newsletters. Li-Chen Wang, author of Palo Alto Tiny BASIC, coined the term "copyleft" to describe this concept. The community response was so overwhelming that the newsletter was relaunched as Dr. Dobb's Journal, the first regular periodical to focus on microcomputer software. Dr. Dobb's lasted in print form for 34 years and then online until 2014, when its website became a static archive.
The small size and free source code made these implementations invaluable in the early days of microcomputers in the mid-1970s, when RAM was expensive and typical memory size was only 4 to 8 KB. While the minimal version of Microsoft's Altair BASIC would also run in 4 KB machines, it left only 790 bytes free for BASIC programs. More free space was a significant advantage of Tiny BASIC. To meet these strict size limits, Tiny BASIC dialects generally lacked a variety of features commonly found in other dialects, for instance, most versions lacked string variables, lacked floating-point math, and allowed only single-letter variable names.
Tiny BASIC implementations are still used today, for programming microcontrollers such as the Arduino.

History

Altair BASIC

The earliest microcomputers, like the MITS Altair 8800, generally had no built-in input/output beyond front-panel switches and LED lamps. Useful work generally required the addition of an I/O expansion card and the use of some form of terminal. At the time, video-based terminals were very expensive, costing much more than the computer, so many users turned to mechanical devices like the Teletype Model 33. The Model 33, like most teleprinters of the era, included a tape punch system intended to allow operators to pre-record their messages and then play them at "high speed", faster than most individuals could type the message live. For the early microcomputers, this provided a convenient computer data storage format, allowing the users to write programs to paper tape and distribute them to other users.
The Homebrew Computer Club met for the first time in March 1975, and its members soon used the meetings to swap software on punched tape. At the June meeting, a tape containing a pre-release version of Altair BASIC disappeared. The tape was given to Steve Dompier, who passed it on to Dan Sokol, who had access to a high-speed tape punch. At the next meeting, 50 copies of Altair BASIC on paper tape appeared in a cardboard box. When Ed Roberts, founder of MITS, learned of this, he stated "Anyone who is using a stolen copy of MITS BASIC should identify himself for what he is, a thief." Bill Gates made this more formal, writing "An Open Letter to Hobbyists", complaining that "As the majority of hobbyists must be aware, most of you steal your software."

Tiny BASIC

The complaint was not well received. Among the many responses, Bob Albrecht, another Homebrew member and founder of the People's Computer Company, felt the best response would be to produce their own BASIC that was completely free to use by anyone. He approached Dennis Allison, a member of the Computer Science faculty at Stanford University, to write a specification for a version of BASIC that would fit in 2 to 3 kilobytes of memory. To aid porting, the design was based on an intermediate language, an interpreter for the interpreter, which meant only a small portion of the total code had to be ported.
Allison's initial design was published in the September 1975 edition of the PCC newsletter, along with an Intel 8080 version of the IL interpreter. The article called on programmers to implement the design on their computer and send the resulting assembly language version back to the PCC. They stated their plans to publish three special newsletters containing these user-submitted versions, along with bug fixes, programs written in the new BASIC, and suggestions and enhancements. The concept gained further notice when it was republished in the January 1976 edition of the ACM Special Interest Group on Programming Languages. Submissions poured in. Among the notable early versions was Tiny BASIC Extended by Dick Whipple and John Arnold which ran in 3K of RAM, added FOR...NXT loops, and allowed a single numeric array. They avoided the use of the IL and wrote it directly in machine code, using octal.
The first of the three planned newsletters, with the title "Dr. Dobb's Journal of Computer Calisthenics & Orthodontia, Running Light Without Overbyte", was published in January 1976. It starts with a note from Albrecht, under the penname "the dragon", suggesting that three editions would not be enough, and asked the readers if they would like to see it continue. It also reprinted the original article on Tiny BASIC from PCC, included the complete listing of Extended TB, and included a number of small BASIC programs including tips-and-tricks from Allison. Response to the first issue was so impressive that the introduction to the second issue stated they had already decided to continue publishing the new newsletter under the simplified name Dr. Dobb's Journal. Over the next several issues, additional versions of the language were published, and similar articles began appearing in other magazines like Interface Age.

Spread

By the middle of 1976, Tiny BASIC interpreters were available for the Intel 8080, the Motorola 6800 and MOS Technology 6502 processors. This was a forerunner of the free software community's collaborative development before the internet allowed easy transfer of files, and was an example of a free software project before the free software movement. Computer hobbyists would exchange paper tapes, cassettes or even retype the files from the printed listings.
Jim Warren, editor of Dr. Dobb's, wrote in the July 1976 ACM Programming Language newsletter about the motivations and methods of this successful project. He started with this: "There is a viable alternative to the problems raised by Bill Gates in his irate letter to computer hobbyists concerning 'ripping off' software. When software is free, or so inexpensive that it's easier to pay for it than to duplicate it, then it won't be 'stolen'." The Bill Gates letter was written to make software into products. The alternative method was to have an experienced professional do the overall design and then outline an implementation strategy. Knowledgeable amateurs would implement the design for a variety of computer systems. Warren predicted this strategy would be continued and expanded.
The May 1976 issue of Dr. Dobbs has Li-Chen Wang's Palo Alto Tiny BASIC for the 8080. The listing begins with the title, author's name, and date but it also has "@COPYLEFT ALL WRONGS RESERVED". A fellow Homebrew Computer Club member, Roger Rauskolb, modified and improved Wang's program and this was published in the December 1976 issue of Interface Age magazine. Roger added his name and preserved the COPYLEFT Notice.

Description

Basic concepts

Tiny BASIC was designed to use as little memory as possible, and this is reflected in the paucity of features as well as details of its interpreter system. Early microcomputers lacked the RAM and secondary storage for a BASIC compiler, which was more typical of timesharing systems.
Like most BASICs of the era, Tiny Basic was interactive with the user typing statements into a command line. As microcomputers of the era were often used with teletype machines or "dumb" terminals, direct editing of existing text was not possible and the editor instead used takeout characters, often the backslash, to indicate where the user backed up to edit existing text.
If the user typed a statement into the command line the system examined it to see if it started with a number. If it did not, the line was immediately parsed and operated on, potentially generating output via. This was known as "direct mode".
If the line was entered with a leading number, the number was converted from decimal format, like "50", and converted to a 8-bit value, in this case, hexadecimal. This number was used as an index into an array-like storage area where the rest of the line was stored in exactly the format it was typed. When the user typed into the command line the system would loop over the array, convert the line number back to decimal format, and then print out the rest of the text in the line.
When a program was present in memory and the user types in the command, the system enters "indirect mode". In this mode, a pointer is set to point to the first line of the program, for instance, 10. The original text for that line is then retrieved from the store and run as if the user had just typed it in direct mode. The pointer then advances to the next line and the process continues.

Formal grammar

The grammar is listed below in Backus–Naur form, almost exactly as it was specified in the Design Note. In the listing, an asterisk denotes zero or more of the object to its left except for the first asterisk in the definition of "term", which is the multiplication operator; parentheses group objects; and an epsilon signifies the empty string. As is common in computer language grammar notation, the vertical bar distinguishes alternatives, as does their being listed on separate lines. The symbol "CR" denotes a carriage return. A BREAK from the console will interrupt execution of the program.

line ::= number statement CR | statement CR
statement ::= PRINT expr-list
IF expression relop expression THEN statement
GOTO expression
INPUT var-list
LET var = expression
GOSUB expression
RETURN
CLEAR
LIST
RUN
END
expr-list ::= *
var-list ::= var *
expression ::= term *
term ::= factor *
factor ::= var | number |
var ::= A | B | C... | Y | Z
number ::= digit digit*
digit ::= 0 | 1 | 2 | 3 |... | 8 | 9
relop ::= < | > | =
string ::= " * "

Note that string wasn't defined in the Design Note.
This syntax, as simple as it was, added one innovation: and could take an expression rather than just a line number, providing an assigned GOTO rather than the switch statement of the, a structure then supported in HP Time-Shared BASIC and predating. The syntax allowing statement was not yet supported in Dartmouth BASIC at this time but had been introduced by Digital and copied by Microsoft.