R E V I E W Q U E S T I O N S
11. What are the advantages and disadvantages of dynamic type binding?
– Advantage of dynamic type binding is more flexible and easier to write generic code, but the disadvantages is that it took a long run-time type checking and interpretation
12. Define static, stack-dynamic, explicit heap-dynamic, and implicit heap- dynamic variables. What are their advantages and disadvantages?
Static memory is allocated before execution begins and remains bound to the same memory throughout the execution.
Advantages: Run-time efficient.
Disadvantages: There is no recursion.
Stack-dynamic memory allocation of the system is a pile when declarations are analyzed/described.
Advantages: There recursion and memory-efficient.
Disadvantages: Run-time is not as efficient as static.
Explicit heap-dynamic allocation and deallocation is with explicit instructions, specified by the programmer, which is valid for execution.
Advantages: flexible storage management.
Disadvantages: Prone to error in creating a new statement / delete statements.
Implicit heap-dynamic allocation and deallocation is caused by a statement.
Advantages: Flexibility is very high.
Disadvantages: When the run-time to keep all the attrs dynamic compiler error detection is reduced.
13. Define lifetime, scope, static scope, and dynamic scope.
- Lifetime is when memory is allocated for a variable (when it exists).
- Scope is the range of statements in which the variable is visible. Variables appear in an if statement can be referenced in the statement.
- Static scope is a scope that is based on program text and link reference to a variable name.
- Dynamic scope is a scope that is based on run-time call sequence.
14. How is a reference to a non-local variable in a static-scoped program connected to its definition?
– A reference to a non-local variables in static-scoped language with nested subprograms need access two-step process:
1) Find the correct activation record.
2)Determining the correct offset in activation record.
15. What is the general problem with static scoping?
– Usually too much access. The structure was destroyed as the evolution of the program scope.
PROBLEM SETS
1. Which of the following identifier forms is most readable? Support your decision.
sumOfSales
sum_of_sales
SUMOFSALES
– I prefered sum_of_sales, because it’s underscore (_) make me to read into space ( ).
2. Some programming languages are typeless. What are the obvious advantages and disadvantages of having no types in a language.
Advantages: Allows users to write programs quickly.
Disadvantages: Can not control the data and variables, the compiler can not detect any errors.
3. Write a simple assignment statement with one arithmetic operator in some language you know. For each component of the statement, list the various bindings that are required to determine the semantics when the statement is executed. For each binding, indicate the binding time used for the language.
Language C ++
int count;
count = count*3;
Types are likely to be calculated: the language specified at design time.
Type count: Linked at compile time.
Set of possible values of the count: Tied at the time of compiler design.
Value count: Tied at execution time with this statement.
The set of possible meanings for the operator symbol “”: * Tied on a definition of the language.
* The purpose of the operator symbol “” in this statement: Linked at compile time.
Internal representation of the literal “3”: Tied at the time of compiler design.
4. Dynamic type binding is closely related to implicit heap-dynamic variables. Explain this relationship
– Both are associated with the task and the statement
5. Describe a situation when a history-sensitive variable in a subprogram is useful.
– History-sensitive variables may be useful in subprograms data manipulation, in which some of the operations performed on variables, and function out, then the function is called again. In this way, the function does not have to take a variable as a parameter, but only to return it.