What is Types of Representative Scope Information?

Compiler DesignProgramming LanguagesComputer Programming

Representing scope information is a concept in which the scope of each variable name is preserved in the symbol table so that we can use the same name in different blocks and different locations. Representing name in symbol table along with an indicator of the block in which it appears.

Suppose we have a variable name 'a' in block A and the same variable in block B. Suppose it can store 'a' in the symbol table without block information. In that case, it will only keep the first instance of 'a' which it encounters, hence to overcome this problem names are stored in the form of pair (variable name, block name) so that the same name can be used in different blocks and procedures.

There are two ways of representing scope information which is as follows −

Scope Representation by Number

It stores all values in one Symbol Table.

The same name can be declared many times as a distinct name in different blocks or procedures.

So, each Procedure or block can be given a unique number.

Symbol Table will not contain just the name of the identifier, but each entry will have a pair (name, procedure-number).

We can recognize the particular identifier in a procedure by matching not only the name of the identifier but also match the procedure number to which it belongs.

Each block or procedure will be assigned a number.

Example

The following shows the configuration of Symbol Table, i.e., fill identifiers with their corresponding procedure or block no.

Here, the identifier or name will belong to the most closely nested of active subprograms declaring that identifier or procedure.

Scope Representation By Blocks or Locations

  • It creates a separate table for each Scope Block or procedure.
  • Multiple identifiers with the same name can easily be inserted because the same name variable will be shared in a separate block.
  • We cannot have two variables with a similar name in the same block or procedure.

  • Each procedure or subprogram will have a different table representation of its contents. When an identifier is searched, the proper table, i.e., subprogram or procedure number and identifier name will be matched.
  • This method is more reliable and simpler to understand.
raja
Updated on 08-Nov-2021 09:57:25

Advertisements