BASIC without line numbers?

BruceMcF

Member
May 19, 2019
100
30
18
The problem is that multiple types of structured code blocks are being proposed. When you have IF blocks, FOR loops, DO/WHILE loops, SUBs, and FUNCTIONs all need a distinct exit command. (FOR loops should also have a CONTINUE command that will short-circuit the remainder of the body for that iteration.)
EXIT is existing CBM V7 syntax, and if the project design team has decided to reserve CBM V7 tokens in their V7 meanings, then that implies that the EXIT we are talking about if the V7 EXIT not the QBasic EXIT {structure-type}.

EXIT FOR doesn't need to be a single token - the tokens for EXIT and FOR can be combined; the same goes with the other EXIT commands. But we do need to specify which type of block is being exited, so the stack can be unspooled properly.
It's not that it needs to be ... it already IS a single token. That was Commodore's doing. The design team could have decided, "scratch everything after V2 and start fresh" ... but they didn't.

The QBASIC syntax is not directly compatible with Basic V7 syntax, where EXIT is already Basic V7 syntax for DO/LOOPs. If we want "structured exit" then the TOKEN cannot be "existing EXIT token", "FOR token" ... because existing EXIT token is something that exits the currently nested DO/LOOP.

Perhaps it could be argued that this means that making "EXIT FOR" parse to "structured exit token, then FOR token" IS upwardly compatible "for practical purposes", so long as the TOKEN is not the EXIT token but a new, "structured exit" token, because good V7 code should not have the phrase "EXIT FOR" in a single statement, and the "structured exit" TOKEN would not be the same TOKEN as the existing "do-loop exit" token.

"CONTINUE" seems a bit redundant in line-basic, it's just GOTO ...

10 FOR I=1 to 100
20 ...
...
50 IF K>2*I GOTO 100
...
100 NEXT I

... and Screen Basic could support it in exactly that way ... but I like it as a ROM Basic Keyword because of the operating efficiency of getting the top variable reference from the stack along with the location of the start of the loop and not having any scanning to do unless the loop completes.
 
Last edited:
May 22, 2019
409
211
43
EXIT is existing CBM V7 syntax, and if the project design team has decided to reserve CBM V7 tokens in their V7 meanings, then that implies that the EXIT we are talking about if the V7 EXIT not the QBasic EXIT {structure-type}.



It's not that it needs to be ... it already IS a single token. That was Commodore's doing. The design team could have decided, "scratch everything after V2 and start fresh" ... but they didn't.

The QBASIC syntax is not directly compatible with Basic V7 syntax, where EXIT is already Basic V7 syntax for DO/LOOPs. If we want "structured exit" then the TOKEN cannot be "existing EXIT token", "FOR token" ... because existing EXIT token is something that exits the currently nested DO/LOOP.

Perhaps it could be argued that this means that making "EXIT FOR" parse to "structured exit token, then FOR token" IS upwardly compatible "for practical purposes", so long as the TOKEN is not the EXIT token but a new, "structured exit" token, because good V7 code should not have the phrase "EXIT FOR" in a single statement, and the "structured exit" TOKEN would not be the same TOKEN as the existing "do-loop exit" token.

"CONTINUE" seems a bit redundant in line-basic, it's just GOTO ...

10 FOR I=1 to 100
20 ...
...
50 IF K>2*I GOTO 100
...
100 NEXT I

... and Screen Basic could support it in exactly that way ... but I like it as a ROM Basic Keyword because of the operating efficiency of getting the top variable reference from the stack along with the location of the start of the loop and not having any scanning to do unless the loop completes.
You seem to be making the assumption that Commander BASIC will be (or even should be) compatible with BASIC 7... I feel like that's adding a lot of baggage to the design, since the team has no intention of implementing BASIC 7. From a usage standpoint, I don't care what the tokens are, and I sure wouldn't want to compromise the design of the language over issues like the token being used.
 
Last edited:
  • Like
Reactions: BruceMcF

BruceMcF

