Monday, April 8, 2013

KBP Assignment

Concepts of Programming Language 10th Edition
Chapter 5

For Mr. TriDjokoWahjono

Review Question


1. What are the design issues for names?

The design issues for names are :
  • Are name case sensitive?
  • Are the special words of the language reserved words or keywords?
2. What is the potential danger of case-sensitive names?
The danger is that you might not be able to find the name in a reference even if you have spelled it correctly, because you haven't got the case right. Therefore, you won't find information that you need, or you might incorrectly create a new record with a different case, which nobody else will be able to find because it isn't with the rest of the information.

4. What is an alias?
An alternative name for an object, such as variable, file, or device.

7. Define binding and binding time.
Binding : an association between an attribute and an entity, such as between a variable and its type or value, or between an operation and a symbol.
Binding Time : The time at which a binding takes place.

9. Define static binding and dynamic binding.
Static Binding : the process of mapping a message to a specific sequence of code (method) at compile-time.
Dynamic Binding : the process of mapping a message to a specific sequence of code (method) at runtime.

Problem Set

2. What is l-value? Write a statement in C language which gives the compile time error "l-value required".

l-value is a value that can be the target of an assignment. The "l" stands for "left" or "locator".
A statement in C language which gives compile error :
1 = 2;
int i; (i+2) = 2;

6. Consider the following JavaScript skeletal program:
//the main program
var x;
function sub1(){
   var x;
   function sub2(){
   ...
   }
}
function sub3(){
...
}
Assume that the execution of this program is in the following unit order:
main calls sub1
sub1 calls sub2
sub2 calls sub3
a. Assuming static scoping, in the following, which declaration of x is the correct one for a reference to x?
   i. sub1
   ii. sub2
   iii. sub3
b. Repeat part a, but assume dynamic scoping.

a.) i.) sub1   ii.) sub1   iii.) Main
b.) i.) sub1   ii.) sub1   iii.) sub1

7. Assume the following JavaScript program was interpreted using static-scoping rules. What value of x is displayed in function sub1? Under dynamic scoping rules, what value of x is displayed in function sub1?

var x;
function sub1(){
   document.write("x = " + x + "<br />");
}
functin sub2(){
   var x;
   x = 10;
   sub1();
}
x = 5;
sub2();

Static scoping: x=5;
Dynamic scoping: x=10;

No comments:

Post a Comment