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]

The deleteOpenParen() and deleteCloseParen() functions were moved from the Translator class to the DoneItem class where two versions of each were implemented.  The first are static versions that take a token pointer argument.  These versions can be called by anyone and are identical to the removed Translator functions.  The other versions are member functions that call the static versions with the first and last members respectively.

Functions were also added to the DoneItem class for replacing the first and last members with a new token pointer.  Before setting the first or last member, the delete open or close parentheses functions are called to delete any open parentheses (first member) or close parentheses (last member) token before assigning the first or last member to the new token pointer.

Three functions were added to the DoneStack class to simply handling of the first and last operand tokens of the done items on the stack.  The pop() function was reimplemented that deletes any parentheses tokens in the first and last members of the top done item, calls the base QStack pop() function to pop a done item from the stack, and returns the RPN output list item that was in the done item popped.  The drop() function deletes any parentheses tokens in the first and last members of the top done item, and removes the done item from the stack (by resizing the stack less one item).  The replaceTopFirstLast() function replaces the first and last operand tokens in the top done item (calls the replace member functions).

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.)