Английская Википедия:BASIC-PLUS

Материал из Онлайн справочника
Перейти к навигацииПерейти к поиску

Шаблон:Short description Шаблон:Infobox programming language BASIC-PLUS is an extended dialect of the BASIC programming language that was developed by Digital Equipment Corporation (DEC) for use on its RSTS/E time-sharing operating system for the PDP-11 series of 16-bit minicomputers in the early 1970s through the 1980s.

BASIC-PLUS was based on BASIC-8 for the TSS/8,[1] itself based very closely on the original Dartmouth BASIC. BASIC-PLUS added a number of new structures, as well as features from JOSS concerning conditional statements and formatting. In turn, BASIC-PLUS was the version on which the original Microsoft BASIC was patterned.[2]

Notable among the additions made to BASIC-PLUS was the introduction of string functions like Шаблон:Mono and Шаблон:Mono, in addition to Dartmouth's original all-purpose Шаблон:Mono command. In future versions of the language, notably Microsoft's, Шаблон:Mono was removed and BASIC-PLUS's string functions became the only ways to perform these sorts of operations. Most BASICs to this day follow this convention.

The language was later rewritten as a true compiler as BASIC-Plus-2, and was ported to the VAX-11 platform as that machine's native BASIC implementation. This version survived several platform changes, and is today known as VSI BASIC for OpenVMS.

Operation

Users would sit at a terminal and type in programming language statements. The statements could either be entered into the system's command interpreter directly, or entered into a text editor, saved to a file, and loaded into the command interpreter from the file. Errors in source code were reported to the user immediately after the line was typed.

As a smart terminal with cursor control could not be guaranteed, BASIC-PLUS used the common system of prefixing all source code with a line number. The code was edited by typing in the number and then changing the contents of the following code. A line of code could be removed by typing in its line number and nothing else, thereby setting it to an empty line.

The virtual address space of an RSTS/E user was limited to a little less than 64KB of space. Using BASIC-PLUS, about half of this virtual address space was used by the combined command interpreter and run-time library (named the Run Time System on RSTS/E). This limited user programs to about 32 kB of memory.

Large programs were broken into separate executable pieces by use of the Шаблон:Code statement, and programs could chain to specific line numbers in a secondary program to indicate that a program should begin execution at a different point from its first line. This feature of chaining to a certain line number allowed programs to signal to each other that they were being called from another program. The use of a shared memory section called core common also allowed programs to pass data to each other as needed. Disk files could also be used but were slower.

To conserve memory, the system included a garbage collecting memory manager, used for both string data and byte-code.

A running program could be interrupted, have variables examined and modified, and then be resumed.

Syntax and features

BASIC-PLUS is patterned closely on later versions of Dartmouth BASIC, including its powerful MAT commands. On top of this, DEC added a number of unique flow-control structures.

Editing

Line numbers were positive integers from 1 to 32767.Шаблон:Sfn Logical lines of code could be continued on multiple physical lines by using a line feed at the end of a line instead of the normal carriage return character.Шаблон:Sfn For ease of external editing of the source file, later versions of BASIC-PLUS also allowed the Шаблон:Code character as a line continuation character.

Multiple statements could be placed on a single line using Шаблон:Code as the statement separator.Шаблон:Sfn The system allowed tabs to be used as inline whitespace, and was used to make loops more clear, as in modern languages.Шаблон:Sfn Comments used either the Шаблон:Code keyword or the Шаблон:Code character,Шаблон:Sfn as opposed to MS BASICs, which used Шаблон:Code and Шаблон:Code.

Standard statements

The Шаблон:Code command divided the screen into regions 14 spaces wide, and the comma was used to move between these locations; Шаблон:Code would output 1, 2 and 3 in a spaced-out fashion,Шаблон:Sfn while Шаблон:Code would leave a single space and produce "1 2 3".Шаблон:SfnШаблон:Efn Шаблон:Code allowed a prompt string to be specified, but used the semicolon to separate it rather than the comma; Шаблон:Nowrap

