CBSE (UGC)-NET: Rules Of Pascal Program
The rules for writing a Pascal program are very specific. This work will cover some of the rules for giving names to values stored in memory and for using different types of data in a program. We will explain the basic parts of a Pascal program and discuss how to perform mathematical operations.
In Pascal, identifiers are used to name the parts of a program and objects used within the program. A valid Pascal identifier is any string of characters that begins with a letter (a z) and contains letters (a z) or digits (0 9). The letters may be either upper-or lowercase. Many systems do not distinguish between upper-and lowercase letters. On these systems, the identifiers SUM, Sum, and sum would be considered identical. Mixing upper-and lowercase letters in identifiers will result in more readable names.
There is no limit to the length of an identifier, but some compilers only recognize the first eight characters in the identifier. This means that these first eight characters must be unique.
Identifiers may be divided into three distinct categories. Reserved identifiers (sometimes referred to as reserved words) have special predefined meanings to the Pascal compiler. These identifiers may not be redefined by the programmer hence their reserved status. Examples of reserved identifiers that will be discussed in this work are program, begin, end, const, and var.
Standard identifiers also have predefined meanings to the Pascal compiler but they are not reserved. This means the programmer may redefine a standard identifier without causing an error when the program is executed. Although the compiler will allow the programmer to redefine standard identifiers, this should not be done because it can make it difficult to follow program logic. The standard identifiers that will be discussed in this work are the words real, integer, boolean, and char.
User-defined identifiers are those identifiers that are supplied by the programmer to name objects or processes that are used within the program. The formulation of user-defined identifiers should follow the rules for identifiers stated at the beginning of this section.
Before discussing the actual structure of a Pascal program, it is important to understand how data is stored in the primary storage unit of a computer. To visualize the computer's primary storage unit, imagine a block of post office boxes. Each box has an assigned number that acts as an address for the location of that particular box. Similarly, the primary storage unit in a computer is divided into many separate storage locations. Each location has a, specific address but, unlike a post office box, can contain only one piece of data at a time. While the contents of the storage location can change, the address stays the same. Storage locations may be referenced by their addresses just as post office boxes can be referred to by the number assigned to them. In machine language, storage location is always referenced by their actual addresses. It is-a difficult task for the programmer. Fortunately, in Pascal (and other high-level languages) the programmer is allowed to “name” storage locations. These names must be valid identifiers. Once the compiler has assigned a name to a specific storage location, the programmer may pimply refer to the location by using its name.
The characteristic of a variable is Its data type (often referred to simply as type). In Pascal, a data type determine both the group or possible values of the variable and the allowable operations for the variable. For example, a variable that is declared to be of type real (that is, number with decimal points) may only contain values that are real numbers, and may only be used with operations that ate allowed for real numbers, such as multiplication and addition. Hours and Rate, have real numbers stored in them, these two variables must be declared to be of data type real.
A storage location whose value can change during program execution is referred to as a variable. Variables contain the data that is used during program execution and the intermediate and final generated by program. A variable has three distinct characteristics:
- a name
- a value
- a type
Pascal contains a variety of data types that indicate to the compiler what kind of data will be stored in a particular location, and also indicate the types of operations that may be per formed on that data.
Batch Versus Interactive Processing
A computer can execute programs in two basic ways: By batch processing or by interactive processing. In batch processing, the user does not interact directly with the computer during program execution. Instead, several user programs are grouped, or batched, and processed one after another in a continuous stream. Batch processing is usually slow because programs must wait in line for their turn to be processed. However, batch processing can make good use of computer time. The programs are executed efficiently. Also, they can be run at times when the system is least busy, such as at night.