Comparison of Deep and Shallow Access

Estudies4you
Dynamic Scope
  • The dynamic scope allocation rules are used for non-block structured languages
  • By considering the current activation, it determines the scope of declaration of the names at runtime
Example: LISP and SNOBOL are the languages which use dynamic scope rule.
  • In this type of scoping, the non-local variables access refers to the non-local data which is declared in most recently called and still active procedures
  • Therefore, each time, new bindings are set up for local names called procedure
  • Symbol tables are required at runtime in dynamic scoping
  • The two ways to implement non-local accessing under dynamic scoping are:
Deep Access
Shallow Access

Deep Access:
  • The idea is to keep a stack of active variables. Use control links instead of access links and to find a variable, search the stack from top to bottom looking for most recent activation record that contains the space for desired variables
  • This method of accessing nonlocal variables is called deep access. Since search is made “deep” in the stack, hence the method is called deep access. In this method, a symbol table should be used at runtime
Shallow Access
  • The idea to keep a central storage and allot one slot for every variable name
  • If the names are not created at runtime then the storage layout can be fixed at compile time. Otherwise, when new activation procedure occurs, then that procedure changes the storage entries for its local at entry and exit (i.e., while entering in the procedure and while leaving the procedure)
Comparison of Deep and Shallow Access
Deep Access
Shallow Access
Deep access takes longer time to access the nonlocals
Shallow access allows fast access
It needs a symbol table at runtime
It has a overhead of handling procedure entry and exit

Runtime Stack and Heap Storage Allocation:
  • The compiler demands for a block of memory to operating system. The compiler utilizes this block of memory for running the compiled program. This block of memory is called runtime storage
  • Runtime storage organization is as follows:
Dynamic Scope in Symbol Table, Comparison of Deep and Shallow Access, Shallow Access in symbol table, Runtime Stack and Heap Storage Allocation,Stack Storage in symbol table,Heap Storage in symbol table, estudies4you, jntuh r16 compiler design syllbus, jntuh r16 compiler design lecture notes, r16 jntuh 3-1 lecture notes pdf, jntu compiler design notes unitwise,
  • Many compilers use the combination of the following two strategies for runtime storage allocation:
Stack Storage
Heap storage

Stack Storage:
  • Compilers for languages that use procedures, functions or methods of user-defined actions manage at least part of their runtime memory as stack
  • Each time a procedure is called, space for its local variables is pushed onto stack, and when the procedure deactivates, the space is popped off the stack
  • Procedure calls and returns values are usually managed by a runtime stack called the control stack
Heap Storage:
  • Heap is the area of runtime storage in which other information is stored
  • For example, memory for some data items is allocated under the program control
  • Memory required for these data items is obtained from this heap area
  • The size of stack and heap is not fixed; it may grow or shrink interchangeably during the program execution
  • Pascal and C need the runtime stack
Home
To Top