Tuesday, June 8, 2010

Translator – PRINT Command (More Debugging)

A dummy semicolon token was being appended after a print-only function, which is not necessary. A new semicolon sub-code flag was added for this case along with a new print function command flag, which is set when a print-only function is appended to the output. If the semicolon token handler sees this command flag set, it will set the semicolon sub-code flag of the print-only function token (the last token appended to the output). This command flag is cleared by the semicolon and comma token handlers to prevent further semicolon from seeing it set.

This change was also necessary for print-only functions at the end of a statement, because there was no translated difference between a print-only function at the end or one followed by a semicolon.  To reproduce the ending semicolon, the semicolon sub-code flag is set when there is a semicolon after the print-only function at the end of the statement (the semicolon is not necessary since the print-only functions at the end keep the cursor on the same line).


The check for the end expression flag (set for comma, semicolon and EOL tokens) was put at the beginning of the state is operand or operator check to skip this section when the flag is set. The check was necessary because otherwise an “operand expected” was occurring when a comma or semicolon followed another comma or semicolon, or one of these was at the end of the statement. In this case, the Translator was expecting an operand when the comma, semicolon or EOL was received.

After several failed attempts to get this right, the check was removed to see what error came up for the different test input errors that have been added to test all the possible cases. In all cases, the “operand expected” occurred. This pointed to the location where the end expression flag needed to be.

The location for the check was in the operand section between the “is not an operator” and the “is a unary operator” sections (remember that unary operators are accepted when the Translator is expecting an operand). Making the comma, semicolon and EOL codes unary operators to get is past this section did not work (they were processed incorrectly later in the code), so a separate check was added.

For the end expression token check, a new “operand or closing parentheses expected” error was added (neither “operand expected” nor “missing closing parentheses” made sense for all cases where this error can occur). The error only occurs if the counter stack is not empty (inside a parenthetical expression or inside an array or function), otherwise the error will be caught by the respective token handlers. Debugging continues...

No comments:

Post a Comment

All comments and feedback welcomed, whether positive or negative.
(Anonymous comments are allowed, but comments with URL links or unrelated comments will be removed.)