Microsoft GW-BASIC interpreter (original) (raw)

GW-BASIC (GW meaning Graphics Workstation or more amusingly 'gee-whiz') was a dialect of BASIC developed by Microsoft, originally for Compaq. It is compatible with Microsoft's/IBM's BASICA, but was disk based and did not require the resources of the ROM included on IBM's machines. It was bundled with with MS-DOS operating systems on IBM PC compatibles by Microsoft. Like other early microcomputer versions of BASIC, GW-BASIC lacked many of the structures needed for structured programming such as local variables, and GW-BASIC programs executed relatively slowly, due to the fact that it was an interpreted programming language. It did have a large number of graphics commands.

Still, it had enough flexibilty to allow one to write simple games, business programs and the like. Since it was available on any PC, it was also a cheap way for would-be programmers to learn the rudiments of computer programming. It also provided a way to develop impressive science fair projects for aspiring students willing to deal with the frustrations of programming in such a spartan system.

GW-BASIC has a command line-based Integrated Development Environment (IDE) system based on the original introduced at Dartmouth College; all program lines must be numbered, all non-numbered lines are considered to be commands in direct mode (ie, to be executed immediately). The user interface is almost completely command line, except for the function key shortcuts at the bottom and an initial copyright notice at the top of the screen. Files are normally saved in a GW-BASIC binary compressed format with tokens replacing commands; however, it has an option to save programs in ASCII text form.

The GW-BASIC IDE has commands to RUN,LOAD,SAVE,LIST the current program, or quit to the operating SYSTEM. Although they may all be used as program statements such use is rare for all commands except SYSTEM.

There is little support for structured programming in GW-BASIC and therefore it is very much up to GW-BASIC programmers, themselves, to provide a good structure for their programs. All IF/THEN/ELSE conditional statements must be written on one line, although WHILE/WEND statements may group multiple lines. Functions can only be defined using the single line DEF FNf(x)= statement (e.g., DEF FNLOG(base,number)=LOG(number)/LOG(base)). Variables are often typed via a type symbol at the end of their name: A$ is a string, A% is an integer, etc. Groups of undeclared variables can also be set to default types based on the initial letter of their name by use of the DEFINT, DEFSTR, etc., statements. The default type for undeclared variables not identified by such typing statements, is single-precision floating-point.

Because many GW_BASIC programmers were without formal training, they often failed to see the need for simple structuring and as a result made extensive, undisciplined use of GOTOs rather than using them as replacements for the missing structural statements. See spaghetti code.

GW-BASIC allowed for the joysticks and pen-input devices of its time, but not for mice. (It is possible to use pen-input commands for mice, but the reliability of the mouse responding properly to pen requests is poor.) GW-BASIC can read from and write to files, LPT ports, and COM ports; it can also do event trapping for ports. It cannot handle tape devices. It is able to play simple sheet music using the PLAY statement, requiring a string of notes (e.g. PLAY "edcdeee2dfedc4"), or the SOUND statement, requiring a frequency in Hertz and a length in clock ticks for the standard internal 'speaker' in IBM machines, consequently sound is limited to single channel beeps and whistles as befits a 'business' machine.

GW-BASIC's place in the MS-DOS distribution was eventually taken by Microsoft QBASIC, a cut-down version of the separately available Microsoft QuickBASIC compiler. GW-BASIC's main advantage over BASICA was that it did not require a BASIC interpreter on the ROM and so could be used on non-IBM PCs.