Strings could be delimited by single or double quotes.Шаблон:Sfn In addition to the Шаблон:Code and Шаблон:Code functions that converted single characters to and from string format,Шаблон:Sfn BASIC-PLUS also supported Dartmouth's Шаблон:Code command. Шаблон:Code iterated the string and returned each character's ASCII value as a slot in a numeric array. For instance, Шаблон:Code would return an array with the five ASCII codes, 110, 105, 114, 114, 105, in elements 1 through 5, and the number 5, the length of the string, in element 0.Шаблон:Sfn One could reverse the operation as well, Шаблон:Code would read the individual numbers in the X array and convert it to a string.Шаблон:Sfn

Statement modifiers

BASIC-PLUS added the concept of "statement modifiers", JOSS-like conditions that could be applied to any statement. For instance, Шаблон:Code is the equivalent of Шаблон:CodeШаблон:Sfn The opposite was also provided, Шаблон:Code was the equivalent of Шаблон:Code.Шаблон:Sfn

Шаблон:Code loops worked as in other versions of BASIC, and the Шаблон:Code command could not be used in an expression to exit early.Шаблон:Sfn Instead, the Шаблон:Code and Шаблон:Code keywords could be used to control early exits. For instance, Шаблон:Code continue looping until I=10, with the assumption that following code would set the value of I,Шаблон:Sfn meaning it might not exit after 10 iterations but as soon as the code set I to 10.Шаблон:Sfn Modifiers could also be used to build compact one-line loops, for instance, Шаблон:Code would loop until X was 100.Шаблон:Sfn

Variables, expressions and matrixes

Variable names in the early versions of BASIC-PLUS could be a single letter or a single letter followed by a single digit.Шаблон:Sfn With the inclusion of "Extend mode" in later versions, variable names could be up to 29 characters long, and dot (.) was added as a permitted character. Every variable name still had to begin with a letter.Шаблон:Efn As in most versions of BASIC, the Шаблон:Code keyword, for variable assignment, was optional. It could set multiple variables to a single value, like Шаблон:Code.Шаблон:Sfn

The language supported three data types; floating-point numbers, integers, and strings. Variables with no suffix were floating point (8 bytes, range 0.29Шаблон:X10^ to 1.7Шаблон:X10^, up to 16 digits of precision). Integer variables (16-bit, range −32768 to +32767) were indicated with a Шаблон:Code suffix,Шаблон:Sfn string variables (variable length) were indicated with a Шаблон:Code suffix.Шаблон:Sfn

The list of mathematical and logical operators was typical of most BASICs, with some extensions. For math, Шаблон:Code, Шаблон:Code, Шаблон:Code, Шаблон:Code and Шаблон:Code were supported, along with Шаблон:Code as an alternate form of Шаблон:Code for computer terminals that might not have that character. Standard logical comparisons were Шаблон:Code, Шаблон:Code, Шаблон:Code, Шаблон:Code, Шаблон:Code, and Шаблон:Code. One interesting addition was the Шаблон:Code operator, for "approximately equal". This would return true if the two numbers would be printed the same, that is, their six most significant digits were the same.Шаблон:Sfn Logical operators included the typical Шаблон:Code, Шаблон:Code and Шаблон:Code, along with Шаблон:Code, Шаблон:Code which return true if both A and B are true or both are false, and Шаблон:Code which is false if A is true and B is false and otherwise always true.Шаблон:Sfn

The Шаблон:Code statement could allocate one-dimensional and two-dimensional arrays of any of the three data types. The range of subscripts always began with 0 (but Шаблон:Code statements did not set elements in row 0 or column 0).Шаблон:SfnШаблон:Sfn

The language also included a number of Шаблон:Code commands to work with the entire array (or MATrix). The Шаблон:Code command would fill the matrix with values in a Шаблон:Code statement,Шаблон:Sfn Шаблон:Code would fill the array with user-typed values, and Шаблон:Code would print out the elements in a 1D or 2D format.Шаблон:Sfn Шаблон:Code could also be used to set default values in a matrix using associated keywords, for instance, Шаблон:Code would fill the A array with zeros.Шаблон:Sfn Шаблон:Code would transpose an entire matrix, and Шаблон:Code would invert it.Шаблон:Sfn Additionally, Шаблон:Code, Шаблон:Code, and Шаблон:Code could be used on matrixes, performing the associated matrix operation.Шаблон:Sfn

