Chapter 1: Introduction Performance Objectives You will learn: Facilities and features of PL/1. Structure of programs written in PL/1. Data types. Storage classes, control, and dynamic storage allocation. Language features. Types and use of statements. What is PL/1? The PL/1 programming language: Is machine independent. Utilizes structured programming constructs. Provides exception handling capabilities. Utilizes dynamic storage management. Offers a comprehensive use of data types. Uses data aggregates - arrays, structures, unions, and combinations thereof. Has extensive I/O capabilities. Provides built-in functions: string, mathematical, arithmetic, precision, array, storage control, condition handling, and date/time. CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 1 CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 2 CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 3 Free-form Machine Independence Macro Facility PL/1 has no reserved keywords. PL/1 determines the meaning of keywords from the context of use. Defaults help in avoiding inadvertent keyword coding errors. PL/1 defines its data types without regard for any hardware. The implementers deliver even if the machine has no support for such data type or precision. Permits conditional compilation and modification of PL/1 source before the compilation. A programmer can include specific code during development and testing, and exclude it from a production program. CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 4 CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 5 CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 6 Program Structure Structured Programming Constructs Data Types PL/1 is a block-oriented language consisting of: packages procedures begin blocks statements PACKAGEs, PROCEDUREs, and BEGIN blocks Permit a high degree of data and program logic encapsulation. SELECT... WHEN... OTHERWISE logic Provide for sophisticated case logic. DO statement Provide for grouping of a number of statements as a single unit that can be executed unconditionally one time, forever, or while a condition is true or until a condition becomes true. Data types include: Real or complex, floating-point or fixed-point, signed or unsigned binary or decimal, and numeric and editable picture data with programmer selected precision. Varying or non-varying, character or bit or graphic, run-time adjustable or compile-time fixed length strings. Program control data supporting pointer and offset locators, adjustable or fixed size areas for grouping of dynamic allocations, entry data, on pointers and file, label, and format data. Areas may be written out to the disk and read back at a later date permitting preservation of linked-lists. CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 7 CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 8 CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 9 CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1:1
Data Arrays, Structures, and Unions Data aggregates can be: Arrays Arrays of structures or unions Structures Structures or unions of arrays Unions Combinations of the above. Data Manipulation Data may be manipulated as individual items or as an aggregate. Built-in Functions PL/1 supports these categories of built-in functions: Character, bit, and graphic string manipulation Arithmetic and mathematical computation Floating point inquiries and floating point manipulation Integer manipulation Precision handling Array manipulation Storage control Condition handling Input/output Date/time manipulation CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 10 CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 11 CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 12 Storage Classes, Control, and Dynamic Storage Allocation There are four different storage classes: AUTOMATIC STATIC Condition Handling Handles a variety of conditions that can arise during PL/1 program execution. These conditions may be expected or unexpected and may be detected by the hardware (e.g. ZERODIVIDE) or detected by PL/1 (e.g. CONVERSION) or the operating system or other software. Program Checkout Conditions can be enabled in a variety of ways to have a program automatically diagnosed for: Array subscripts being out of range. String and substrings being out of range. Data exceeding declared or machine supported precisions. CONTROLLED BASED CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 13 CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 14 CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 15 Input and Output I/O Conditions Blocks PL/1 programs have the capability to: process various sizes and type of records. access various devices. edit and validate various kinds of input and output data. produce report files. Two types of I/O are provided: Record-oriented input/output. Stream input/output. PL/1 provides the following I/O conditions: ENDFILE ENDPAGE KEY RECORD TRANSMIT UNDEFINEDFILE FILEOPEN ONKEY ONSOURCE ONCHAR ONFILE PAGENO LINENO PL/1 is a block-structured language. External Procedure, is the outermost block, it provides the shell for all code and data. Procedures are executed only as subroutines or functions. Begin-blocks, are executed inline, can be nested to any depth. CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 16 CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 17 CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 18 CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1:2
Keywords Data Defaults PL/1 does not have reserved words. PL/1 has keywords which are recognized only in context, and may otherwise be used freely by the programmer. A variable and keyword can use the identical designation. PL/1 offers the programmer control over data attributes. A variable can be specified to the number of digits or bits it is to occupy. Strings can have constant lengths or vary from zero to a maximum number of bits or bytes, with the compiler keeping track of the current length. PL/1 provides an extensive system of defaults. In the minimal case, data does not need to be declared at all. A set of default attributes will be provided depending on the context in which it is used. CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 19 CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 20 CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 21 Storage can be: AUTOMATIC STATIC BASED EXTERNAL Storage I/O Input-output is an integral part of PL/1; it is not an add-on library function. Files can be processed as streams of bytes or as individual records which can be fixed-length or variable. Files can be processed sequentially or randomly by record or key. Programs can start an I/O operation and later be interrupted on completion. Exceptions PL/1 has a detailed system for handling exceptions, which can asynchronously result from I/O errors, hardware-generated or program-generated. Handlers for each condition can be specified via the ON statement; handlers can be stacked and unstacked. CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 22 CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 23 CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 24 Character Set Character Types Special Characters SBCS: Single-byte character set. DBCS: Double-byte character set. PL/1 supports these character types: Alphabetic and extra lingual characters Decimal digits Binary digits Hexadecimal digits b - (. % > = * ) ' ; & < + /, " : _ CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 25 CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 26 CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 27 CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1:3
Composite Symbols Identifiers Programmer-defined Names > >= > -= ** = /* => *= < <= */ += /= An identifier is a series of characters that are not contained in a comment or a constant. The first character of an identifier must be an alphabetic or extralingual character. External user names must not start with IBM, PLI, CEE, _IBM, _PLI, and _CEE. In a PL/1 program, names are given to variables and program-control data. There also are built-in names, condition names, and generic names. = &= \= **= CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 28 CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 29 CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 30 Blanks Comments Statements Each operator or delimiter can be surrounded with blanks (b). One or more blanks must separate identifiers and constants that are not separated by some other delimiter. Any number of blanks can appear wherever one blank is allowed. Comments are allowed wherever blanks are allowed as delimiters. A comment is treated as a blank and used as a delimiter. Comments are ignored and do not affect the logic of a program. Identifiers, delimiters, operators, and constants are used to construct PL/1 statements. There are few restrictions in the format of PL/1 statements, and programs can be written without considering special coding rules or ascertaining whether each statement begins in a specific column. A statement can begin in the next position after the previous statement, or it can be separated by any number of blanks. CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 31 CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 32 CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 33 Simple Statements Compound Statements Groups There are three types of simple statements: Keyword Assignment null There are four compound statements: IF ON WHEN OTHERWISE A group is either a: do-group select-group CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 34 CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 35 CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 36 CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1:4
CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1: 37 Introduction Program Structure STRUCT: PROCEDURE OPTIONS (MAIN); /* The declarations of variables in a procedure are usually, but not necessarily, placed at the beginning of the procedure. */ DECLARE (X,Y,Z) FIXED, MESSAGE CHARACTER(80), TOTAL FLOAT; /* Executable statements are placed following variable declarations */ X = 0; PUT SKIP LIST(MESSAGE); FINISH: PROCEDURE; DECLARE TEXT (5) CHARACTER (20); END FINISH: /* All procedures must terminate with END statements */ END STRUCT; CETI/ COMPUTER EDUCATION TECHNIQUES, INC. 1:5