NADAR SARASWATHI COLLEGE OF ARTS&SCIENCE,THENI
DEPARTMENT OF COMPUTER SCIENCE&INFORMATION TECHNOLOGY
R.RAMYA DEVI
I-MSC(CS)
COMPILER DESIGN
TOPIC: REPRESENTING SCOPE
INFORMATION,FORTRAN
REPRESENTING SCOPE INFORMATION
Representing scope information is a concept
in 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 Scope Information involves:
 A lifetime of a variable in a particular block.
 Representing name in symbol table along
with an indicator of the block in which it
appears.
Representing Scope Information involves:
 Suppose we have a variable name 'a' in block A and
the same variable in block B. Suppose we store 'a' in
symbol table without block information. In that se, 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.
 Scope Representation reflects the visibility of the
variable name in the source program.
Representing Scope Information in
FORTRAN:
 FORTRAN program consists of the main
program, subroutines, and functions.
 Each name has a scope consisting of one
routine, i.e., the variable scope is limited to
the end of the routine.
Representing Scope Information in
FORTRAN:
 It can generate object code for each
routine upon reaching the end of the routine
and hence the names stored in the symbol
table for variables belonging to that particular
routine need to be eliminated.
 Hence we need to store only names that
are external to routine and also of the
common block in the symbol table.
CONSIDER A HASHING SCHEME, AS SHOWN BELOW
CONSIDER A HASHING SCHEME, AS SHOWN BELOW
 In each chain, names that are external to the
current routine will appear first.
 It can append new internal names to the end
and new external names to the beginning.
CONSIDER A HASHING SCHEME, AS SHOWN BELOW
 It is clear from the above diagram hash value
has selected name 2, and hence 2 iscpart of
the current routine, and Name 1 is external to
it, that’s why Name 1 is written in the
beginning and Name 2 is appended at the
end.
 When we reach the end of the routine and
generate object code for it, we reset the
pointer to available storage in the reusable
table but not a permanent one.
CONSIDER A HASHING SCHEME, AS SHOWN BELOW
 All pointer that is from the permanent table to
the reusable table is set to nill, and the hash
table will directly point to the reusable table.
 We can also reuse the storage space used
for names in the following way. We will use
location in name link storage areas to
represent the name, and such a location can
describe different routines since that area is
reused.
COMPILER DESIGN
COMPILER DESIGN

COMPILER DESIGN

  • 1.
    NADAR SARASWATHI COLLEGEOF ARTS&SCIENCE,THENI DEPARTMENT OF COMPUTER SCIENCE&INFORMATION TECHNOLOGY R.RAMYA DEVI I-MSC(CS)
  • 2.
    COMPILER DESIGN TOPIC: REPRESENTINGSCOPE INFORMATION,FORTRAN
  • 3.
    REPRESENTING SCOPE INFORMATION Representingscope information is a concept in 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.
  • 4.
    Representing Scope Informationinvolves:  A lifetime of a variable in a particular block.  Representing name in symbol table along with an indicator of the block in which it appears.
  • 5.
    Representing Scope Informationinvolves:  Suppose we have a variable name 'a' in block A and the same variable in block B. Suppose we store 'a' in symbol table without block information. In that se, 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.  Scope Representation reflects the visibility of the variable name in the source program.
  • 6.
    Representing Scope Informationin FORTRAN:  FORTRAN program consists of the main program, subroutines, and functions.  Each name has a scope consisting of one routine, i.e., the variable scope is limited to the end of the routine.
  • 7.
    Representing Scope Informationin FORTRAN:  It can generate object code for each routine upon reaching the end of the routine and hence the names stored in the symbol table for variables belonging to that particular routine need to be eliminated.  Hence we need to store only names that are external to routine and also of the common block in the symbol table.
  • 8.
    CONSIDER A HASHINGSCHEME, AS SHOWN BELOW
  • 9.
    CONSIDER A HASHINGSCHEME, AS SHOWN BELOW  In each chain, names that are external to the current routine will appear first.  It can append new internal names to the end and new external names to the beginning.
  • 10.
    CONSIDER A HASHINGSCHEME, AS SHOWN BELOW  It is clear from the above diagram hash value has selected name 2, and hence 2 iscpart of the current routine, and Name 1 is external to it, that’s why Name 1 is written in the beginning and Name 2 is appended at the end.  When we reach the end of the routine and generate object code for it, we reset the pointer to available storage in the reusable table but not a permanent one.
  • 11.
    CONSIDER A HASHINGSCHEME, AS SHOWN BELOW  All pointer that is from the permanent table to the reusable table is set to nill, and the hash table will directly point to the reusable table.  We can also reuse the storage space used for names in the following way. We will use location in name link storage areas to represent the name, and such a location can describe different routines since that area is reused.