Thursday 27 June 2013

Chapter 10



Concept of Programming Languages by Robert W. Sebesta Answer

Review Questions


2. Which of the caller or callee saves execution status 

information?
Status information can be saved by either caller or callee.


4. What is the task of a linker?
Task of a linker is to find the files that contain the translated subprograms referenced in that program and load them into memory. Then, the linker must set the target addresses of all calls to those subprograms in the main program to the entry addresses of those subprograms.

6. What is the difference between an activation record and an activation record instance?
By definition, activation record is the format or layout of the noncode program of a subprogram, named so because the data it describes are relevant only during activation. Activation record instance, on the other hand, is a concrete example of an activation record, a collection data in the form of activation record.

8. What kind of machines often use registers to pass parameters?
Usually, RISC machines use registers to pass parameters.

10. Define static chain, static depth, nesting_depth, and chain_offset.
A static chain is a chain of static links that connect certain activation record instances in the stack. A static depth is an integer indicating how deep the static chain is nested in the outermost scope. Nesting_depth and chain_offset are somewhat similar, that is, the difference between the static_depth of the subprogram containing the reference to a certain variable and the static_depth of the subprogram containing the declaration of that certain variable.

15. Explain two methods of implementing blocks.
Blocks can be implemented using the static-chain process for implementing nested subprograms, so blocks in this case are treated as parameter-less subprograms that are always called from the same place in the program.

19. Compare the efficiency of deep access method to that of the shallow access method, in terms of both calls and nonlocal accesses.
The deep access methods provides fast subprogram linkage, but references to non local, and it’s very costly when it comes to non locals accessed with long call chain. Shallow access methods, however, provide faster references to non locals, but more costly in subprogram linkage.

Problem Set

6. Although local variables in Java methods are dynamically allocated at the beginning of each activation, under what circumstances could the value of a local variable in a particular activation retain the value of previous activation?
A local variable can retain the value of previous activation when declared as static. Static modifiers in Java are history-sensitive.


7. It is stated in this chapter that when a nonlocal variables are accessed in a dynamic-scoped language using the dynamic chain, variable names must be stored in the activation records with the values. If this were actually done, every nonlocal access would require a sequence of costly string comparison on names. Design an alternative to these string comparisons that would be faster.

Use an approach of auxillary data structure, the so-called display, or perhaps, try to write variables as integers which act like an array. Upon activation, it will compare faster.


8. Pascal allows gotos with nonlocal targets. How could such statements be handled if static chains were used for nonlocal variable access? Hint: Consider the way the correct activation record instance of the static parent of a newly enacted procedure is found.
The target of every goto in a program could be represented as an address and a nesting_depth, where nesting_depth is the difference between the nesting level of the procedure that contains the goto and that of the procedure containing the target. When a goto is executed, the static chain is followed by the number of links indicated in the nesting_depth of the goto target. The stack top pointer is reset to the top of the activation record at the end of the chain.


9. The static-chain method could be expanded slightly by using two static links in each activation record instance where the second points to the static grandparent activation record instance. How would this approach affect the time required for subprogram linkage and nonlocal references?

The nesting of scopes is known at compile time. So, the compiler can determine not only that a reference is nonlocal, but also the length of the static chain that must be followed to reach the activation records instance that contains the nonlocal object.

0 comments:

Post a Comment