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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

The base type can be any enumerated or predefined scalar type except<br />

REAL. You can use a subrange type anywhere in the program where its<br />

base type is legal. The rules for operations on a subrange are the<br />

same as the rules for operations on its base type. A subrange and its<br />

base type are compatible.<br />

The use of subrange types can make a program clearer. For example,<br />

integer values for the days of the year range from 1 to 365. Any<br />

value outside this range is obviously incorrect. You could specify an<br />

integer subrange for the days of the year as fo]lows:<br />

VAF: Da~,~····Of···· y €·~a r J •• 366<br />

By specifying a subrange, you indicate that the values of the variabJe<br />

Day-Of-Year are restricted to the integers from 1 to 366.<br />

Example<br />

TYPE Months = CJan, Feb, Mar, Apr, Mas~ Jun,<br />

Jul, Au~, Sep, Oct, Nov, Dec),<br />

VAR Camp_Mos: Mas •• Oct;<br />

Leaf_Mos: Sept.Nov;<br />

First_Half: 'A' •• 'M';<br />

We> l"'cf:<br />

() •• t.l::.'.i5::~~;'<br />

This example defines the variables Camp_Mos and Leaf_Mos as subranges<br />

of the enumerated type Months. A Camp Mos value can be only May, Jun,<br />

Jul, Aug, Sep, or Oct. A Leaf Mos val~e can be only Sep, Oct, or Nov.<br />

The variable First Half is a subrange of the ASCII characters, with<br />

possible values uppercase A through uppercase M. The variable Word is<br />

a subrange of the integers from a to 05535.<br />

2.2.2.3 The ORD Function - Each element of a scalar type (except the<br />

REAL type) has a unique ordinal value, which indicates its order in a<br />

list of elements of its type. The ORD function returns the ordinal<br />

value as an integer, for example:<br />

OR[lC '(~')<br />

This expression returns 81, which is the ordinal value of uppercase Q<br />

in the ASCII character set (see Appendix B). Note that the order of<br />

the ASCII character set may not be what you expect. The numeric<br />

characters are in numeric order, and the alphabetic characters are in<br />

alphabetic order. All uppercase characters have lower ordina] values<br />

than all lowercase characters, for example:<br />

ORDC'Q') is less than ORDC'a') and<br />

OF~D( 'A') is less than ORDC '7') but<br />

ORDC'Z') is less than ORD('a')<br />

You can use ORD on a value of an enumerated<br />

are ordered starting at zero, for example:<br />

type.<br />

Enumerated<br />

types<br />

Of,[I C Tuef.)da~)<br />

Assuming that Tuesday is a value of type Weekdays (which includes<br />

values Monday, Tuesday, Wednesday, Thursday, and Friday),<br />

expression returns the integer 1.<br />

the<br />

this<br />

The ordinal value of an integer is the integer itself. For examp]e,<br />

ORD(O) equals 0, ORD(23) equals 23, and ORD(-1984) equals -1984.<br />

2-7

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

Saved successfully!

Ooh no, something went wrong!