Skip to main content

This is how BASIC worked in the Spectrum at least. Each command was a single keystroke (you'd hit 'P'P and "PRINT"PRINT would appear). Of the 256 possible character values, 91 were the BASIC commands and operators like "POKE"POKE or "<>"<>, not counting the single-character operators like ++ and so on. You can see the list here: https://en.wikipedia.org/wiki/ZX_Spectrum_character_set#Character_seton Wikipedia.

So, the number '1'1 took four bytes to store on the spectrumSpectrum (if I remember right, it stored two copies of all 16 bit ints for some reason), but the commands "SGN PI"SGN PI took only 2, one byte each: 0xBC 0xA7.

In BASIC, the commands to change the contents of memory, the equivalent of C's pointers, are "PEEK"PEEK and "POKE"POKE.

Again, I don't think this is what the question is asking. While BASIC (like any language, really) can be compiled to bytecode or assembly, it was typically implemented as a dynamically interpreted language from a bytestreambyte stream. Outside of the byte stream, there's no preparsingpre-parsing, splitting the language up into metasyntactic concepts akin to a "syntax tree", or anything like that.

As I understand it, Sinclair BASIC in particular was an interpreted language: the program counter went along line by line, passing each in turn to the interpreter, in a single pass with no backtracking other than via the "GO TO" contructGO TO construct.

  • the Timex Sinclair's addition to the Sinclair BASIC of the DELETE <first line#> <last line#> command permitted the removal of ranges of lines from a BASIC program.

    the Timex Sinclair's addition to the Sinclair BASIC of the DELETE <first line#> <last line#> command permitted the removal of ranges of lines from a BASIC program.

  • the RENUM <first line$> <step size> command renumbered code line numbers, affecting all GOTO, GOSUB, RESTORE, RUN, LINE, ON ERROR GOTO and other similar commands. The reason this could be considered self-modifying is that it would leave alone any expressions such as GOTO VAL "50", DELETE 10, 100, and indeed further calls to RENUM.

    the RENUM <first line$> <step size> command renumbered code line numbers, affecting all GOTO, GOSUB, RESTORE, RUN, LINE, ON ERROR GOTO and other similar commands. The reason this could be considered self-modifying is that it would leave alone any expressions such as GOTO VAL "50", DELETE 10, 100, and indeed further calls to RENUM.

    So it's possible, though I've not tried it, that this:

     10 GOTO VAL "40"
     20 PRINT "nothing"
     30 DELETE 10, 70
     40 PRINT "word"
     50 RENUM 10, 30
     60 DELETE 130, 160
     70 GOTO 10
    

    ...will, on hitting line 50, change itself to:

     10 GOTO VAL "40"
     40 PRINT "nothing"
     70 DELETE 10, 70
     100 PRINT "word"
     130 RENUM 10, 30
     160 DELETE 130, 160
     190 GOTO 10
    

    ... then on hitting the new line 160, convert to:

     10 GOTO VAL "40"
     40 PRINT "nothing"
     70 DELETE 10, 70
     100 PRINT "word"
     190 GOTO 10
    

    ... then on hitting the new line 70, convert to:

     100 PRINT "word"
     160 GOTO 10
    

    ... which is still valid since a GOTO goes to the next largest number. The resulting output would be:

     word
     nothing
     word
     word
     word
     ....
    

    I have never used a Timex, so can't say for sure that's how they worked (did these update the program counter? Halt the program? Restart it? I can't find it documented). But either way, this is the closest I can find.

So it's possible, though I've not tried it, that this:

10 GOTO VAL "40"
20 PRINT "nothing"
30 DELETE 10, 70
40 PRINT "word"
50 RENUM 10, 30
60 DELETE 130, 160
70 GOTO 10

...will, on hitting line 50, change itself to:

10 GOTO VAL "40"
40 PRINT "nothing"
70 DELETE 10, 70
100 PRINT "word"
130 RENUM 10, 30
160 DELETE 130, 160
190 GOTO 10

... then on hitting the new line 160, convert to:

10 GOTO VAL "40"
40 PRINT "nothing"
70 DELETE 10, 70
100 PRINT "word"
190 GOTO 10

... then on hitting the new line 70, convert to:

100 PRINT "word"
160 GOTO 10

... which is still valid since a GOTO goes to the next largest number. The resulting output would be:

word
nothing
word
word
word
....

I have never used a Timex, so can't say fersure that's how they worked (did these update the program counter? Halt the program? Restart it? I can't find it documented). But either way, this is the closest I can find.

This is how BASIC worked in the Spectrum at least. Each command was a single keystroke (you'd hit 'P' and "PRINT" would appear). Of the 256 possible character values, 91 were the BASIC commands and operators like "POKE" or "<>", not counting the single-character operators like + and so on. You can see the list here: https://en.wikipedia.org/wiki/ZX_Spectrum_character_set#Character_set

So, the number '1' took four bytes to store on the spectrum (if I remember right, it stored two copies of all 16 bit ints for some reason), but the commands "SGN PI" took only 2, one byte each: 0xBC 0xA7.

In BASIC, the commands to change the contents of memory, the equivalent of C's pointers, are "PEEK" and "POKE".

Again, I don't think this is what the question is asking. While BASIC (like any language, really) can be compiled to bytecode or assembly, it was typically implemented as a dynamically interpreted language from a bytestream. Outside of the byte stream, there's no preparsing, splitting the language up into metasyntactic concepts akin to a "syntax tree", or anything like that.

As I understand it, Sinclair BASIC in particular was an interpreted language: the program counter went along line by line, passing each in turn to the interpreter, in a single pass with no backtracking other than via the "GO TO" contruct.

  • the Timex Sinclair's addition to the Sinclair BASIC of the DELETE <first line#> <last line#> command permitted the removal of ranges of lines from a BASIC program.
  • the RENUM <first line$> <step size> command renumbered code line numbers, affecting all GOTO, GOSUB, RESTORE, RUN, LINE, ON ERROR GOTO and other similar commands. The reason this could be considered self-modifying is that it would leave alone any expressions such as GOTO VAL "50", DELETE 10, 100, and indeed further calls to RENUM.

So it's possible, though I've not tried it, that this:

10 GOTO VAL "40"
20 PRINT "nothing"
30 DELETE 10, 70
40 PRINT "word"
50 RENUM 10, 30
60 DELETE 130, 160
70 GOTO 10

...will, on hitting line 50, change itself to:

10 GOTO VAL "40"
40 PRINT "nothing"
70 DELETE 10, 70
100 PRINT "word"
130 RENUM 10, 30
160 DELETE 130, 160
190 GOTO 10

... then on hitting the new line 160, convert to:

10 GOTO VAL "40"
40 PRINT "nothing"
70 DELETE 10, 70
100 PRINT "word"
190 GOTO 10

... then on hitting the new line 70, convert to:

100 PRINT "word"
160 GOTO 10

... which is still valid since a GOTO goes to the next largest number. The resulting output would be:

word
nothing
word
word
word
....

I have never used a Timex, so can't say fersure that's how they worked (did these update the program counter? Halt the program? Restart it? I can't find it documented). But either way, this is the closest I can find.

This is how BASIC worked in the Spectrum at least. Each command was a single keystroke (you'd hit P and PRINT would appear). Of the 256 possible character values, 91 were the BASIC commands and operators like POKE or <>, not counting the single-character operators like + and so on. You can see the list on Wikipedia.

So, the number 1 took four bytes to store on the Spectrum (if I remember right, it stored two copies of all 16 bit ints for some reason), but the commands SGN PI took only 2, one byte each: 0xBC 0xA7.

In BASIC, the commands to change the contents of memory, the equivalent of C's pointers, are PEEK and POKE.

Again, I don't think this is what the question is asking. While BASIC (like any language, really) can be compiled to bytecode or assembly, it was typically implemented as a dynamically interpreted language from a byte stream. Outside of the byte stream, there's no pre-parsing, splitting the language up into metasyntactic concepts akin to a "syntax tree", or anything like that.

As I understand it, Sinclair BASIC in particular was an interpreted language: the program counter went along line by line, passing each in turn to the interpreter, in a single pass with no backtracking other than via the GO TO construct.

  • the Timex Sinclair's addition to the Sinclair BASIC of the DELETE <first line#> <last line#> command permitted the removal of ranges of lines from a BASIC program.

  • the RENUM <first line$> <step size> command renumbered code line numbers, affecting all GOTO, GOSUB, RESTORE, RUN, LINE, ON ERROR GOTO and other similar commands. The reason this could be considered self-modifying is that it would leave alone any expressions such as GOTO VAL "50", DELETE 10, 100, and indeed further calls to RENUM.

    So it's possible, though I've not tried it, that this:

     10 GOTO VAL "40"
     20 PRINT "nothing"
     30 DELETE 10, 70
     40 PRINT "word"
     50 RENUM 10, 30
     60 DELETE 130, 160
     70 GOTO 10
    

    ...will, on hitting line 50, change itself to:

     10 GOTO VAL "40"
     40 PRINT "nothing"
     70 DELETE 10, 70
     100 PRINT "word"
     130 RENUM 10, 30
     160 DELETE 130, 160
     190 GOTO 10
    

    ... then on hitting the new line 160, convert to:

     10 GOTO VAL "40"
     40 PRINT "nothing"
     70 DELETE 10, 70
     100 PRINT "word"
     190 GOTO 10
    

    ... then on hitting the new line 70, convert to:

     100 PRINT "word"
     160 GOTO 10
    

    ... which is still valid since a GOTO goes to the next largest number. The resulting output would be:

     word
     nothing
     word
     word
     word
     ....
    

    I have never used a Timex, so can't say for sure that's how they worked (did these update the program counter? Halt the program? Restart it? I can't find it documented). But either way, this is the closest I can find.

Clarify my uncertainty.
Source Link

I have never used a Timex, so can't say fersure that's how they worked (did these update the program counter? Halt the program? Restart it? I can't find it documented). But either way, but it'sthis is the closest I can find.

I have never used a Timex, so can't say fersure that's how they worked, but it's the closest I can find.

I have never used a Timex, so can't say fersure that's how they worked (did these update the program counter? Halt the program? Restart it? I can't find it documented). But either way, this is the closest I can find.

added 51 characters in body
Source Link
10 GOTO VAL "40"
20 PRINT "nothing"
30 DELETE 4010, 70
40 PRINT "word"
50 RENUM 10, 30
60 DELETE 130, 160
70 GOTO 10
10 GOTO VAL "40"
40 PRINT "nothing"
70 DELETE 4010, 70
100 PRINT "word"
130 RENUM 10, 30
160 DELETE 130, 160
190 GOTO 10
10 GOTO VAL "40"
40 PRINT "nothing"
70 DELETE 4010, 70
100 PRINT "word"
190 GOTO 10
10 GOTO VAL "40"
100 PRINT "word"
160 GOTO 10

... which is still valid since a GOTO goes to the next largest number. The resulting output would be:

10 GOTO VAL "40"
20 PRINT "nothing"
30 DELETE 40, 70
40 PRINT "word"
50 RENUM 10, 30
60 DELETE 130, 160
70 GOTO 10
10 GOTO VAL "40"
40 PRINT "nothing"
70 DELETE 40, 70
100 PRINT "word"
130 RENUM 10, 30
160 DELETE 130, 160
190 GOTO 10
10 GOTO VAL "40"
40 PRINT "nothing"
70 DELETE 40, 70
100 PRINT "word"
190 GOTO 10
10 GOTO VAL "40"
100 PRINT "word"
160 GOTO 10

The resulting output would be:

10 GOTO VAL "40"
20 PRINT "nothing"
30 DELETE 10, 70
40 PRINT "word"
50 RENUM 10, 30
60 DELETE 130, 160
70 GOTO 10
10 GOTO VAL "40"
40 PRINT "nothing"
70 DELETE 10, 70
100 PRINT "word"
130 RENUM 10, 30
160 DELETE 130, 160
190 GOTO 10
10 GOTO VAL "40"
40 PRINT "nothing"
70 DELETE 10, 70
100 PRINT "word"
190 GOTO 10
100 PRINT "word"
160 GOTO 10

... which is still valid since a GOTO goes to the next largest number. The resulting output would be:

Might count?
Source Link
Loading
Source Link
Loading