Saturday, November 23, 2013

Recreator – RPN Lists (Tagged)

The recreator is now complete and all of the initial set of commands (LET, PRINT, INPUT, and REM) are fully supported.  The repository has been tagged v0.6.1 to mark this milestone.  Some minor issues were also corrected for this commit including:
  • Corrected an expected results for the recreated translator test #12 (INPUT tests).
  • Reorganized the access functions in the recreator class.
  • Renamed the recreator class is empty access function to output is empty so as not to be confused with the stack is empty function.
  • Renamed the recreator class last access function to the more explicit output last character and removed the output string is empty check.
  • Corrected some comment formatting and added some missing comments.
  • Corrected formatting issues where spaces were incorrectly added instead of tab characters (problems are caused by QtCreator editor bugs where is doesn't always pay attention to the spacing/tab settings).
  • Added some missing FLAG option comments (details below).
The next major step is to integrate the recreator with the GUI, but in order to do this, the program code of lines needs to be decoded into an RPN list of tokens for the recreator.  When a line is entered into the program, it will be recreated and the recreated text will replaced the entered text in the edit box.  Preferences will be added to control the formatting of the recreated output, for example, if spaces should be added around operators, after commas, etc.  The FLAG option comments show where checks for these options will be.

[commit 0cd7b84700]

Recreator – Colons

Colons between statements are handled by setting the colon sub-code of the last token of a statement.  To support the recreation of colons, a check was added to the main recreator loop after the check for the parentheses sub-code that if the colon sub-code is set, a colon and a space is added to the output string.

This change caused a slight problem with the recreation of the remark operator if there is a colon just before the remark.  Two spaces were being added in front of the "'" operator.  To prevent this, a check was added after a non-empty output string check to also not add a space if the last character in the output string is already a space.

A new last access function was added to the recreator class that returns the last character in the output string or a null character if the output string is empty.  The expected recreated outputs for translator test  #16 (colon tests) were updated and are recreated correctly.

[commit fc90cf0e32]

Recreator – Remarks

There are two codes for remarks, the command code (for the REM command) and the operator code (for the "'" operator).  The token contains the string of the remark.  Generally, the keyword (REM or "'") along with the remark string is added to the output string.  However, there were two issues to be handled.

Unlike all the other commands, no space is required after the REM command when followed by a letter, so a statement like "REMARK A Comment" is valid.  The issue is for a REM statement entered as "remark a comment" in all lower case.  When recreated, the result would have been the "REMark a comment" statement.  So, if the first character of the remark string is lower case, the REM keyword is converted to lower case.  This still won't work if something like "Remark A Comment" is entered.

The second issue involves the remark operator.  A space is needed before the "'" operator if the command is not at the beginning of the line to provide some separation between the previous statement.  To determine if the remark is at the beginning of the line, an is empty access function was added to the recreator class  that returns whether the output string is empty (which implies this the beginning of the line if nothing was added yet).

A single rem recreate function was added to handle both remark codes and a pointer to this function was added to the remark code table entries.  To test the lower case check, an all lower case remark statement was added to translator test #15 (REM tests).  The expected recreated outputs for this test were updated and are recreated correctly.

[commit 03c73c3de7]