Home Random Page


CATEGORIES:

BiologyChemistryConstructionCultureEcologyEconomyElectronicsFinanceGeographyHistoryInformaticsLawMathematicsMechanicsMedicineOtherPedagogyPhilosophyPhysicsPolicyPsychologySociologySportTourism






Example of a type-definition-part

type

natural = 0..maxint;

count = integer;

range = integer;

colour = (red, yellow, green, blue);

sex = (male, female);

year = 1900..1999;

shape = (triangle, rectangle, circle);

punchedcard = array [1..80] of char;

charsequence = file of char;

polar = record

r : real;

theta : angle

end;

indextype = 1..limit;

vector = array [indextype] of real;

person = ­ persondetails;

persondetails = record

name, firstname : charsequence;

age : natural;

married : Boolean;

father, child, sibling : person;

case s : sex of

male :

(enlisted, bearded : Boolean);

female :

(mother, programmer : Boolean)

end;

FileOfInteger = file of integer;

 

NOTE --- In the above example count, range, and integer denote the same type. The types denoted by year and natural are compatible with, but not the same as, the type denoted by range, count, and integer.

 

 

Declarations and denotations of variables

 



Variable-declarations

A variable shall be an entity to which a value can be attributed (see 6.8.2.2). Each identifier in the identifier-list of a variable-declaration shall denote a distinct variable possessing the type denoted by the type-denoter of the variable-declaration.

variable-declaration = identifier-list ':' type-denoter .

The occurrence of an identifier in the identifier-list of a variable-declaration of the variable-declaration-part of a block shall constitute its defining-point as a variable-identifier for the region that is the block. The structure of a variable possessing a structured-type shall be the structure of the structured-type. A use of a variable-access shall be an access, at the time of the use, to the variable thereby denoted. A variable-access, according to whether it is an entire-variable, a component-variable, an identified-variable, or a buffer-variable, shall denote a declared variable, a component of a variable, a variable that is identified by a pointer value (see 6.4.4), or a buffer-variable, respectively.

variable-access = entire-variable ½ component-variable ½ identified-variable ½ buffer-variable .

 

Example of a variable-declaration-part:

var

x, y, z, max : real;

i, j : integer;

k : 0..9;

p, q, r : Boolean;

operator : (plus, minus, times);

a : array [0..63] of real;

c : colour;

f : file of char;

hue1, hue2 : set of colour;

p1, p2 : person;

m, m1, m2 : array [1..10, 1..10] of real;

coord : polar;

pooltape : array [1..4] of FileOfInteger;

date : record

month : 1..12;

year : integer

end;

 

NOTE --- Variables occurring in examples in the remainder of this International Standard should be assumed to have been declared as specified in the above example.

 

Entire-variables

entire-variable = variable-identifier .

variable-identifier = identifier .

 

Component-variables

 



General

A component of a variable shall be a variable. A component-variable shall denote a component of a variable. A reference or an access to a component of a variable shall constitute a reference or an access, respectively, to the variable. The value, if any, of the component of a variable shall be the same component of the value, if any, of the variable.

component-variable = indexed-variable ½ field-designator .

 

Indexed-variables

A component of a variable possessing an array-type shall be denoted by an indexed-variable. indexed-variable = array-variable '[' index-expression, { ',' index-expression } ']' .

array-variable = variable-access .

index-expression = expression .

An array-variable shall be a variable-access that denotes a variable possessing an array-type. For an indexed-variable closest-containing a single index-expression, the value of the index-expression shall be assignment-compatible with the index-type of the array-type. The component denoted by the indexed-variable shall be the component that corresponds to the value of the index-expression by the mapping of the type possessed by the array-variable (see 6.4.3.2).

 

Example 1:

a[12]

a[i + j]

m[k]

 

If the array-variable is itself an indexed-variable, an abbreviation shall be permitted. In the abbreviated form, a single comma shall replace the sequence ] [ that occurs in the full form. The abbreviated form and the full form shall be equivalent.

The order of both the evaluation of the index-expressions of, and the access to the array-variable of, an indexed-variable shall be implementation-dependent.

 

Example 2:

m[k][1]

m[k, 1]

 

NOTE --- These two examples denote the same component-variable.

 

Field-designators

A field-designator either shall denote that component of the record-variable of the field-designator associated (see 6.4.3.3) with the field-identifier of the field-specifier of the field-designator or shall denote the variable denoted by the field-designator-identifier (see 6.8.3.10) of the field- designator. A record-variable shall be a variable-access that denotes a variable possessing a record-type.

The occurrence of a record-variable in a field-designator shall constitute the defining-point of the field-identifiers associated with components of the record-type possessed by the record-variable, for the region that is the field-specifier of the field-designator.

field-designator = record-variable '.' field-specifier ½ field-designator-identifier .

record-variable = variable-access .

field-specifier = field-identifier .

 

Examples:

p2­.mother

coord.theta

 

An access to a component of a variant of a variant-part, where the selector of the variant-part is not a field, shall attribute to the selector that value associated (see 6.4.3.3) with the variant. It shall be an error unless a variant is active for the entirety of each reference and access to each component of the variant.

When a variant becomes non-active, all of its components shall become totally-undefined.

 

NOTE --- If the selector of a variant-part is undefined, then no variant of the variant-part is active.

 


Date: 2015-12-24; view: 753


<== previous page | next page ==>
Required simple-types | Procedure-declarations
doclecture.net - lectures - 2014-2024 year. Copyright infringement or personal data (0.008 sec.)