Neolithic Tiny Basic
Re: Neolithic Tiny Basic
This is a personal view, but I'd be wary of a syntax design which involves scanning ahead. (ELSE is not so bad in BBC Basic as it only scans to the end of the line.) But the idea of finding a "matching" element seems to me a problematic one: you might need a rule that such an element has to be in the first statement on a line, or not guarded by an IF, for example.
I very often write code where a FOR might have two or three NEXTs, or similarly for UNTILs. Perhaps I'm just a very naughty boy. Or perhaps such code should be illegal in a particular dialect which does try to match loop start with loop end.
I very often write code where a FOR might have two or three NEXTs, or similarly for UNTILs. Perhaps I'm just a very naughty boy. Or perhaps such code should be illegal in a particular dialect which does try to match loop start with loop end.
- barrym95838
- Posts: 2056
- Joined: 30 Jun 2013
- Location: Sacramento, CA, USA
Re: Neolithic Tiny Basic
I'm familiar with only the Micro$oft, Woz and TRS-80 Level I variations of BASIC, and for me a FOR/NEXT loop that may execute zero times is unexpected, due to the extra effort in scanning forward (through treacherous but legal spaghetti) ... that's more of a C thing, isn't it?
[Edit: I see that Ed and I think along similar "naughty" lines. I believe that DEC even offered an UNLESS keyword, which adds another (unnecessary IMO) kink ...]
[Edit: I see that Ed and I think along similar "naughty" lines. I believe that DEC even offered an UNLESS keyword, which adds another (unnecessary IMO) kink ...]
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!
Mike B. (about me) (learning how to github)
Mike B. (about me) (learning how to github)
Re: Neolithic Tiny Basic
And I've just discovered that my for/next isn't behaving as I expected it to. I think a problem with the comparison... need to think about that.
But first, input...
Neil
But first, input...
Neil
Re: Neolithic Tiny Basic
barrym95838 wrote:
I'm familiar with only the Micro$oft, Woz and TRS-80 Level I variations of BASIC, and for me a FOR/NEXT loop that may execute zero times is unexpected, due to the extra effort in scanning forward (through treacherous but legal spaghetti) ... that's more of a C thing, isn't it?
C treats a FOR loop like a WHILE construct... So:
Code: Select all
for (i = 0 ; i < 10 ; ++i) { do somestuff} Code: Select all
i = 0 ;
while (i < 10) {
do somestuff ;
++i ;
}Quote:
[Edit: I see that Ed and I think along similar "naughty" lines. I believe that DEC even offered an UNLESS keyword, which adds another (unnecessary IMO) kink ...]
-Gordon
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/
Re: Neolithic Tiny Basic
BigEd wrote:
I very often write code where a FOR might have two or three NEXTs, or similarly for UNTILs. Perhaps I'm just a very naughty boy. Or perhaps such code should be illegal in a particular dialect which does try to match loop start with loop end.
Neil
p.s. yup, it breaks it; it mostly works, but this code with two nexts from a single for: executes both the inner and outer loops the expected number of times, but it's clearly not matching the nexts correctly; line 80 is executed only once and its next is being treated as an end (reasonable: an endif, next, or return all do the same thing: nothing; they're considered markers rather than executable keywords). Neil
Re: Neolithic Tiny Basic
(FWIW I believe there's a Basic on the Spectrum Next which likewise tries to match loop beginnings and ends. And I think I checked that ANSI Basic also does. So, it's certainly a design choice.)
Re: Neolithic Tiny Basic
It's not 'legal' in my TinyBasic to omit the loop variable - and it is checked. Could I remove the need for it and check? Yes, but I think I like it. One thing I can't do is:
which you can do in some Basics..
-Gordon
Code: Select all
NEXT J,I-Gordon
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/
Re: Neolithic Tiny Basic
My feeling is that whatever is being attempted with multiple nexts from the same for can probably be achieved with more structured, er, structure.
I'm having some difficulty even contemplating how you might track nexts if the language not only permits that you can have more than one next per for but also that any given next might apply to more than one for... truly 'goto considered harmful'
I suppose it comes down to whether one wishes to write a structured program, or treat basic like spaghetti machine code?
Strictly, of course, the only construct you really need is if and goto... not even endif.
Neil
I'm having some difficulty even contemplating how you might track nexts if the language not only permits that you can have more than one next per for but also that any given next might apply to more than one for... truly 'goto considered harmful'
I suppose it comes down to whether one wishes to write a structured program, or treat basic like spaghetti machine code?
Strictly, of course, the only construct you really need is if and goto... not even endif.
Neil
Re: Neolithic Tiny Basic
A particular thing which I find quite difficult to write efficiently as a properly structured program is a prime tester using trial division - because there are two conditions for leaving a loop, broadly speaking.
Re: Neolithic Tiny Basic
BigEd wrote:
A particular thing which I find quite difficult to write efficiently as a properly structured program is a prime tester using trial division - because there are two conditions for leaving a loop, broadly speaking.
Code: Select all
800REM Is it Prime?
810REM Input N, output P - true or false (1 or 0)
811REM
820IF N < 1 P = 0 : RETURN : REM 0 and 1 are not Prime
830IF N < 4 P = 1 : RETURN : REM 2 and 3 are Prime
834IF N%2 = 0 P = 0 : RETURN : REM Trivial case for even numbers
840S = N : GOSUB 1000 : U = Q : REM Test up to the sqrt of S
845T = 3
850DO
860 IF N % T = 0 THEN P = 0 : DPOP: RETURN
870 T = T + 2
880UNTIL T > Q
890P = 1
899RETURN-Gordon
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/
Re: Neolithic Tiny Basic
Well, at the moment I seem to have completed the last module: input of either an integer or a string. So it's _nominally_ finished, though I need to look again at that for/next issue; perhaps something wrong in the compare routine. I also need to rationalise variable names and jump target names.
Then I'll stick it up and let you all have a laugh...
But I'm under 4k (just - $fcb = 4043 bytes
)
Neil
Then I'll stick it up and let you all have a laugh...
But I'm under 4k (just - $fcb = 4043 bytes
Neil
Re: Neolithic Tiny Basic
well done! Under 4k is impressive!
Re: Neolithic Tiny Basic
The parent C version - x64 linux - is 29.7k, so it's improved somewhat.
Neil
Neil
Re: Neolithic Tiny Basic
Well as a first cut, here it is. A couple of issues that I know about:
It builds to just under 4k, starting $e000.
Enjoy, please let me know if you find (or fix!) any bugs. It's explicit in the code, but, FreeBSD licence to avoid future worries.
Neil
- There are some combinations of values for which for/next never stops. Still investigating; I may rewrite the whole chunk.
- Code to list single lines or group of lines still to be done
- As far as I know, execution stops on an error, with a message, but does not yet list the line number
- There is no 'oops' (e.g. ctrl-C) or warm restart
Code: Select all
; assemble with as65, http://www.kingswood-consulting.co.uk/assemblers/
; use: as65 tiny.asm -h0 -ltiny.lst -s2 -x -m
; (or remove -s2 for binary output)
;
; THIS BUILD FOR SYMON EMULATOR - check ACIA register locations
Enjoy, please let me know if you find (or fix!) any bugs. It's explicit in the code, but, FreeBSD licence to avoid future worries.
Neil
- Attachments
-
- tiny.asm
- (73.75 KiB) Downloaded 203 times