Variable DeclarationsTopProgram StructureTypes

Types

< type definition list > -> < type definition list > < type definition >
|
< type definition > -> typedef < type specification > < identifier > ;
< type specification > -> < type name > [ < integer constant > ]
| struct { < field list > }
< type name > -> < identifier >
| int

< field list >

-> < field specification >
| < field list > < field specification >
< field specification > -> < type name > < identifier > ;

A < type definition > associates an identifier with a structured type. This name can then be used to declare variables or parameters of the type and to describe other structured types that have the elements of the defined type as sub-components. All type names must be declared before they can be used. In particular, Co does not support recursive types.

Note, that in Co, one must introduce and use type names for all structured types you wish to use in a program. The language does not allow one to use explicit array or record type specifications outside of the type definition part of the main program.

The only scalar type provided in Co is the type integer. As noted below, character constants are treated as integer values and the values 0 and 1 are used to represent the Boolean values `true' and `false'.

The type name included in an array specification determines the element type of the array. The integer constant in an array specification specifies the number of elements in the array. The elements of an array are numbered starting at zero. Thus, the specification

int[5]

describes an array of integers with elements 0, 1, 2, 3 and 4 but no element 5. Arrays are single dimensional, but the element type of an array may be some earlier defined array type. Thus, arrays of arrays of ... may be defined.

Structure types in Co are similar to strutures in C except that, in the interest of syntactic simplicity, each field must be specified separately (i.e. one cannot include a list of identifiers in a field specification). A particular < identifier > may only name one field of a given record type, but can be reused as a variable name or as the name of a field of any other record type.


Computer Science 434
Department of Computer Science
Williams College

Variable DeclarationsTopProgram StructureTypes