skx / gobasic

A BASIC interpreter written in golang.
https://blog.steve.fi/tags/basic/
GNU General Public License v2.0
328 stars 27 forks source link

Suppose for NEXT without variable #91

Open udhos opened 5 years ago

udhos commented 5 years ago

gobasic should support NEXT without a variable.

The NEXT variable should be optional unless for BASIC code collapsing multiple FOR loops into the same NEXT (10 for a=1 to 2: for b=3 to 5: next b,a).

Documentation: https://hwiegman.home.xs4all.nl/gw-man/FORNEXT.html

$ gobasic next.bas 
1Error running program:
    Line 30 : Expected IDENT after NEXT in FOR loop, got Token{Type:NEWLINE Value:\n}
$ 
$ more next.bas 
10 for i=1 to 3
20 print i
30 next
skx commented 5 years ago

Some BASICs allow this. e.g. visual-basic:

Some BASIC implementations do not.

When I've been in doubt, I've gone with the latter approach.