skx / gobasic

A BASIC interpreter written in golang.

Home Page:https://blog.steve.fi/tags/basic/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Expected identifier after DATA

udhos opened this issue · comments

commented

Can anyone spot the problem causing the error below?

$ gobasic bubble.bas 
Error running program:
	Line 130 : Expected identifier after DATA - found Token{Type:( Value:(}
$ 
$ more bubble.bas 
100 DATA "HELLO", "WORLD", "BASIC", "BUBBLE", "SORT", "DEMO", "GO"
110 LET J=7
120 FOR N=1 TO J
130 READ A$(N)
140 NEXT
150 PRINT "SORTING ARRAY"
160 GOSUB 1000
170 PRINT "SORTING ARRAY - DONE"
180 PRINT
190 FOR N=1 TO J
200 PRINT A$(N)
210 NEXT
220 END
1000 REM BUBBLE SORT ARRAY
1010 REM INPUT: A$()=ARRAY J=ARRAY_SIZE
1020 REM OUTPUT: A$()=SORTED_ARRAY
1030 REM OTHER VARIABLES USED: FLIPS, N
1040 REM
1050 LET FLIPS=1
1060 WHILE FLIPS
1070 LET FLIPS=0
1080 FOR N=1 TO J-1
1090 IF A$(N)>A$(N+1) THEN SWAP A$(N), A$(N+1): LET FLIPS=1
1100 NEXT N
1110 WEND
1120 RETURN
$ 

The following program demonstrates the same problem, more simply:

 10 DIM a(3)
 20 FOR I = 1 TO 3
 30  READ a[I]
 40 NEXT I
 50 DATA 3, 4, 1, 7 , 9

The problem is that I've always required "READ $VAR", and that case wasn't updated to cope with arrays.

Genuine bug:

  • Cannot READ into ARRAY.

That said your program is going to struggle, since you use A$(N) rather than what I expect A$[N]. Also you invoke wend and swap, neither of which I support - or have heard of!

(I'll close this issue when READing from DATA into an array works.)

commented

I found that sorting code here: http://www.antonis.de/qbebooks/gwbasman/whilewend.html

Then I added the missing parts to make it work. It works as is with PC-BASIC (https://github.com/robhagemans/pcbasic)

We're hitting conflict because gwbasic is not what I've implemented, this BASIC is closest to ZX Spectrum BASIC - which was simple.

I expect users who wish to port programs will be forced to make changes.

commented

No conflicts, man. I've been suggesting small improvements that would help running GW-BASIC dialects AND would NOT hurt ability to run ZX Spectrum dialect. Of course you would code those enhancements only if you enjoy them. No bad feelings. Cheers.