What is representation of fixed-length and variablelength array representation in the symbol table?


Symbol Table is a data structure that supports an effective and efficient way of storing data about various names occurring in the source code. These names are used in the source code to identify the different program elements, like a variable, constants, procedures, and the labels of statements.

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.

There are numerous ways of representing names in symbol table such as fixed-length array representation and variable-length array representation.

Fixed-Length Array Representation

It is one of the easiest methods of representing names in contiguous array records.

Name field of the symbol table is of fixed size.

Similarly, size is also fixed for the amount of information that can be stored for a particular name.

Consider IBM 370 Representation

  • Length of Identifier = 08 characters
  • Amount of Information = 16 characters


Suppose each block can only 4 characters. Hence we require 2 blocks to store an identifier and 4 blocks to keep its information.

Let us Consider the name DONALD.

It is visible that space allocated to the name is wasted as only one and a half block is occupied. However, 2 blocks are given for the name. Let us consider another example.

Here there is a wastage of one complete block. We summed up this using the following diagram. Shaded boxes in the symbol tables denote wastage of memory.

Advantages

  • It is easy to understand.
  • It is easy to implement and access.


Disadvantages

  • Wastage of a large amount of memory.
  • Sequential access
  • Insertion and deletion of records are comparatively very slow.
  • It requires large processing and memory requirements.


Variable Length Array Representation

Instead of storing names directly in the symbol table, it will save all names in an independent array of characters and will only keep the start index and length of the name. This will overcome the disadvantage of a fixed-length name. Now it can have a variable length exceeding 8 characters as it was fixed in the previous method. Similarly, we can represent the previous example as

Advantages

  • A variable name can be of any length.
  • Ease of Access.
  • No wastage of memory in the symbol table.
  • The symbol table now more organized.
  • It can facilitate quicker editing.


Disadvantages

  • The problem of indirection maintenance.
  • The requirement of extra array records for storing variable names.


Updated on: 08-Nov-2021

913 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements