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

LET should be optional

udhos opened this issue · comments

commented

I think LET should be optional.

$ more let.bas 
10 let a=1 : print a
20 b=2 : print b
$ 
$ gobasic let.bas 
1Error running program:
	Line 20 : Object{Type:error, Value:The variable 'b' doesn't exist}
$ 

I can appreciate this is one that might surprise people, because there are several approaches various BASC inplementions have taken:

  • Require the use of LET at all times.
    • The ZX Spectrum did that.
  • Allow it, optionally.
    • e.g. "LET a = 3; b = 3"
  • Require it when a variable is created, but not when it is updated:`
    • e.g. LET a = 3; a = 6;

I think this would be a big change and would not be something I would implement. This approach does require more typing, but it grants the ability to recognize invalid variables very easily.

commented

There are several old, simple, BASIC games that gobasic could get closer to support if it allowed minor changes similtar to making LET optional.

See many examples here: http://www.vintage-basic.net/games.html

For instance, my BASIC-to-Go compiler 'basgo-build' is close to fully supporting this game unchanged:

http://www.vintage-basic.net/bcg/mathdice.bas

One thing that jumps out there is:

   210 IF D=2 THEN 260

That's something that is also not supported, since I'd need it to be written:

   210 IF D=2 THEN GOTO 260

I'll think about it some more, in the meantime I would be happy to accept a patch - though I suspect that's unlikely.

commented

Yeah, supporting the short form "THEN line-number" would be nice too.
Filled #82

I've been persuaded; I'll resolve this.

Not sure if I can add a rewrite at load-time, or if it needs real-handling. I'll find out :)

I have a solution which seems to cover the obvious cases. But it causes GOTO/GOSUB problems, because injecting tokens ruins our offset-counting.

I'll sleep on it.