[Coco] Color Basic Renumber
William Astle
lost at l-w.ca
Tue Jan 27 16:38:55 EST 2015
On 15-01-27 02:29 PM, Allen Huffman wrote:
> Nick, do you know much about the BASIC tokenizer format? It would be trivial to write a renumber program as an exercise. You would have to do some parsing but there is a small number of tokens that could have line numbers after them. It might be as simple as starting at a line, scanning through and stopping at each potential token to see if a line number is after it. By making as list, it would be easy to renumber.
That's essentially what the RENUM does. It doesn't notice all possible
tokens that take line numbers (notably the ones that don't generally get
used in programs like DEL). The critical tokens to consider are GOTO,
GOSUB, THEN, and ELSE. You might also want to consider LIST, RUN, and
DEL. You don't have to consider "ON" directly since it always has GOTO
or GOSUB - just make sure to handle a comma separated list of line
numbers after GOTO/GOSUB.
What RENUM actually does is make two passes. The first pass expands all
line numbers out to 5 bytes and converts the numbers to a temporary
representation with some notes. The second pass replaces all replaced
line numbers with their new numbers and then collapse the resulting
numbers back down to the smallest number of digits.
The actual code is a bit of a brain buster to understand.
The upshot is that it isn't quite as simple as it looks if you're going
to do it in assembly, especially if you need to minimize the memory
footprint.
More information about the Coco
mailing list