Sunday, August 11, 2013

Print Function Support

The PRINT statement consists of expressions separated by semicolons or commas.  Commas can also be used with no expressions between them.  The expressions may also contain the print functions TAB and SPC.  These functions are distinguished from other functions in that they have no return data type.  The PRINT translate function could specifically handle these print functions since they are only use in a PRINT statement.

However, the get expression routine also needs to be able handle these print functions in at least to report errors when they are used incorrectly in expressions.  It currently does this simply by the fact that the None data type is not acceptable by any operator or data type request (an expression with a data type of None is not currently requested).

Instead of having the PRINT translate routine handle the print functions, the get expression routine was modified to accept the None data type, which affected two things.  This allows print functions to be returned.  It also allows no expression to be returned (just the next token as the terminating token), which is needed in the PRINT statement for commas.  This will be detected by the done stack being empty.  The PRINT translate routine will be the only caller with the None data type.

The new translator was changed back to only reporting the TAB( or SPC( token when used incorrectly in expressions.  This was necessary due to parser and other errors inside the parentheses of the print function as the error was reported at the wrong place.  Consider the expression:
A = TAB(B$)
An "expected numeric expression" error was reported at the B$ token, but should point to the TAB( token as it doesn't belong in the expression in the first place.  Several more statements were added to translator test #14 that included various parser errors in print functions used incorrectly.  See the commit log for more details of the changes made.

[commit 9502d5b183]