File processing

The Шаблон:Code "virtual DIM" statement could map "virtual data array(s)" or "virtual array(s)" to a disk file, which allowed arrays larger than the computer's available memory (or even its address space), and allowed use of array elements to read, write, and extend disk files (persistent storage). They called this arrangement "virtual data storage" and "virtual core", but it did not use the modern approach of allocating the arrays and a memory-mapped file. Instead, a single buffer was used to store 512 bytes of data at a time, and when an entry in the virtual array was accessed, the corresponding data was read, and old data written, as required. The Шаблон:Code statement caused the buffer to be written back (if necessary) before closing the file. Because no additional sectors were cached, accessing data in the "wrong" order could multiply the number of disk accesses. Additional rules were imposed on virtual arrays, such that one datum could never span a record boundary: Each data type was aligned to a multiple of its size. Virtual strings were stored as fixed-length ASCIIZ data, with sizes restricted to 2, 4, 8, 16, 32, 64, 128, 256, or 512 bytes, and were accessed using Шаблон:Code and Шаблон:Code.Шаблон:Sfn

Virtual machine

BASIC-PLUS was not an interpreter but a compile and go system: each line of BASIC was translated into "PPCODE" (Push-Pop Code) as it was entered, for subsequent fast execution on its virtual machine. These translations did not tokenize the BASIC lines but rewrote them for use on a stack machine; you could not translate these representations back to BASIC statements. This avoided the need to repeatedly decode the keywords as strings: once converted to PPCODE the keywords were numbers that pointed to routines to run that function. BASIC-PLUS included a Шаблон:Code command, but this was not a true compiler; this simply saved the program's PPCODE representation so that it did not have to be recompiled when the BASIC program was next loaded into memory. The system stored a user's program in two formats. One was the editable source code in text format, created using the Шаблон:Code command and normally placed in a .BAS file. The other was the PPCODE version of the program created by the Шаблон:Code command and saved to a .BAC file; .BAC files were smaller and loaded and ran faster, but could not be edited.[3]

BASIC Plus 2

Шаблон:Main A related product called Basic Plus 2 ("BP2" or BASIC-Plus-2), was later developed by DEC to add additional features and increased performance.

It used true compilation into threaded code and wrote its output to object files compatible with the machine code object files produced by the assembler and other language systems. These object files could be kept in libraries. A linker (the TKB, also known as the taskbuilder) then created executable files from object files and the libraries. TKB also supported overlays; this allowed individual routines to be swapped into the virtual address space as needed, overlaying routines not currently being used.

Additionally, BP2 programs ran under the RSX Run Time System; this RTS only occupied 8KB of the user's virtual address space, leaving 56KB for the user's program.[4] (RSTS/E version 9 introduced separate Instruction and Data space, and the "disappearing" RSX Run Time System, permitting up to 64KB of each of instruction code and data.) These two factors allowed individual BP2 programs to be much larger than BASIC-PLUS programs, often reducing the need for CHAINing among multiple programs.

Unlike BASIC-PLUS (which was only available on RSTS/E), BP2 was also available for the RSX-11 operating system. BP2 programs were also more compatible with the later VAX BASIC.

Comparison to MS BASIC

Microsoft BASIC was patterned very closely on BASIC-PLUS.[2] Earlier versions of MS BASIC, the 1.x series, lacked integer variables, but these were added in the 2.x series that was found on many machines, including the later models of the Commodore PET and Commodore 64. The ability to place logical and loop commands in-line, like Шаблон:Code was not copied over and does not appear on any common version of microcomputer BASIC. MS BASIC also lacked the matrix commands.

See also

Notes

Шаблон:Notelist

References

Citations

Шаблон:Reflist

Bibliography

Шаблон:BASIC

Шаблон:Authority control