Friday, November 22, 2013

Recreator – INPUT Statements

Like PRINT statements, INPUT statements contain several codes including the input parse item (double, integer or string), input begin, input begin with string prompt, input assign reference (double, integer or string), and the input or input prompt command code.  The input begin with string prompt and input command codes could also have the option sub-code set.  The separator of the recreator class will be used between these codes to keep track of the separators between the input reference items.

As the codes of the INPUT statement are processed, the resulting INPUT statement is built up by adding to the string on top of the holding stack.  The string of the current reference is added to the string being built with a separator in between.  After each reference or prompt string, the separator is set to a comma (or a semicolon after the prompt string without the option sub-code).  At the end of the statement, the INPUT or INPUT PROMPT keyword is added to the output string along with the built up string that is popped from the stack.

Implementation

The input begin string code follows the input prompt string expression, the string of which will be on top of the stack.  The input prompt begin recreate function for the input begin string code sets the separator to a comma if the option sub-code is set, otherwise sets it to a semicolon.

The input assign recreate function contains a local string.  If the separator is set, the string is set to the string of the reference that is popped from the stack.  The separator is added to the string on top of the stack followed by the string of the reference.  The separator is not set for the first reference of an INPUT statement, so no action is needed (the string of the reference is left on the stack).  The separator is set to a comma for the next reference.

The input recreate function for both the INPUT and INPUT PROMPT code adds the command keyword to the output string.  A space is added followed by the built up string that is popped from the stack.  If the command code has the option sub-code set (for keeping cursor on the same line), a semicolon is added to the output string.  The separator is cleared for the next statement.

The table class name access function with token pointer argument was modified to return the full name of the code.  This includes a space and the second word of a code that has the two word option set along with a second name.  This was needed for the INPUT PROMPT command that contains two words.

Pointers to the new input recreate functions were added to the table entries of the various input codes.  The input parse item and input begin codes do not produce anything during recreation and their table entries were set to the pointer of the blank recreate function.  The expected recreated outputs for translator test #12 (INPUT statements) were updated and are recreated correctly.

[commit 9c8631000f]