Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
2 К ПС(мережі 1, 2 семестр).doc
Скачиваний:
0
Добавлен:
01.03.2025
Размер:
3.75 Mб
Скачать

The language Syntax

Basic statements are terminated by line endings unless there is a line continuation character. A very minimal BASIC syntax only needs the LET, PRINT, IF and GOTO commands. An interpreter which executes programs with this minimal syntax doesn't need a stack. Some early microcomputer implementations were this simple. If one adds a stack, nested FOR-loops and the GOSUB command can be added. An interpreter with these features requires the BASIC code to have line numbers.

Line numbers were a very distinctive aspect of classic home computer BASIC. Alas, the use of line numbers has the disadvantage of requiring the programmer to guesstimate ahead of program entry how many lines a given program part will take. This need is most often met by habitually incrementing successive line numbers by a regular interval, say 10, but naturally leads to problems as soon as later-added code exceeds the number-space available between the original lines. To alleviate this problem with early BASIC interpreters, expert users soon wrote their own utility programs for renumbering their programs after initial entry. Some BASIC interpreters later appeared with a built-in RENUMBER command, thus eliminating the most pressing problem with line numbers.

Modern BASIC dialects have abandoned line numbers, and support most (or all) of the structured control and data declaration constructs known in other languages like C and Pascal (note also that some advanced versions of line number-based home computer BASICs incorporated such constructs as these to good effect):

  • do - loop - while - until - exit

  • on x goto / gosub (switch & case)

Recent variants such as Visual Basic have introduced object-oriented features, and even inheritance in the latest version. Memory management is easier than in many other procedural programming languages because of the commonly included garbage collector (presumably for which, however, one pays a run-time performance penalty).

This wealth of variants shows that the language is an "organic" one and that it may be seen as a subculture dealing with computer programming rather than as a fixed set of syntactic rules. This applies as well to other "old" computer languages like COBOL and FORTRAN, although the BASIC movement is by far the largest; this may be explained by the large number of IT professionals who cut their teeth on BASIC programming during the home computer era in the 1980s.

Procedures and flow control

BASIC doesn't have a standard external library like other languages such as C. Instead, the interpreter (or compiler) contains an extensive built-in library of intrinsic procedures. These procedures include most of the tools a programmer needs to learn programming and write simple applications, including functions for math, strings, console input/output, graphics and file manipulation.

Some BASIC dialects do not allow programmers to write their own procedures. Programmers must instead write their programs with large numbers of GOTO statements for branching. This can result in very confusing source, commonly referred to as spaghetti code. GOSUB statements branch to simple kinds of subroutines without parameters or local variables. Most modern versions of BASIC such as Microsoft QuickBASIC have added support for full subroutines and functions. This is another area where BASIC differs from many other programming languages. BASIC, like Pascal, makes a distinction between a procedure which does not return a value (called a subroutine) and a procedure which does (called a function). Many other languages (notably C) make no distinction and consider everything a function (with some returning a "void" value).

While functions in the larger sense of subroutines returning values were a latecomer to BASIC dialects, many early systems supported the definition of one-line mathematical functions by DEF FN ("DEFine FunctioN"). The original Dartmouth BASIC also supported Algol-like functions and subroutines from an early date.