









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
In this document topics covered which are Activation records and storage management (Static chains), Static chains, Static depth, Chain offset , When control is at Position 2 in program, When control is at Position 3 in program.
Typology: Study notes
1 / 15
This page cannot be seen from the preview
Don't miss anything!










(^) The length of the static chain needed to reach the correct
activation record instance for a nonlocal reference to a variable X is exactly the difference between the static_depth of the procedure containing the reference of X and the static_depth of the procedure containing the declaration for X.
(^) This difference is called the nesting_depth or chain_offset, of
the reference.
(^) The actual reference can be represented by an ordered pair of
integers (chain_offset, local_offset) where chain_offset is the number of links to the correct activation record instance.
(^) To illustrate the complete process of non-
local accesses, consider the following
skeletal program in C
code.doc
RA –Return address, SL – Static link, DL – Dynamic link
Reference to variables in expression Decl – Declaration, Ref – Refrence, SD – Static depth, proc - procedure
When control is at Position 2 in program
(^) After SUB1 completes its execution, the activation record
instance for SUB1 is removed from the stack, and control returns to SUB3. (^) The reference to the variable E at position 2 in SUB3 is local
and uses the pair (0,4) for access.
(^) The reference to the variable B is to the one declared in SUB2,
because that is the nearest static ancestor that contains such a declaration. It is accessed with the pair(1,4). The local_offset is 4 because B is the first variable declared in SUB1, and SUB has one parameter.
(^) The reference to the variable A is to the A declared in BIGSUB,
because neither SUB3 nor its static parent SUB2 has a declaration for a variable named A. it is referenced with the pair (2,3).
When control is at Position 3 in program
(^) After SUB3 completes its execution, the activation record
instance for SUB3 is removed from the stack, leaving only the activation record instances for MAIN_2, BIGSUB, and SUB2. (^) At position 3 in SUB2, the reference to the variable A is to the A
in BIGSUB, which has the only declaration of A among the active routines. This access is made with the pair(1,3). (^) At this position, there is no visible scope containing a
declaration for the variable D, so this reference to D is a static semantics error. The error would be detected when the compiler attempted to compute the chain_offset/local_offset pair.
(^) The reference to E is to the local E in SUB2, which can be
accessed with the pair (0,5).