Thursday, August 22, 2013

New Translator – Remarks

There are two forms of remarks (comments), the REM command and the remark operator (a single quote).  The remark operator can be placed anywhere an end-of-statement token can be put including at the beginning of the line where a command is.  There are no commands after a remark since all characters are part of the comment up to the end of the line.  Remarks were implemented a couple of different ways and while these all worked, these solutions were not very clean (there were multiple checks for the Rem and RemOp tokens in several routines).

The final solution was to implement a new get commands routine, which as the name implies will be able to handle multiple commands on the line separated by colons (which wasn't implemented yet).  The new routine contains a loop, which begins by getting a token.  If the token is a Rem or RemOp, the loop is exited.  Otherwise the token is processed by calling the process command routine (see below).  If the terminating token of the command is a RemOp, the loop is exited.  Otherwise, for now, the routine returns the terminating token from the command translator routine and the done status.

When the loop is exited in the new get commands routine, which will be due to a Rem or RemOp token, the token is appended to the RPN output list, and the next token is obtained, which should be an end-of-line token unless there is a bug in the parser.  The end-of-line token is returned as the terminating token with the done status.

The original get command routine was renamed to the process command routine, which made more sense and this routine won't be public as only the get commands routine will be the only caller.  It was modified to receive the first token from the token argument instead of getting the token itself.

The expected results for translator test #15 (Remark tests) needed to be updated due to the change in translation of the PRINT and INPUT commands (the old results were saved).  Now all the translator tests pass with the new translator routines. 

[commit a3a71526f9]