Member
May 19, 2019
100
30
18
You seem to be making the assumption that Commander BASIC will be (or even should be) compatible with BASIC 7... I feel like that's adding a lot of baggage to the design, since the team has no intention of implementing BASIC 7. From a usage standpoint, I don't care what the tokens are, and I sure wouldn't want to compromise the design of the language over issues like the token being used.
More (finally getting around to) reading the Programmers Reference Guide where it says something to that effect.

My prior working assumption before reading the PRG had been that anything upwardly compatible with CBMv2 would be OK, and I was in favor of aligning with QBasic for a variety of reasons. Hence LEAVE, so that Screen Editor Basic could support QBASIC Loop commands while there wouldn't be any difficulty supporting both QBasic as well as that rudimentary ROM Basic loop syntax in the same Basic interpreter/compiler. At least, QBasic 1.1 has no keyword LEAVE, so not crosstalk between the two.

But when they say they want to retain CBMv3.5 and CBMv7 tokens for better compatibility with those Basics, that modifies my prior assumption. Now EXIT is pretty much the same as what I originally called LEAVE.
 
Last edited:

mobluse

New Member
Sep 20, 2019
21
8
3
There is Ratfor that can be used as a preprocessor for Fortran 77 (and Fortran 66 if you change the Makefile), and then you program in a C like programming language and it is converted to Fortran. BASIC V2 is rather similar to Fortran 66, but less complex, so one could make a program similar to Ratfor that generated BASIC V2. It could be called Ratbas2. One could of course change from C to BASIC V7.0 keywords.


There are also examples and manual there. It is a rather complex program, but the version for BASIC V2 might be simpler, and maybe one could compile it with cc65 and run it on the X16.

Here is a Ratfor program (changed to more like BASIC V2 from example test.r) and its translation into Fortran 66 (which is more similar to BASIC V2 than Fortran 77):
PHP:
x=1; y=2
if (x == y)
    print "Wrong, x != y"
else if(x > y)
    print "Also wrong, x < y"
else
    print "Ok!"
x=1
# Here is a comment
while (x < 10) {
    if(y != 2) break
    if(y != 2) next
    print "x = "`x # backtick instead of semicolon
    x=x+1
}
# REM A BASIC comment
repeat
    x=x-1
until (x == 0)
for (x=0; x < 10; x=x+1)
    print "x = "`x
end
This is the output of Ratfor, but it is not legal Fortran 66 since I changed some lines to BASIC V2, but Ratfor ignores these changes:
Code:
C Output from Public domain Ratfor, version 1.01
      x=1
      y=2
      if(.not.(x .eq. y))goto 23000
      print "Wrong, x != y"
      goto 23001
23000 continue
      if(.not.(x .gt. y))goto 23002
      print "Also wrong, x < y"
      goto 23003
23002 continue
      print "Ok!"
23003 continue
23001 continue
      x=1
C Here is a comment
23004 if(.not.(x .lt. 10))goto 23005
      if(.not.(y .ne. 2))goto 23006
      goto 23005
23006 continue
      if(.not.(y .ne. 2))goto 23008
      goto 23004
23008 continue
C backtick instead of semicolon
      print "x = "`x
      x=x+1
C REM A BASIC comment
      goto 23004
23005 continue
23010 continue
      x=x-1
23011 if(.not.(x .eq. 0))goto 23010
23012 continue
      x=0
23013 if(.not.(x .lt. 10))goto 23015
      print "x = "`x
23014 x=x+1
      goto 23013
23015 continue
      end
Then I change this to a program compatible with autonum.sh (this is done automatically using sh, sed and a ratfor in Fortran 66 mode):
Code:
X=1
Y=2
IF NOT (X = Y) THEN GOTO L23000
PRINT "WRONG, X != Y"
GOTO L23001
L23000:
IF NOT (X > Y) THEN GOTO L23002
PRINT "ALSO WRONG, X < Y"
GOTO L23003
L23002:
PRINT "OK!"
L23003:
L23001:
X=1
' HERE IS A COMMENT
L23004:
IF NOT (X < 10) THEN GOTO L23005
IF NOT (Y <> 2) THEN GOTO L23006
GOTO L23005
L23006:
IF NOT (Y <> 2) THEN GOTO L23008
GOTO L23004
L23008:
' BACKTICK INSTEAD OF SEMICOLON
PRINT "X = ";X
X=X+1
REM A BASIC COMMENT
GOTO L23004
L23005:
L23010:
X=X-1
L23011:
IF NOT (X = 0) THEN GOTO L23010
L23012:
X=0
L23013:
IF NOT (X < 10) THEN GOTO L23015
PRINT "X = ";X
L23014:
X=X+1
GOTO L23013
L23015:
END
I used this command line in Bash:
Bash:
./ratfor -C -6 testbas.r | sed -E -e '1! s/(23[0-9][0-9][0-9])/L\1/g' -e 's/ continue/:/' -e 's/^(L23[0-9]+) /\1:\n/' -e 's/^C(.*)/\x27\1/' -e 's/\x27 (rem|REM)/rem/' -e 's/^ +//' -e 's/.not./not /g' -e 's/.and./and /g' -e 's/.or./or /g' -e 's/.eq./=/g' -e 's/.gt./>/g' -e 's/.lt./</g' -e 's/.ne./<>/g' -e 's/.ge./>=/g' -e 's/.le./<=/g' -e 's/if\((.+)\)/if \1 then /' -e 's/`/;/g' -e 's/(.*)/\U\1/' -ne '1!p' > testbas.non
Then I run autonum.sh on that:
Code:
10 X=1
20 Y=2
30 IF NOT (X = Y) THEN GOTO 60
40 PRINT "WRONG, X != Y"
50 GOTO 130
60 REM L23000
70 IF NOT (X > Y) THEN GOTO 100
80 PRINT "ALSO WRONG, X < Y"
90 GOTO 120
100 REM L23002
110 PRINT "OK!"
120 REM L23003
130 REM L23001
140 X=1
150 REM L23004
160 IF NOT (X < 10) THEN GOTO 270
170 IF NOT (Y <> 2) THEN GOTO 190
180 GOTO 270
190 REM L23006
200 IF NOT (Y <> 2) THEN GOTO 220
210 GOTO 150
220 REM L23008
230 PRINT "X = "X
240 X=X+1
250 REM A BASIC COMMENT
260 GOTO 150
270 REM L23005
280 REM L23010
290 X=X-1
300 REM L23011
310 IF NOT (X = 0) THEN GOTO 280
320 REM L23012
330 X=0
340 REM L23013
350 IF NOT (X < 10) THEN GOTO 400
360 PRINT "X = "X
370 REM L23014
380 X=X+1
390 GOTO 340
400 REM L23015
410 END
And when I run this in x16emu I get:
Code:
OK!
X =  1
X =  2
X =  3
X =  4
X =  5
X =  6
X =  7
X =  8
X =  9
X =  0
X =  1
X =  2
X =  3
X =  4
X =  5
X =  6
X =  7
X =  8
X =  9
Which looks right!

There is a more bug fixed Ratfor in Debian Buster Linux, and I got that source using apt source ratfor. I patched it further so I have an extra option -6 which generates Fortran 66 code instead of Fortran 77, but you can use the original code if you compile it without defining F77 in the Makefile.

I found this interesting paper about Ratfor: https://wolfram.schneider.org/bsd/7thEdManVol2/ratfor/ratfor.pdf
 
Last edited:

BruceMcF

Member
May 19, 2019
100
30
18
What I have been calling "Screen Editor Basic" is the project doing something similar to that ... they are going to have a line-number-optional Basic with labels and more keywords available which is translated into ROM Basic by the Screen Editor that you edit the files in (since you cannot easily use a line editor for a line-number-optional basic - editing using a line editor without line numbers would be like the original DOS EDLIN, where you are constantly using line numbers based on which line in the file it is, which is a royal PITA).