Sunday, June 13, 2010

Translator – PRINT Command (Testing)

Sorry for the lack of posts but it has been quite an effort trying to get the desired error messages for the different errors. The simple approach would be to simply report “Syntax Error” like GW-Basic does for errors, but that defeats the idea of a Beginner's programming language – it should be helpful. After seeing how well QBasic identifies errors (though not perfect), the decision was made to do an even better job than QBasic.

There has been a little backtracking on the scheme that all error codes (and messages) should be unique. There was starting to be a lot of similar messages except for subtle differences like a “; not semicolon” or “; not comma” at the end. The decision was made that this was unnecessary, since the location in the code could be identified by the token being pointed to (comma, semicolon, or EOL), so there's really no point to having multiple unique errors for these.

It would require too much space to try an explain all the details of the changes, but here is a summary of the major changes:
  1. Print-only functions are checked if invalid immediately upon receipt instead of waiting until the function is processed at the closing parentheses (without this, a statement like A=TAB(B$) would report that the argument is invalid possible implying that the TAB is okay in the assignment).
  2. The counter stack was modified to hold both the operand counter it previously held and a new number of expected arguments value that is set for internal functions. This value is used to determine if another argument is expected or no more arguments are expected for a given internal function.
  3. The comma and semicolon token handlers were reorganized for better error reporting.
  4. The expression end check function was modified to check if a comma or closing parentheses is expected for internal functions (complicated by functions having different number of arguments).
  5. Many checks of the current mode were required in the different locations in the Translator code so the correct error could be reported.
There is still a few errors that are not being reported as desired. A little more work is required to clean these up and a release can finally be made...