Saturday, November 22, 2014

Translator Exceptions – Commands

The routines that process commands were the next modified to throw exceptions.  This included the get commands routine used to get command statements separated by colons.  For now, if the two calls to the get token function return an error (not good status), the appropriate error is thrown.  The get token function will also be modified to throw errors soon.  Since get commands now throws errors, it no longer needs to return a status so the return type was removed (along with the local status variable).

The process command routine handles the processing of one command and was modified to throw exceptions.  It calls a specific translate function for a command or the LET translate function if the first token is not a command.  The LET, PRINT and INPUT translate functions were also modified to throw exceptions.  The status return type was also removed and if statement surrounding the call to process command in get commands was removed (which will cause thrown exceptions to be thrown up its caller - the translator function operator function).

In the translator function operator function, a status is no longer returned from the get commands function, so assignment of the local status variable was removed.  And thrown exceptions are passed up to the caller of the function operator function (which will catch the errors).  For a successful return, the local status variable is set to Done.  This is temporary until the get expression function is also modified to throw exceptions.

The LET, PRINT and INPUT translate functions were restructured a bit.  Local variable declarations were moved to where the variables are first used.  Some of the error checking if statements were rearranged to ease the handling of errors (when the lower functions are modified to throw exceptions).  These changes came from the failed total translator exception changes.  The checks for the end-of-statement were also moved to a more logical place in each of these routines.

[branch misc-cpp-stl commit 7217ce58c6]

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