Tuesday, September 3, 2013

Pre-Encoder Issues – Output List Indexes

Tokens that are arguments or sub-scripts are attached to identifiers with parentheses and define functions with parentheses tokens.  These attached tokens will be used by the Encoder.  For tokens that are determined to be an array, the subscript are checked with hidden integer convert codes added for double subscripts and errors reported for string subscripts.  For tokens that are functions calls, the arguments are checked with conversion codes added or errors reported as needed.

Later, this mechanism will also be used to attach tokens to certain command tokens.  For instance, in a single line IF statement, the ELSE, END IF or last token on the line will be attached to the IF command token.  The Encoder will use this attached token to calculate the offset from the IF command to the token, so that during execution, the number of words to skip will be known for when the expression is false.

Currently it is the RPN Items that contain the tokens and it is the RPN Items that are actually attached (the RPN Item contains an array of attached RPN Item pointers).  However, there is a problem as there is no way to determine where in the list the attached RPN Item is located.  This will be needed to know where to insert conversion code or to calculate an offset.

This was corrected by adding an index member to the RPN Item.  When an item is appended to the output list, this index is assigned the value where the item will be located (which is the size of the list just before appending the item).  When an item is inserted into the list, the indexes of the items after the insertion point are incremented for each of the items new location.

For testing purposes, the text output for an RPN Item was modified to include the index of attached items.  The affected results files were updated.  See the commit log for more details of the changes.

[commit 5ef00faa25]