Tuesday, July 23, 2013

New Full Done-Stack Class

The final improvement seen while implementing the LET translation was in giving the done stack inside the translator more functionality, including automatic handling of the first and last operand token pointers stored in each done stack item with the PRN output list item pointer.  Control of the open and close parentheses tokens was given the done item structure since it owns the first and last tokens that may contain parentheses tokens.  The done item structure and done stack class were also put into their own header and source file.  Click Continue... for details of the changes.

[commit 98f6ed9ae9]

Old Translator – INPUT PROMPT Problem

While updating the uses for a more functional done stack class (see next post for details), a bug was discovered in the old translator INPUT command handler when an error is detected with the INPUT PROMPT string expression because the type of the expression is not a string.  A segmentation fault would occur for certain types of expressions, particularly if the first or last operands contained parentheses or were not set, because the first and last tokens were not being handled correctly.  It has been the policy not to fix bugs in the old translator routines (not worth the time and effort), but these lines needed to be changed anyway and the changes were simple.

This code previously set the error token to the first operand token pointer through the last operand token of the top done stack item.  It then proceeded to delete any closing parentheses token in the RPN output list item token, which was obviously wrong (only the last operand token would have a closing parentheses).  This code also did not allow the first and last token pointers to contain null values, which caused the segmentation fault.

The code was changed to set the error token to the RPN item's token if the first point is null, and set through the last pointer if the last pointer is also not null, and deleting any closing parentheses token in the last operand token.  Statements were added to translator test #12 (INPUT tests) that cause the issues (these will be useful for testing the new INPUT command translation once implemented).

[commit 1f360f08fb]