Sunday, June 6, 2010

Translator – PRINT Command (Debugging)

The code that handles checking the done stack and appending the necessary data type specific code was also put into a new add print code function so that it can be called from the comma token handler, semicolon token handler and new print command handler. Once the changes were implemented and made to compile, testing was started with the new regression test script.

The first problem encountered was that at the end of the line for the expression tests reported that the done stack was not empty, which was true because the expression only mode leaves the result on the done stack. The code was modified to save the expression mode from the start function and the end-of-line token handler checks for the expression only mode and makes sure there is one item on the done stack.

The next problem encountered was that the single PRINT command (the last test of the current test inputs) reported an “expected operand” at the end of the line. This occurred because after the PRINT command token was received, the mode was set to Expression and the state was set to Operand. The EOL token received next was considered an operator and therefore caused the error.

To correct this, a new EndExpr table entry flag was added and set in the EOL code table entry. This flag is also needed for the Comma and SemiColon codes and will be used for other codes that end expressions (for example, Colon, THEN, ELSE, END IF, etc.). If a token is received that has this flag set, then the normal operand/operator sections are skipped. The stack emptying section follows next where these codes will empty most of the operators from the hold stack. All of these codes will have token handlers.

Once all the existing test inputs worked, several PRINT test inputs were added. The next issue discovered was that both the comma and semicolon token handlers must switch Translator state back to Operand from Operator (an “expected operator” error was occurring). The are many other bugs in the PRINT statement code; debugging continues...