Thursday, June 10, 2010

Translator – PRINT Command (Testing)

A statement like “Z=A+” was reporting the “BUG: expected operand on done stack” error because the add operator (emptied at the EOL) consumed two operands from the done stack, the A and then the Z. The EOL empties the assignment operator next, which is expecting two operands, but there  was only one, the result of the add operator, thus the bug error.

To fix this problem, a new FirstOperand state was needed. This state is set at the beginning. After the first operand, the Operand state is used (except after an assignment operator, comma in a PRINT statement, and semicolon in a PRINT statement). When an operator is received in operand mode that has the end expression flag set (comma, semicolon and EOL), only if the state is not FirstOperand (meaning operands have been received yet) does an error occur. The error message was changed from “operand expected” to “expected expression” since more than just an operand is expected (unary operator, parenthetical expression, etc.).

Upon more comparing with Qbasic's error checking behavior, it became evident that the current error messages could be more helpful in explaining what is expected. Therefore many of the error messages were updated and some new messages were added. In keeping with the current scheme, all error codes (and messages) are unique – in other words, occur in only on location. This makes it much easier to identify what part of the code generated the error.

Many more test inputs were added with all kinds of errors to see if the error messages produced was sufficient and pointing to the proper token. The same statements were tried with QBasic. In some cases, I feel the QBasic message is insufficient. There was even one error statement “A B = 1” that QBasic did not catch as an error until the program was run (oops). There are still more adjustments to the error messages required (including two bug errors that are still occurring and two that are not pointing at the correct token). Hopefully this will be cleaned up shortly and the next release, with the PRINT command, can be made...