Saturday, June 5, 2010

Translator – Command Handlers

The command handlers will be called at the end of the statement, which the end-of-line token handler is current performing. This will change when the end-of-statement is implemented (soon with the colon operator). For now, the end-of-line token handler will call the command handler for the command on top of the command stack.

The command handler functions are friends of the Translator class, like the token handler functions; necessary so that pointers to these functions can be put into the table entries. The interface to these functions are similar to the token handlers except a pointer to the command stack item is passed for the second argument instead of a reference to a token pointer. This gives the command handler access to the code and flag information in the command stack item in addition to the token pointer of the command. If an error occurs and a different token needs to be pointed to for the error, the token pointer can be changed (the original token needs to be deleted first).
  1. Command handlers will now be in charge of checking if an expression has been ended correctly and will make sure the done stack has been emptied.  The end-of-line handler is responsible for:
  2. Checking if the command stack is not empty (otherwise a “command stack empty” bug error occurs).
  3. Checking if the command on top of the command stack has a command handler (otherwise a “not yet implemented” bug error occurs).
  4. Popping the command item from command stack and calling its command handler.
  5. Popping the initial null token from the hold stack.
  6. Checking if the done stack is empty.
  7. Checking if the command stack is empty.
  8. Deleting the EOL token and return a done status.
Some of this functionality will be moved to the end-of-statement routine and the end-of-line token handler will be changed once multiple statements per line is implemented. There also needs to be an assignment command handler that does nothing more than return a good status. Now on to implementing the PRINT command handler function...