rje Posted September 8, 2020 Share Posted September 8, 2020 Just out of curiosity, what sort of pain would be involved in adding a major syntactic feature like WHILE? I understand that a WHILE is little more than W_LABEL: IF expr GOTO W_CONTINUE GOTO W_DONE W_CONTINUE: ...do stuff.. GOTO W_LABEL W_DONE: ...but that's not trivial, injecting a new thing into BASIC 2.0. I also understand that C's FOR construct is just an initial condition and a WHILE with a "last" statement in the loop. F_BEGIN: <initialization step> F_WHILE: IF <test step> GOTO F_CONTINUE GOTO F_DONE F_CONTINUE: ...do stuff.. <last step> GOTO F_WHILE F_DONE 1 Quote Link to comment Share on other sites More sharing options...
rje Posted September 8, 2020 Author Share Posted September 8, 2020 (edited) Thinking a little about it, it seems that WHILE can be modeled after BASIC 2.0's FOR statement, right? Because the FOR has an embedded test for stopping the loop. So it's kind of like a WHILE. Or, put another way, the two share some common logic patterns, if not actual code. Edited September 8, 2020 by rje Quote Link to comment Share on other sites More sharing options...
SlithyMatt Posted September 8, 2020 Share Posted September 8, 2020 GW-Basic (and subsequently QBasic) had a nice, simple syntax for WHILE: 10 X = 0 20 WHILE X < 5 30 PRINT X 40 X = X + 1 50 WEND Of course, this is a bad code example, as you should really just use FOR in this case, but there is a good precedent for clean, terse while loops in other Microsoft BASICs. 3 Quote Link to comment Share on other sites More sharing options...
rje Posted September 8, 2020 Author Share Posted September 8, 2020 So maybe I should ask... is FORTH good for writing things like BASIC interpreters? Quote Link to comment Share on other sites More sharing options...
BruceMcF Posted September 9, 2020 Share Posted September 9, 2020 Certainly ... it makes it much easier to experiment with interpretation models and work out how to eliminate bottlenecks, and then when the model is in place, convert the Basic keyword actions into assembly for speed. But that would be for a Basic loaded from disk, for extending the ROM Basic, the tools are a good assembler and a good breakpoint/watchpoints single step capable monitor. Quote Link to comment Share on other sites More sharing options...
BruceMcF Posted September 9, 2020 Share Posted September 9, 2020 10 hours ago, SlithyMatt said: GW-Basic (and subsequently QBasic) had a nice, simple syntax for WHILE: 10 X = 0 20 WHILE X < 5 30 PRINT X 40 X = X + 1 50 WEND Of course, this is a bad code example, as you should really just use FOR in this case, but there is a good precedent for clean, terse while loops in other Microsoft BASICs. A DO ...WHILE from QBasic would be easier to implement At DO, push an "impossible" FOR entry, then WHILE executes the test, if it is true, use the for loop entry to repeat, if it fails, continue. It's the same as if you say: FOR I = 1 TO 2 ... IF <test> THEN I=I-1 ... NEXT I. WHILE ... WEND can borrow the FOR stack too, but the extra work with WHILE ... WEND is when it falls out of the loop, you have to scan through each statement looking for the matching WEND ... which means maintaining a depth count starting at 1 that you increment with each WHILE token and decrement with each WEND token until it hits zero, then continue executing. But like GW-BASIC, CBM V2 BASIC is a little less flexible about having the same keyword do different things in different contexts. Therefore I would advise someone looking to add WHILE WEND to start out with DO ... UNTIL ... when they have the evaluation of an expression and the FOR stack management and looping worked out, that is everything for WHILE ... WEND except scanning the program to find the WEND that closes the current WHILE. And then just leave off the other three versions of DO ... LOOP, so the only closer for DO loops is UNTIL and WHILE only occurs in a WHILE ... WEND loop. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.