Home » Uncategorized » Concepts of Programming Language – Chapter 5 (Names, Bindings, Scopes)

Concepts of Programming Language – Chapter 5 (Names, Bindings, Scopes)

Review Question

1. What are the design issues for names?

    – Are names case sensitive?

   – Are the special words of the language reserved words or keywords?

2. What is the potential danger of case-sensitive ?

   if the variables have the similar meanings, such as, “Rose” with “rose”, in case-sensitive,    there is no connection between them, case-sensitive violates the design principle that    language constructs that look similar should have similar meanings.

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 can take                      place at language design time, or run time.

   binding time -> the time at which a binding takes place.

13. Define lifetime, scope, static scope, and dynamic scope.

   lifetime -> the time during which the variables is bound to a specific memory location.

   scope -> the range of statements in which the variable is visible.

   static scope -> the scope of a variable can be statically determined – that is, prior to                              execution. it permits a human program reader and also a compiler to                              determine the type of every variable in the program simply by examining its                              source code.

   dynamic scope -> based on the calling sequence of subprograms, not on their spatial                                    relationship to each other, the scope can be determined only at run                                    time.

18. What is a block?

   A block is a section of code that allows to have its own local variables whose scope is    minimized and the variables are typically stack dynamic. Blocks provide the origin of the    phrase block-structured language.

19. What is the purpose of the let constructs in functional languages?

   This let constructs have two parts, which is to bind names to values, usually specified as    expressions and also an expression that uses the names defined in the bind names, rather    than statements.

Problem Set

  1. Decide which of the following identifier names is valid in C language. Support your decision.
_Student
int
Student
123Student
Student123
The valid identifiers are: _Student, Student, and Student123. It’s because an identifier in C language has its own rule. There are:
             – An identifier can’t be started with number. The number is valid as long as it is not in the front of an identifier.
               – An identifier can’t include any data types.
               – An identifier can’t be started with symbol.
               – There are not allowed if the name of identifiers if same.
 
 4.  Why is the type declaration of a variable necessary? What is the value range of the int type variable in Java?
The type declaration of a variable is necessary because, in a program it documented information about its data, which provides clues about the program’s behavior. The value range of the int type variable in Java is 32 bits (4 bytes).
 
10. Consider the following C program:
void fun(void) {
int a, b, c; /* definition 1 */
. . .
while (. . .) {
int b, c, d; /*definition 2 */

. . . <-1 p=””>

while (. . .) {
int c, d, e; /* definition 3 */

. . . <-2 p=””>

}

. . . <-3 p=””>

}

. . . <-4 p=””>

}
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.
– In 1 and 3 : the visible variables are a, b(both), c(both), and d from definition 1 and 2.
– In 2: the visible variables are a, b(both), c(both), d(both), and e from definition 1, 2, and 3.
– In 4: the visible variables are a, b, and c from the definition.

 

Leave a comment