General Enhancements of Pascal

Written by Manpreet Singh | February 19, 2020


Most of the software testing companies in Bangalore prefer using Pascal still like the first step of the learning process because it helps them to understand the basics in an easy way.
Subrange bounds may be constant expressions, in line with the wider relaxation described above, and such subranges define conventional static types. The bounds may also be general expressions, involving run-time variables, and introducing nonstatic types; this topic is discussed separately later.

CASE enhancements. In both variant record declarations and CASE statements, ranges are permitted in constant-lists, and an OTHERWISE clause may be introduced to complete the list.

Short-circuit operators. 

Variants of the Boolean operators AND and OR are provided which guarantee that an expression it evaluated no further than is necessary to determine the result. The new variants are called AND_THEN and OR_ELSE, and they can be used as in the following example to simplify conditional code.

      IF (p <> NIL) AND_THEN (p^.f2 = 2)

      THEN  …..

      ELSE  …..

If p is nil, control passes immediately to the else part, and the illegal dereference p^.f2 (which would result in a protection violation if the program we’re running in a protected memory environment) is not executed.

Non-Decimal numbers may be introduced into source programs using the notation base#number, for instance, 16#FF or 8#377 (hexadecimal FF = octal 377 = decimal 255).

Characteristics. Just as maxing gives implementation-specific information about the integer type, there is a predefined constant max char (the character with largest ordinal value), and constants max real, minreal and eps real which give the characteristics of the real type.

Numeric input from textfiles accepts the representation laid down in the data-interchange standard (ISO 6093), which permits a decimal point in leading or trailing position.

Zero field width. The optional field width parameter in textfile output may take the value zero.

Inverse ord. An enhancement to the success and pred functions allows them to take an optional second parameter of integer type. This is more versatile than a simple inverse of ord, but among other things gives succ that capability; for example, given a conventional day-of-week enumeration, succ(Monday,3) yields Thursday.

Underscores are permitted as significant characters within identifiers, though not in leading or trailing positions.

Array and record constructors

The set constructors of classic Pascal form the basis of constructors to define other structured values. When all the ingredients are constant, a constructed value can be named as a constant or used to define initial states. Within statements, the constructor may include run-time values.

An array constructor may list specific indexes, with the values those elements are to be given, and/or may provide a default to be given to any elements not individually listed. A record constructor names record fields together with the values to be given; the whole record must be defined. (For some purposes it may be more convenient to specify values of individual fields in the record declaration.)

    [3..6,9:5.5; 10:10.5; OTHERWISE 0]   {array}

    [f1,f4:10; f2:’$’; f3:’Message’]    {record}

The processes of indexing and field selection can be applied to structured constants (including string literals) just as to variables; furthermore, within statements an index may be a run-time value, so that different elements of the constant are accessed on different occasions.

February 19, 2020 | 266 Views

Leave a comment

Your email address will not be published. Required fields are marked *

fifteen − 14 =