Rabu, 29 Oktober 2014

CHAPTER 5

Nama : Aditya Isnugraha
Class   : LM01
NIM    : 1801419606

Assignment from Tri Djoko Wahjono
CHAPTER5

- REVIEW QUESTION

11. What are the advantages and disadvantages of dynamic type binding?
Answer :
Advantages: flexibility and no definite types declared(PHP, JavaScript).

Disadvantages: adds to the cost of implementation and type error detection by the compiler is difficult.



12. Define static, stack-dynamic, explicit heap-dynamic, and implicit heap- dynamic variables. What are their advantages and disadvantages?
Answer :
- Static: bound to memory cells before execution begins and remains bound to the same memory cell throughout the execution.

- Stack-dynamic: storage bindings are created for variables when their declaration statements are elaborated.

- Explicit heap-dynamic: allocated and deallocated by explicit directives, specified by the programmer, which take effect during execution.

- Implicit heap-dynamic variables: Allocation and deallocation caused by assignment statements.


13. Define lifetime, scope, static scope, and dynamic scope.
Answer :
 - Lifetime: A time during which the variable is bound to a specific memory location. The lifetime begins when it is bound to a specific cell and ends when it is unbound from that cell.
 - Scope: The range of statements in which the variable is visible. A variable is visible in a statement if it can be referenced in that statement.
 - Static scope: is based on program text and to connect a name reference to a variable , you (or the compiler) must find the declaration.
 - Dynamic scope: Based on calling sequences of program units, not their textual layout (temporal versus spatial). References to variables are connected to declarations by searching back through the chain of subprogram calls that forced execution to this point.



14. How is a reference to a nonlocal variable in a static-scoped program con- nected to its definition?
Answer :
 A reference to a non-locally variable in a static-scoped language with nested subprograms requires a two step access process:

1. Find the correct activation record instance

2. Determine the correct offset within that activation record instance


15. What is the general problem with static scoping?
Answer :
Usually too much access. Scope structure destroyed as program evolves.






- PROBLEM SET
1. Which of the following identifier forms is most readable? Support your decision.
SumOfSales
sum_of_sales
SUMOFSALES
Answer :
Sum Of Sales is the most readable. It is because it’s doesn’t have any problem with case sensitive, because the following identifier doesn’t use any caps lock.


2. Some programming languages are typeless. What are the obvious advan- tages and disadvantages of having no types in a language?
Answer :
- Advantages : allow users to write sloppy programs faster.
- Disadvantages : cannot control the data and variables, compiler cannot detect any mistakes.


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.
Answer :
(C++)
int count;count = count + 5;

Possible types for count: set at language design time. Type of count: bound at compile time.
Set of possible values of count: bound at compiler design time. Value of count: bound at execution time with this statement. Set of possible meanings for the operator symbol ““:*bound at language definition time.*Meaning of the operator symbol “” in this statement: bound at compile time.
Internal representation of the literal “5”: bound at compiler design time.


4. Dynamic type binding is closely related to implicit heap-dynamic vari- ables. Explain this relationship.
Answer :
 Implicit heap-dynamic variables acquire types only when assigned value, which must be at runtime. Therefore, this variable are always dynamically bound to types.


5. Describe a situation when a history-sensitive variable in a subprogram is useful.
Answer :
To describe a situation when a history-sensitive variable in a subprogram is useful, suppose that a FORTRAN subroutine is used to implement a data structure as an abstraction. In this situation, it is essential that the structure persists between different calls to the managing subroutine.







Tidak ada komentar:

Posting Komentar