Names, Binding, Type Checking and Scopes
Written on Monday, May 05, 2008 by Ennah, the comsci student
Research 4. Read throughly Chapter 4 of Sebesta's Book. Really helpful. I got a perfect score in this research.
Read Chapter 4 by Sebesta.
Part 1. Define the following terms:
a) Alias
b) Binding and binding time
c) Static binding, Dynamic binding
d) Static, static-dynamic, explicit heap-dynamic, implicit heap-dynamic
e) Coercion, type error, type checking, strong typing
f) Name type compatibility, structure type compatibility
g) Lifetime, scope, static scope, dynamic scope
h) Block
Part 2. Explain briefly.
a) What are the design issues for names?
b) In what ways are reserved words better than key words?
c) What are the advantages & disadvantages of implicit declarations?
Answers
Part 1
a) Aliases
Aliases are names that have more than one variable name that can be used to access a single memory location. Aliases are multiple identifiers reference the same address.
b) 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 a binding takes place.
c) Static binding, Dynamic binding
Static binding is a binding that occurs first before runtime and remains unchanged throughout program execution. Dynamic binding is a binding that occurs first before runtime or can change in the course of the program execution.
d) Static,static-dynamic, explicit heap-dynamic, implicit heap-dynamic
Static variables are those that are bound to memory cells before program execution begins and remain bound to those memory cells until program execution terminates.
Stack-dynamic variables are those whose storage bindings are created when their declaration statements are elaborated, but whose types are statically bound.
Explicit heap-dynamic variables are nameless (abstract) memory cells that are allocated and deallocated by explicit run-time instructions specified by the programmer. These variables, which are allocated and deallocated to the heap, can only be referenced through pointer or reference variable.
Implicit heap-dynamic variables are bound to heap storage only when they are assigned values. All their attributes are bound every time they are assigned.In a sense, they are just names that adapt to whatever use they are asked to serve.
e) Coercion,type error, type checking, strong typing
Coercion is an automatic conversion of compiler generated code to a legal type.
Type error is the application of an operator to an operand of an inappropriate type.
Type checking is the activity of ensuring that the operands of an operator are of compatible types.
Strong Typing is a new idea in language design which type errors are always detected in the language. This requires that the types of all operands can be determined, either at compile time or at run time. A strongly type language allows the detection, at run time, of uses of the incorrect type values in variables that can store values of more than one type.
f) Name type compatibility, structure type compatibility
Name type compatibility is a compatibility method which means that two variables have compatibility types only if they are in either the same declaration or in declarations that use the same type name.
Structure type compatibility is a compatibility method which means that two variable have compatibility types only if their types have identical structure.
g) Lifetime,scope, static scope, dynamic scope
Lifetime of the variable is the period of time beginning when the procedure is entered and ending when execution of the procedure reaches the end. Lifetime is a temporal concept.
Scope of a program variable is the range of statements in which the variable is visible. It is from its declaration to the end reserve word of the procedure. Scope is a spatial or textual concept.
Static scope is the method of binding names to non local variables. Static scope is thus named because the scope of a variable can be statically determined, that is, prior to execution.
Dynamic scope is a type of scope that is based on calling sequences of subprograms, not on their spatial relationship with each other.Thus the scope can be determined only at run time.
h) Block
Block is a method of creating static scopes inside program unit. Block is a section of code that have its own local variables whose scope is minimized. Such variables are typically stack dynamic, so they have their storage allocated when the section is entered and deallocated when the section is exited.
Part 2
a) What are the design issues for names?
The primary design issues for names are the following:
· What is the maximum length of a name?
· Can connector characters be used in names?
· Are names case sensitive?
· Are the special words reserved words or keywords?
Length
o If too short, they cannot be connotative
o Language examples:
§ FORTRAN I: maximum 6
§ COBOL: maximum 30
§ FORTRAN 90 and ANSI C: maximum 31
§ Ada and Java: no limit, and all are significant
§ C++: no limit, but implementors often impose one
Connectors
o Pascal, Modula-2, and FORTRAN 77 don't allow
o Others do
Case sensitivity
o Disadvantage: readability (names that lookalike are different)
§ worse in C++ and Java because predefined names are mixed case (e.g. IndexOutOfBoundsException)
o C, C++, and Java names are case sensitive
o The names in other languages are not
Special words
o An aid to readability; used to delimit or separate statement clauses
b) In what ways are reserved words better than key words?
A keyword is a word of a programming language that is a special only in certain context. A reserved word is a special word of a programming language that cannot be used as a name. As a language design choice, reserved words are better than keyword because the ability to redefine keywords can lead to readability problems.
For example in FORTRAN whose special words are keywords:
Integer Real
Real Integer
which declare the program variable Real to be a type of Integer type and the variable integer to be of real type.
c) What are the advantages & disadvantages of implicit declarations?
An implicit declaration is a means of associating variables with types through default convention instead of declaration statement. In this case, the first appearance of a variable name in a program constitutes its implicit declaration.
The advantage of implicit declaration is its writability because of its default mechanism while the disadvantage is its reliability because it prevents the compilation process from detecting some typographical and programmer errors.
If you enjoyed this post Subscribe to our feed