[SDL Forum Society - Logo] Tutorial on SDL-88
Belina, Hogrefe (edits Reed)

6.7 Records and fields

Back Home Up Next

The record and field types known from ordinary programming languages can be defined by using the constructs already introduced. But the specification of ADTs is not trivial even if one is familiar with it. Therefore, SDL offers the possibility to define record and field types in a conventional way known from programming languages.

Records are specified with the keyword STRUCT:

NEWTYPE address_type
STRUCT
    name,
    first_name,
    street:       Charstring;
    number:    Integer;
    city:          Charstring;
ENDNEWTYPE:

A variable address of type address_type can then be declared::

DCL address address_type

and the variable address of type address_type can be assigned in the following way:

address :=
    (.Hogrefe,
      Dieter,
      Rothenbaumchaussee,
      67,
      Hamburg.)

A certain component of the record can be accessed in the following way

town := address!city

Another frequently used data type is the file type. For this type SDL does not have a special language construct, but there is a predefined generator with name Array which can be used. In the following example a sort file type with 10 field elements of type address type is defined:

SYNTYPE counter = Integer CONSTANTS 1:10; ENDSYNTYPE:
NEWTYPE field_type
    Array (counter, address_type)
ENDNEWTYPE;

Suppose there is a variable file of sort file_type. then a field element can be accessed in the usual way:

file(8) := address

Back Home Up Next

Contact the webmaster with questions or comments about this web site.
Copyright © 1997-May, 2013 SDL Forum Society