Sunday, November 24, 2013

Program – Decoder

Before the internal code of a program line can be recreated, the program code needs to be decoded into an RPN list.  Like the encoder, which is part of the program model class because it needs access to the dictionaries, the decoder will also be part of the program model.

The decode routine is given the line information of the line to decode containing the offset of the line within the program code and its size.  A new RPN list is created and for each program word in the line, a new token is created and assigned the code and sub-code of the program word.  If the code has an operand text function in its table entry (implying the code has an operand word), the operand text function is called to get the text for the token from the operand, which is assigned to the string of the token.  The token is added to the RPN list.  After all the words of the line are processed, a pointer to the RPN list is returned.

Like the encode routine, the decode routine is a private function within the program model class.  To access recreated lines of the program, a new line text routine was added.  This routine is given the index to the line and starts be retrieving the information for the line, which is passed to the decode routine.  The pointer to the RPN list returned is passed to the recreate routine of the recreator instance (which was added to the program model class).  The RPN list is deleted and the string returned from the recreate routine is returned.

The temporary check to prevent encoder test files from being used with the recreate output option (-to) was removed from the tester class.  In the tester run routine for encoder test files after outputting the code of the program and the dictionary entries, if the recreate output option was selected, each line of the program is output using the line text routine.

The expected results files for the three encoder tests were created from the encoder test results files with the output of the program added to the end.  All the encoder tests are recreated correctly.  The test script and batch files were updated to also test the encoder test files with the recreate output option.

[commit 1f24a70152]