Wednesday, June 9, 2010

Translator – PRINT Command (Still Debugging)

And speaking of QBasic, out of curiosity of how it handles invalid commas in function arguments for comparison to IBCP, QBasic detects the wrong number of arguments at the first comma that shouldn't be there (the “expected )” error occurs pointing to the comma) or the closing parentheses when there should be another argument (the “expected ,” error occurs pointer to the closing parentheses. IBCP doesn't catch the error until the closing parentheses (and points to the function name with the “wrong number of arguments” error). The QBasic behavior is better.

This behavior was not difficult to replicate. The count stack (that keeps track of operands, i.e. commas) was modified to hold a count stack item, which contains the current number of operands (commas) counter and a new expected number of arguments that is set if the token is an internal function. The comma token handler then checks if too many arguments have been entered if the expected number of arguments is set.

To make this work with internal functions that have multiple number of arguments (MID$, INSTR and ASC), the entries in the table needed to be rearranged where the code with the more number of arguments moved first, so that the number of expected operands was set high enough not the have an error reported before getting to the closing parentheses.

One more bug needs to be fixed, a statement like “Z=A+” reports the “BUG: expected operand on done stack” error. Bug errors are programming errors that should not occur. The statement “Z=(A+” does correctly report the “operand or closing parentheses expected” error. This appears to be the final bug...

QBasic (Another Incremental Compiler)

I discovered that QBasic 1.1 is available as a free download. Version 1.0 came with DOS 5.0 as a replacement for GW-Basic and with Windows 95, NT 3.x and NT 4.0. Version 1.1 came with DOS 6.x, Windows 95, 98, and Me. QBasic was based on QuickBasic 4.5. I was fascinated with the features of QuickBasic 4.5 when it came out, the incremental compiler aspect was intriguing, but did not think they took the user interface concepts far enough (one of the intentions of IBCP).

After getting familiar with QuickBasic 4.5, I never used it much afterward since it's compiled programs were much slower than when compiled with QuickBasic 3.0 (not an incremental compiler) for the project I was involved with at the time and continued to use GW-Basic for development and the QuickBasic 3.0 compiler for production.

QBasic does not contain any of compiler or linker elements of QuickBasic 4.5, however, the incremental compiler remains. The lines are compiled as they are entered and errors are reported immediately. QBasic is good inspiration for IBCP and will be used for comparison, both for features and run-time (though possibly unfair since QBasic is not 32-bit). QBasic will be mentioned frequently from here on (along with GW-Basic, QuickBasic 3.0 and FreeBASIC), though there is no intention of making IBCP a clone of QBasic (see FreeBASIC for that, which is just a compiler).