Close

Program storage, parsing, editing

A project log for One kilobyte Tiny BASIC for the 8080 and Z80

BASIC for the 8080 and Z80, fits in 1K of memory, runs BASIC games on a 2K system. Features similar to Palo Alto Tiny BASIC.

willstevenswill.stevens 01/25/2024 at 01:460 Comments

1K Tiny BASIC is tokenised, unlike a lot of other Tiny BASICs. Tokens are either line numbers, integers, strings, variable names, or keywords (including operators and syntactic punctuation), or the special ‘syntax error’ token which indicates that a syntax error occurred. For statements, operators, and some other tokens, the token value is the low order byte of the address of the subroutine corresponding to that token. For operators, the value also increases with increasing operator precedence - this means that the order in which operator subroutines occur in memory is important.

Programs are stored as a simple sequence of tokens in memory. LIST simply has to traverse the sequence and print the string corresponding to each token. GOTO and GOSUB look for the target line by starting from the start of the program and scanning forwards until it is found (and produce an error message if not found).

Parsing happens in-place in memory immediately after the current last line of the program. As soon as a sequence of entered characters is recognised as a token, it is converted into a token. This means there is no need for a separate input buffer elsewhere in memory.

After a line has been parsed it is either executed (if it doesn’t start with a line number), or moved to the right place in the program with a triple-reversal memory rotate algorithm implemented in 27 bytes. This same algorithm is used to delete a line if a line number is entered by itself.

The INPUT statement shares the same parser as is used when entering programs, except that a separate area of memory is used. This means that the input statement will accept expressions as well as integer constants.

Discussions