SamCoVT / TaliForth2

A Subroutine Threaded Code (STC) ANSI-like Forth for the 65c02
Other
29 stars 5 forks source link

Should evaluate terminate on a parse error? #38

Closed patricksurry closed 4 months ago

patricksurry commented 6 months ago

One thing I run into regularly is introducing a syntax error to a big chunk of code that I'm evaluate'ing. (For example referring to an undefined symbol.) This causes very unpredictable behavior (stack underflow, reset, etc) since I think evaluate continues processing after the error (without reporting it). So writing to an undefined symbol during evaluate writes to whatever happened to be on the stack before the missing symbol.

It's not clear what the standard behavior is, but imho it would be better to report the error and fail back to interactive input rather than continuing to consume the evaluate source.

SamCoVT commented 6 months ago

Evaulate does terminate on error, such as using an undefined word. It also sets the input back to the keyboard, resets and empties the input buffer, and resets the return and data stacks to empty. If you are feeding text to Tali through I/O, then it will continue processing on the next line, as that is the keyboard.

patricksurry commented 6 months ago

hmm, looks like you're right in the simple cases I've tried. I'm using a nested evaluate but can't reproduce with a simple example yet. If I find one I'll add here.

SamCoVT commented 6 months ago

I think the only thing that was missing is that BLK was not set to zero (which is my bad, as I wrote Tali's block support) so an error while LOADing a block would leave BLK with the block number. I'm fixing that right now (as I make \ work in blocks).

The error handling jumps to ABORT and never returns, as ABORT falls into QUIT which has the main processing loop, so I'd be surprised (but very interested) if you were able to find a combination of Input/EVAULUATE/LOAD where an error does not reset everything.

I have had inquiries on how to get Tali to "stop processing" a cut&paste when there is a syntax error near the beginning - the current behavior is to print an error and throw away the rest of the current line, but then keep reading the next line and continuing. This can result in tons of other errors because the word with the typo isn't defined and also Tali is set back to interpreting and might still be in the middle of a compiled word.

If you have a solution for that, I'd be interested.