Record Structure Declarations and References

What Information Is Stored In Symbol Table From Declaration

  • A record declaration has a form such as : record $field_1$, …, $field_n$ : $type_1$ ; … end
    1. Initialize offset within the record to be 0.
    1. For each entry group,
    2. (a) Find the symbol table entry for the type
    3. (b) Allocate storage within the record using the storage allocation algorithm
    4. (c) Make a symbol table entry for each field, filling in its print name, type, offset in the record, and size
    5. (d) Link the entries for the fields to an entry for the record
    1. The size of the record is the total size given by the storage allocation algorithm, rounded up to whole words, (e.g. multiple of 8)
    1. Variant records simply restart the storage allocation at the place where the variant part begins. Total size is the maximum size of the variants

Generation Of Intermediate Code For References To Records

type date = record mo : 1..12;
day : 1..31;
year : integer end;
person = record name : alfa;
ss : integer;
birth : date end;

var people : array[1..100] of person;

  • people[i].birth.day
  • people[i] : (aref people (i-1)32 ) = (aref people (+ -32 ( i 32) ) )

References Using Pointers

Records With Variant Parts

Citation:

  • Aho, Lam, Sethi, & Ullman, Compilers: Principles, Techniques, and Tools

  • UT Austin CS375: Compilers by G.Novak.