Contents | Prev | Next | Index


Record Types

A record type is a structure consisting of a fixed number of elements, called fields, with possibly different types. In a record type declaration, for each field the name and type is specified. The scope of the field identifiers extends from the point of their declaration to the end of the record type. They are also visible within within designators refering to fields of record variables.

A record field list consists of a fixed part, variant part, or both. The first field of a variant part is called the tag field. Its value indicates which variant is assumed by the variant part. Individual variant structures are identified by case labels. These labels are constants of the type indicated by the tag field.

In the following grammar specification for record types, Java specific language extensions for Pascal are shown in red color. They include the Java modifier and Java name directives.

record_type        ::= record field_seq END                    
record             ::= modifier RECORD                         
field_seq          ::= fixed_part                              
                   ::= fixed_part ; variant_part               
                   ::= variant_part                            
                   ::= fixed_part ;                            
                   ::= fixed_part ; variant_part ; 
                   ::= variant_part ;              
                   ::= <empty>                                 
fixed_part         ::= fixed_part ; field_list                 
                   ::= field_list                              
field_list         ::= modifier field_id_list : type           
field_id_list      ::= field_id_list , field_name              
                   ::= field_name                              
field_name         ::= member_id                               
                   ::= member_id java_name                  
variant_part       ::= CASE tag OF variant_list                
tag                ::= qualident                               
                   ::= field_name : qualident                  
variant_list       ::= variant_list ; variant                  
                   ::= variant                                 
variant            ::= variant_label_list : ( field_seq )      
variant_label_list ::= variant_label_list , variant_labels   
                   ::= variant_labels                          
variant_labels     ::= const_expr                              

This compiler always maps record types and variants to Java classes. Notice that in this compiler, unlike other Pascal implementations, it is not possible to use variants for accessing the same data with different types.

The following are examples of record types:

  RECORD
    day, month, year : INTEGER;
  END

  RECORD
    name, firstname : ARRAY [0..31] OF CHAR;
    age : INTEGER;
    salary : REAL
  END


Contents | Prev | Next | Index

Canterbury Pascal for Java  (Last documentation update Apr 19, 2000)
Copyright © 1998 Mill Hill & Canterbury Corporation, Ltd. All rights reserved
Please send any comments or corrections to mhc@webcom.com