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 (usually generated by a keyboard's "Enter" key). 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 ::= (string|expression) (, (string|expression) )* var-list ::= var (, var)* expression ::= (+|-|ε) term ((+|-) term)* term ::= factor ((*|/) factor)* factor ::= var | number | (expression) var ::= A | B | C ... | Y | Z number ::= digit digit* digit ::= 0 | 1 | 2 | 3 | ... | 8 | 9 relop ::= |=|ε) | > ( 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 (as opposed to just a line number to branch to) was not yet supported in Dartmouth BASIC at this time but had been introduced by Digital and copied by Microsoft.
Implementation in a virtual machine The Design Note specified a
virtual machine, in which the Tiny BASIC
interpreter is itself run on a virtual machine interpreter. The designer's idea to use an application virtual machine goes back to Val Schorre (with
META II, 1964) and Glennie (Syntax Machine). The choice of a virtual machine approach economized on memory space and implementation effort, although the BASIC programs run thereon were executed somewhat slowly. Dialects that used the virtual machine included Tiny BASIC Extended,
Tom Pittman's Tiny BASIC and NIBL. Other dialects such as Denver Tiny BASIC (DTB) and Palo Alto Tiny BASIC were direct interpreters. Some programmers, such as Fred Greeb with DTB, treated the IL (Interpretive Language) program as
pseudocode for the
algorithm to implement in assembly language; Denver Tiny BASIC did not use a virtual machine, but it did closely follow the IL program. This is a representative excerpt from the 120-line IL program: S1: TST S3,'GO' ;GOTO OR GOSUB? TST S2,'TO' ;YES...TO, OR...SUB CALL EXPR ;GET LABEL DONE ;ERROR IF CR NOT NEXT XFER ;SET UP AND JUMP S3: TST S8,'PRINT' ;PRINT. A common pattern in the program is to test for a keyword or part of a keyword, then act on that information. Each test is an assertion as to what is next in the line buffer. If the assertion fails, control jumps to a subsequent label (usually looking for a new keyword or token). Here the system advances its buffer cursor over any spaces and tests for and if it fails to find it then jumps to line . If it finds it, execution continues with the next IL command. In this case, the system next tests for , skipping to line if it fails (a test for , to see if this is instead a command). If it passes, control continues; in this case, calling an IL subroutine that starts at label , which parses an expression. In Tiny BASIC, (a computed GO TO) is as legal as and is the alternative to the ON-GOTO of larger BASIC implementations. The subroutine pushes the result of the expression onto the arithmetic stack (in this case, the line number). verifies no other text follows the expression and gives an error if it does. pops the number from the stack and transfers execution (GOes TO) the corresponding line number, if it exists. The following table gives a partial list of the 32 commands of the virtual machine in which the first Tiny BASIC interpreter was written. ; : If
string matches the BASIC line, advance cursor over and execute the next IL instruction; if the test fails, execute the IL instruction at the label
lbl ; : Execute the IL subroutine starting at ; save the IL address following the CALL on the control stack ; : Report a syntax error if after deleting leading blanks the cursor is not positioned to reach a carriage return ; : Test value at the top of the AE stack to be within range. If not, report an error. If so, attempt to position cursor at that line. If it exists, begin interpretation there; if not, report an error. ; : Continue execution of the IL at the label specified ; : Return to the IL location specified at the top of the control stack ; : Print characters from the BASIC text up to but not including the closing quotation mark ; : Print number obtained by popping the top of the expression stack ; : Insert spaces to move the print head to next zone ; : Output a CRLF to the printer
Tom Pittman, discussing the IL, says: "The TINY BASIC interpreter was designed by Dennis Allison as a
recursive descent parser. Some of the elegant simplicity of this design was lost in the addition of syntactical sugar to the language but the basic form remains. The IL is especially suited to Recursive Descent parsing of TINY BASIC because of the general recursive nature of its procedures and the simplicity of the TINY BASIC tokens. The IL language is effectively optimized for the interpretation of TINY. Experience has shown that the difficulty of adding new features to the language is all out of proportion with the nature of the features. Usually it is necessary to add additional machine language subroutines to support the new features. Often the difficulty outweighs the advantages."
Deviations from the design Defining Tiny BASIC for the Homebrew Computer Club, Pittman wrote, "Tiny BASIC is a proper subset of Dartmouth BASIC, consisting of the following statement types only: LET, PRINT, INPUT, IF, GOTO, GOSUB, RETURN, END, CLEAR, LIST, RUN. Arithmetic is in 16-bit integers only with the operators + - * / and nested parentheses. There are only the 26 single letter variable names A, B, ...Z, and no functions. There are no strings or arrays... Tiny BASIC specifies line numbers less than 256." He then went on to describe his implementation: "This language has been augmented to include the functions RND, USR, and PEEK and POKE, giving the user access to all his system components in the 6800 from the BASIC program." Many implementers brought their own experiences with
HP Time-Shared BASIC or
DEC BASIC-PLUS to their designs and relaxed the formal Tiny BASIC language specification. Of the seven prominent implementations published by 1977: • All added some sort of random number function, typically . Though not included in the specification, a newsletter article prior to the Design Note for Tiny BASIC requested only this function. • All enabled to be optional and most let expressions in assignment statements contain
relational operators. • All but 6800TB supported statement delimiters in lines, typically although TBX used and PATB used . • In statements, all but MINOL removed the need for expressions to contain relational operators (e.g., was valid). Implementations removed altogether or made it optional or supported it only for implied . None supported clauses. • Many modified to support print zones, using to go to the next zone and to not advance the cursor. • All but 6800TB and DTB added . • All but 6800TB and MINOL added a function to return memory size: TBX had , DTB and PATB had , L1B had , and NIBL had . • Four implementations added arrays, whether a single, undimensioned array in PATB and L1B or ensionable arrays in TBX and DTB. • Four implementations added the ark statement. • Four implementations added the loop: PATB, NIBL, and L1B offered , while TBX did not support and used the keyword to end a loop. • Only NIBL had any nod towards structured programming, with , despite Allison's lament in Issue 2 about problems with BASIC. As an alternative to tokenization, to save RAM, TBX, DTB, and MINOL truncated keywords: for , for , for . The full, traditional keywords were not accepted. In contrast, PATB allowed accepted traditional keywords but also allowed any keyword to be abbreviated to its minimal unique string, with a trailing period. For instance, could be typed , although and other variations also worked. This system was retained in
Level I BASIC for the
TRS-80, which used PATB, and was also later found in
Atari BASIC and the BASIC of various
Sharp Pocket Computers. ==Dialects==