Friday, November 21, 2014

Translator Exceptions – Top-Level

Several convenience functions were added to the Token Error structure to make it syntactically easier to use.  These include a function operator function with no arguments for returning the status of the error, a function operator function with a status argument for checking if the error status is the passed status, and an assignment operator function taking a status value to assign to the error status.

The translator function operator function was modified to throw errors instead of setting a local status variable, which is then used to throw the error at the end of the function.  Eventually the get expressions and get commands functions will throw exceptions for errors and the local status variable won't be necessary.

The try block in the tester parse input function was reformatted where the try-catch blocks were moved outside of the forever loop to the function block.  The return statement in the catch block could then be removed.

[branch misc-cpp-stl commit c639347b07]

Translator Exceptions – Development Strategy

The next incremental change was initially difficult to see for adding exception throws throughout the translator routines.  Starting at the bottom by changing the get token function to throw exceptions was problematic because all callers would have to catch the errors and create an error token to hold the column and length of the error.  Starting at the top by changing both the get expressions (used for testing) and get commands functions to throw exceptions was problematic because all functions in between would also need to be modified.  An attempt to change the entire translator was made.

After the code was modified and corrected for compile errors, the tests were run, but there were many problems, which was not unexpected considering the large number of changes made.  Instead of trying to debug, the changes were committed to a temporary work branch (though not pushed to the official GitHub repository).  This is a scheme to use git to temporary save work:
git checkout -b work           (create a temporary work branch)
git commit -a                  (stages all changed files and commits them)
git checkout -b misc-cpp-stl   (restore all files before changes)
This saved the changes of the failed attempt and restored the original files.  Changes from the work branch could now be transferred to the working directory piecemeal.  For example, several changes were made to the Token Error structure in the token header file (details in the next post).  For more details on using this scheme, click Continue...