Friday 12 April 2013

Chapter 5 - Programming Languages Concept - Tenth Edition - Robert Sebesta

Review chapter 5

1. What are the design issues for names ?
case sensitivity and special words of the language and keyboard

2. What is the potential danger of case-sensitive names ?
Case sensitivity causes a serious detriment to readability, and violates the design principle that language constructs, that look similar should have similar meaning

4. What is an alias ?
alias is an variable name that can be used to access same memory locations and variables

7. Define binding and binding time
Binding is 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 is time at which a binding takes place

9. Define static binding and dynamic binding
Static binding is the condition if the binding occurs before the run tume begins and remains unchanged throughout program execution
dynamic binding is the condition if the binding first occurs during run time or can change in the course of program execution

18. What is a block ?
a block are variables that typically stack dynamic, so their storage is allocated when the section is entered and deallocated when the section is exited


Problem set


1. Decide which of the following identifier names is valid in C language. Support your decision.
_Student
Int
123Student
Student123


Following Identifier
    a. _Student = Allowed, Rarely used, doesn’t really affect anything
    b. int = Not allowed, because it will be confusing to have a variable name as the type specifiers
    c. 123Student = Not allowed, the variable name look messy and can be confusing if used extensively.
    d. Student123 = Allowed, handy in case we want to separate a variable that we clearly know the purpose (For example we usually use x to measure length, we can type x1 for the first length, and x2 for the second length).

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 coping, 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 , but assume dynamic scoping.

Scope

a. Static :

    1. Sub1 : sub1
    2. Sub2 : sub1
    3. Sub3: main

b. Dynamic :

    1. Sub1 : sub1
    2. Sub2 : sub1
    3. Sub3: 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 sub1?

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


Static Scope then x = 5, if Dynamic Scope then x = 10

10. Consider the following C program

void fun(void) {
int a, b, c; // definition 1

while ( …) {
int b, c, d; // definition 2
… <-1
while (…) {
int c, d, e; // definition 3
… <- 2
}
… <- 3
}
… <- 4
}

For each of the four marked points in this function, list each visible variable, along with the number of the definition statement that defines it.

Points:

1) Variables :
    a = 1    b = 2
    c = 2    d = 2
2) Variables :
    a = 1    b = 2
    c = 3    d = 3
    e = 3
3) Variables :
    a = 1    b = 2
    c = 2    d = 2
4) Variables :
    a = 1
    b = 1
    c = 1

No comments:

Post a Comment