Skip to content
Tristan Hume edited this page Apr 22, 2012 · 3 revisions

#typeSpec

##Syntax A typeSpec (type specification) is one of:

(a)int (b)real (c)boolean (d)stringType % Example: string ( 20 ) (e)subrangeType % Example: 1 .. 150 (f)enumeratedType % Example: enum ( red,_ green_,_ blue )_ (g)arrayType % Example: array 1 .. 150 of real (h)setType % Example: set of 1 .. 10 (i)recordType % Example: recordend record (j)unionType % Example: unionend union (k)pointerType % Example: pointer to collectionVar (l)namedType % Example: colorRange (m)nat % natural number (n)intn % n-byte integer (n=1,_ 2_,_ 4)_ (o)natn % n-byte natural (n= 1,_ 2_,_ 4)_ (p)realn % n-byte real (n=4,_ 8)_ (q)char % single character (r)char(n) % n characters (s)subprogramType

##Description A type specification determines the allowed values for a variable or constant. For example, if variable x is an integer (its typeSpec is int), the possible values for x are numbers such as -15, 0, 3 and 348207. If x is a real number (its typeSpec is real), then its possible values include 7.8, -35.0, and 15e12. If _x _is a boolean, its possible values are true and false. If _x _is a string, its possible values include Hello and Good-bye.

##Example

    var numberOfSides : int
    var x, y : real
    type range : 0 .. 150   % The typeSpec here is 0 .. 150
    type entry :            % Here is a record typeSpec
        record
            name : string ( 25 )
            age : range
        end record

##See also int.html, real.html, boolean.html, string1.html, subrangetype.html, enum.html, array.html, set.html, record.html, union.html, pointer.html, named.html,** nat.html**, int.htmln, nat.htmln, real.htmln, char.html, and char.html(n) types.

Clone this wiki locally