Thursday, June 17, 2010

Language – INPUT command

After looking at QBasic (GW-Basic, QuickBasic and FreeBASIC have the same features on the INPUT command) and TrueBASIC (similar to ANSI Basic) for inspiration, a set of desired features for the INPUT command was selected. There's no reason to get too elaborate with the INPUT command as there is a better solution for inputting values (more on that later). The syntax chosen for the INPUT command implementation is:
INPUT [[<string-expression>] {,|;}] <variable>[,<variable> ...][;]
QBasic (and GW-Basic, etc.) supports an optional prompt string, but it must be a string constant. TrueBASIC (ANSI BASIC) allows a string expression but it is preceded by the PROMPT keyword (followed by a colon and the "? " is suppressed). ANSI BASIC has some other options in additional to PROMPT (perhaps TrueBASIC does now too, but not in the 1985 version).

A string expression will be used for the prompt so that anything can be used for the prompt, not just a string constant (which is too restrictive). Similar to QBasic, a comma separator after the prompt outputs just the value of the string expression, and a semicolon will add "? " after the prompt. If there is no string expression or separator, then the standard "? " is output. The prompt is optional, and if there is just a separator, then there will just the "? "  (semicolon) or no prompt (comma). Using just the semicolon is pointless because it is the same as not having the semicolon. Using just the comma will have no prompt (which gives errors with both QBasic and GW-Basic).

The trailing optional semicolon will keep the cursor on the same line after the input is entered. QBasic (and the others) accomplish this with the optional semicolon directly after the INPUT keyword. This is weird and it makes more sense to put the optional semicolon at the end just like with the PRINT statement.

Note: Debugging will resume on the error reporting issues, but I have little time available during this week and wanted to get started with the background for the INPUT command.