31.12.2013 Views

TOPS-20 PASCAL Language Manual - Bitsavers

TOPS-20 PASCAL Language Manual - Bitsavers

TOPS-20 PASCAL Language Manual - Bitsavers

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>PASCAL</strong> DATA TYPES<br />

You can use strings such as 'HELLO' and '****', but you must represent<br />

them as packed arrays of characters (see Section 2.3.1.2). When you<br />

use the ORD function in an expression of type CHAR, the result is the<br />

ordinal value in the ASCII character set of the character value. See<br />

Section 2.2.2.3 for an explanation of the ORD function.<br />

2.2.2 User-Defined Scalar Data Types<br />

User-defined scalar data types are those that you define, as opposed<br />

to those data types that <strong>PASCAL</strong> predefines for you. <strong>PASCAL</strong> allows you<br />

to define two kinds of scalar data types: enumerated and subrange.<br />

An enumerated type consists of an ordered list of identifiers. The<br />

subrange type is a continuous range of values of a defined scalar<br />

type, called a base type. The following sections describe these two<br />

user-defined types.<br />

2.2.2.1 Enumerated Data Types - An enumerated data type is an ordered<br />

list of identifiers. To define an enumerated type, list in some order<br />

all the identifiers denoting its values. With <strong>PASCAL</strong>, you can define<br />

an enumerated data type in two ways:<br />

Fo rma t I<br />

Fo rma t 2<br />

where:<br />

TYPE identifier (identifier II,identifier, •.• ] )<br />

VAR identifier (identifier I[ ,identifier, •.• ] )<br />

identifier<br />

is the name of the enumerated type.<br />

For example:<br />

TYPE Beverage = (Milk, Water, Cola, Beer);<br />

This TYPE section defines the type Beverage and lists all the<br />

that Beverage can assume within a program.<br />

values<br />

<strong>PASCAL</strong> assigns an order to the items in your list from left to right.<br />

Thus, the values of an enumerated type follow a left-to-right order,<br />

so that the last value in the list is greater than the first, for<br />

example:<br />

TYPE Seasons = (Spring, Summer, Fall, Winter) ,<br />

The relational expression (Spring < Fall)<br />

precedes Fall in the list of values.<br />

is TRUE because Spring<br />

The only restriction on the values of an enumerated type is that you<br />

cannot define the same value in more than one list in the same TYPE<br />

section. For example, the following is illegal:<br />

TYPE Seasons = (Spring, Summer, Fall, Winter)<br />

School~ear = (Fall, Winter, Spring);<br />

2-5

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!