1 File: X01_Fundamentals.doc By: J.M. Smeenk Revision: 5/18/09 9:24 PM ---------------BPL FUNDAMENTALS ---------------1. BPL FUNDAMENTALS. This section describes concepts fundamental to BPL. 1.1. CHARACTER SET. BPL executes lines of codes written using the ASCII character set. (BPL could easily be modified for EBCDIC or UniCode character sets.) A BPL program is composed of the following ASCII characters: A a ! , B b @ . C c # ? D d $ / E e % ~ F f ^ ` G H I g h i & * ( blank J K L M N O P Q R S T U V W X Y Z j k l m n o p q r s t u v w x y z ) _ - + = { } [ ] | \ : ; " ' < > newline The newline character, used to store the enter key, is represented with ASCII code decimal 10 (LF). BPL is usually written with a font whose characters are all of equal width (as in this document) so that certain output prints uniformly. 1.1.1. OTHER ASCII CHARACTERS IN CODE. Whenever a tab character occurs in BPL, it is replaced by 3 blanks; this aids typing with BPL's indentation scheme. Whenever a nonprinting character (any ASCII character not mentioned so far) appears in BPL code, an error is reported. 1.2. CODE STANDARDIZATION. Code is stored in BPL in a standard format in which the code is "cleaned up" from what is provided, so that numbers are printed in a standard format, multiple blanks outside of literal strings are compressed to single blanks, indentation is standardized, etc. Thus the user can type in his/her own style, knowing minor typographical errors will be fixed. Line numbers can be prefixed to program listings by saying list PN, where PN is the program name. 1.3. BPL DIRECT MODE AND EXECUTION MODE. BPL is fundamentally an interpreted language, although a BPL-based compiled language could easily be envisioned. In direct mode, BPL prompts a user with a 3-blank indentation. The user types a line of code and the result (if any) is printed immediately at the left margin (which distinguishes BPL output from user input). Then this cycle is repeated. In execution mode, the user writes a program using a text editor and then runs the program in BPL so that multiple lines of code are interpreted. 1.4. COMMENTS. If a BPL line of code contains **, all subsequent characters in the line are ignored by the interpreter. (These characters are typically comments about the code for the reader's benefit; comments are typically (but not necessarily) mostly in uppercase to distinguish them from code.) 1.5. BPL CONTINUED LINES. 2 A user may input a line longer than the print width (which is typically 80 characters) by arbitrarily breaking the line into two or more shorter lines, all but the last of which ends with ++. The BPL interpreter reconstructs the entire line by concatenating the sublines. When BPL code is printed, BPL inserts the sequence ++ as often as needed to display lines that exceed the print width; the ++ sequences might not appear in the same places as ++ sequences appeared in the original code. The ++ sequence for continued lines is ineffective within literal constants. 1.6. OVERVIEW OF IMPORTANT CONCEPTS. This section describes important BPL concepts. 1.6.1. OVERVIEW OF OBJECTS. BPL objects are constants, variables, functions, and directories. A constant is an array of literal and/or numeric data. An array stores data as a single scalar, as a 1-dimensional vector, as a 2-dimensional matrix, as a 3dimensional box, or as a higher-order array. Literal data is composed of 0 or more characters. Numeric data is composed of 0 or more numbers. A variable is a name that can be assigned and reassigned a value. The value may be a constant, another variable, or an expression (a calculation based on constants and variables). A function is a name that stores 0 or more lines of code. A function performs a calculation on constants, variables, and/or expressions and may yield a result that may be used in expressions. A directory is a name that stores 0 or more entries (constants, variables, functions, and other directories). Ways are provided to assign, reassign, and describe the contents of the directory. BPL allows the user to create named user constants, user variables, user functions, and user directories. BPL provides named system constants, system variables, system functions, and system directories that are built-in. System constants, whether named or unnamed, are similar to user constants, variables, functions, or directories but system constants may not be reassigned a value. System objects either return information about the BPL system or else modify the behavior of the BPL system. 1.6.2. ERRORS. In both direct mode and execution mode, when BPL encounters a statement of code containing an error, the statement is not executed. Instead, execution typically halts and an error message is printed. Then BPL gives the direct mode prompt and awaits direct mode input (presumably a correction to the error). The error message may seem cryptic to the novice but is succinct and helpful to the experienced BPL user. A typical error message contains information about the kind of error, the function name (if any) where it occurred, the statement where it occurred, and a reprint of the significant part of the line to call attention to the location of the error. 1.6.3. LOADING, SAVING, AND RUNNING EXTERNAL DIRECTORIES. The user works in a portion of the computer memory called the active workspace. When the user first accesses BPL, the active workspace contains only system 3 objects. A user may work within the active workspace and create the objects necessary for a programming task. A user may also load and then manipulate objects stored in a directory that is external to the active workspace. The user may save the (possibly modified) objects in a (possibly different) external directory. For convenience, BPL allows the user to easily load an external directory into the workspace and run an expression stored in a system variable of the external directory, so that it "comes out running". The forms are as follows: @: @ExternDirName @ExternDirName: @ @ExternDirName% to load the workspace from an external directory to save the workspace into an external directory to load the workspace from an external directory and have it come out running 1.6.4. EDITING FUNCTIONS AND VARIABLES. Many users use a familiar word processing program for text editing, and since files exist that are neither created in BPL nor were originally designed to be manipulated by BPL, BPL allows importing and exporting of files in either text or binary formats. When text editing is completed, the text file is converted to the code of a BPL function stored in a literal variable, which may then be executed. A binary file is stored in a BPL numeric variable. Using functions, literal variables may be converted to numeric variables and vice-versa. Visual stylistic information (fonts, bolds, underlines, italics, etc.) must not appear in BPL code. 1.6.5. DOCUMENTING OBJECTS. BPL has a documentation program doc which prints out information about objects: a variable's value, a function's code, a directory's objects, and optionally other information such as byte size or creation date can be displayed. The forms are as follows: doc doc doc doc "VarName" "FnName" "DirName" "@" display display display display information information information information about about about about variable VarName function FnName directory DirName the active workspace