What is Array Name Representation in Symbol Table?


It is a data structure including data for each identifier, fields for the attribute of the identifier. The data structure enables us to find the data for each identifier fastly and to save or retrieve the information for that record quickly.

The symbol table is searched each time a name is encountered in the source text. When a new name or new data about an existing name is found, the content of the symbol table modifies. Thus, the symbol table should have an effective structure for creating the data held in the table also for inserting new entries to the symbol table.

This representation is used to represent the array name and its dimension and other attributes in the symbol table.

Array names can be represented in the symbol table in two different manners.

  • Fixed number of dimensions
  • Variable number (No Limit) of dimensions.

Fixed Number of Dimensions

Consider an example of FORTRAN, where the number of dimensions is limited to 3 for an array figure show array representation in the symbol table.

  • The word containing A represent dimension of the array. A is 2 bit long.
Bit 1Bit 2 Description of Array
00Not an Array
011 Dimensional
102 Dimensional
113 Dimensional
  • UL1, UL2, UL3 represents the upper limit for each of the dimension of Array. The Upper Limits of the array can be a formal parameter.

For this possibility, we have provided 3 bits for B to define whether any of the three possible limits are formal parameters.

010

Here ith bit is 1 that means ULi is a formal parameter.

In the above case 2nd bit is 1 and hence UL2 is passed as a formal parameter, and UL2 in the symbol table now will contain a pointer to Symbol table Record containing the value of UL2.

Example1− Consider the following subroutine in FORTRAN.

SUBROUTINE S (ARRAY, A, B)

INTEGER A, B

REAL ARRAY (5, A, B)

Construct Symbol Table Record for Array in this subroutine.

Solution

∴ UL1 = 5

UL2 = Pointer to record for name A.

UL3 = Pointer to record for name B.

Linked Array Representation of Array with no limit on the dimension

  • Symbol Table will store multiple dimensions of n array.
  • It contains a pointer to an array containing the lower and upper limit of the first dimension, and this array is connected to another array that contains lower and upper limit for the second dimension and so on.

Advantages

  • Random access to the symbol table is facilitated.
  • The ease of accessibility is increased.
  • Easy to maintain information.


Disadvantage

  • Problems of pointer indirection and dangling references.
  • The additional requirement of the separate array for each dimension


Updated on: 08-Nov-2021

358 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements