Wednesday 4 March 2015

5.0 - QA

1.   What are the design issues for names?
=    The design issues for names are “Are the names case sensitive?” or “Are words for reserved words or keywords?”

2.   What is the potential danger of case-sensitive names?
=    readability (names that look alike, but are different).

3.   In what way are reserved words better than keywords?
 A reserved word is a special word that cannot be used as a user-defined name.
 A keyword is a word that is special only in certain contexts.

4.   What is an alias?
=    When more than one variable can be used to access the same memory location, the variables are called aliases.

5.   Which category of C++ reference variables is always aliases?
=    Union types. Union is a type whose variables may store different type values at different times during program execution.

6.   What is the l-values of a variables? What is the r-values?
=    The l­-values of a variable is its address. The r-values of a variable is its value.

7.   Define binding and binding time.
=    A binding is an association, such as between an attribute and an entity, or between an operation and a symbol. Binding time is the time at which binding takes place.

8.   After language design and implementation [what are the four times bindings can take place in a program?]
  • Language design time —  bind operator symbols to operations
  • Language implementation time– bind floating point type to a representation
  • Compile time — bind a variable to a type in C or Java
  • Load time — bind a C or C++ static variable to a memory cell)
  • Runtime — bind a non-static local variable to a memory cell

9.   Define static binding and dynamic binding.
=    Static binding first occurs before run time and remains unchanged throughout program execution. dynamic binding first occurs during execution and can change during execution of the program.

10. What are the advantages and disadvantages of implicit declarations?
=    The advantage is write-ability.

11. What are the advantages and disadvantages of dynamic type binding?
=    The advantage is flexibility (generic program units).

12. Define static, stack-dynamic, explicit heap-dynamic, and implicit heap-dynamic variables. What are their advantages and disadvantages?
=    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.
=    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 non-local variable in a static-scoped program connected to its definition?
=    A reference to a non-local 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?
=    Usually too much access. Scope structure destroyed as program evolves.

16. What is the referencing environment of a statement?
=    Set of all names visible to the statement.

17. What is a static ancestor of a subprogram? What is a dynamic ancestor of a subprogram?
=    The static ancestors of a subprogram sub() are all the procedures in the program within which the procedure sub() is defined, i.e., the definition of the procedure sub() is nested. The definition of a procedure may be directly nested within only one procedure, called its static parent procedure. However, this static parent procedure may itself be nested within another procedure, and so on up to the main() program. All these procedures are considered to be static ancestors of the procedure sub(). Simply put, the static ancestors are those that strictly contain the subprogram in question.
The dynamic ancestors of a subprogram sub() are all the procedures called before sub() during the execution of a program, that have not yet finished executing. These are the procedures that are waiting for procedure sub() to finish executing before they can terminate. Simply put, dynamic ancestors are those that are called to reach the subprogram in question.

18. What is a block?
=    The storage a variable is allocated when the section is entered and deallocated when the section is exited.

19. What is the purpose of the let constructs in functional languages?
=    “let” introduces a new variable scope, and allows you to bind variables to values for that scope. It is often read as “let x be [value] in …”

22. What are the advantages and disadvantages of dynamic scoping?
=    Advantage: convenience.
Disadvantage: cant type-check at compile time. Poor readability (can’t determine type of a variable statically).

23. What are the advantages of named constants?
=    The advantages are readability and modifiability.

No comments:

Post a Comment