CHAPTER 4

NAMES, BINDING, TYPE CHECKING, AND SCOPES

 

Imperative programming languages are abstractions of the von Neumann Computer architecture.  The architecture’s two primary components are its memory and its processor.  The abstractions in a language for the memory cells of the machine are variables. 

 

·        A variable can be characterized by a collection of properties, or attributes, the most important of which is type, a fundamental concept in programming languages.

 

Design Issues:

·        What is the max. length of a name?

·        Can connector characters be used in names?

·        Are names case sensitive?

·        Are the special words reserved words or keywords?

 

Name Forms:

·        A name is a string of characters used to identify some entity in a program.

·        The commonly acceptable name form is a string with a long length limit, if any, with some connector character such as the underscore (_) included.

·        In some languages, like C, C++, and Java, uppercase and lowercase letters in names are distinct, that is names in these languages are case sensitive.

 

Special Words:

·        Special words in programming languages are used to make programs more readable by naming actions to be performed.  They also are used to separate the syntactic entities of programs.

·        Keyword is a word of programming languages that is special only in certain context

·        Reserved word is a special word of a programming language that cannot be used as a name.

 

Variables

·        A program variable is an abstraction of a computer memory cell or collection of cells.

·        A variable can be characterized as a sextuple of attributes:

            (name, address, value, type, lifetime, scope)

 

NAME

·        Variable names are he most common names in programs

·        Names are often referred as identifiers.

 

ADDRESS

·        The address of a variable is the memory address with which it is associated.

·        In many languages, it is possible for the same name to be associated with different addresses at different places and at different times in the program.

·        It is possible to have multiple identifiers reference the same address

·        When more than one variable name can be used to access a single memory location, the names are called aliases.

·        Aliasing makes program verification more difficult

·        Two pointer variables are aliases when they point to the same memory location.  The same is true for reference variables

·        Aliasing can be created in many languages through subprogram parameters

 

TYPE

·        The type of a variable determines the range of values the variable can have and the set of operations that are defined for values of the type

 

Value

·        The value of the variable is the contents of the memory cell or cells associated with the variable

·        When we use the term memory cell we mean abstract memory cell

 

THE CONCEPT OF BINDING

 

BINDING OF ATTRIBUTES TO VARIABLES

 

TYPE BINDINGS

VARIABLE DECLARATION:

 

   DYNAMIC TYPE BINDING

 

STORAGE BINDING AND ALLOCATION

 

TYPE CHECKING

 

STRONG TYPING

 

TYPE COMPATIBILITY

 

SCOPE

 

STATIC SCOPE

 

BLOCKS

 

EVALUATIOIN OF STATIC SCOPING

·        It is convenient to view the structure of program as a tree in which each node represents a procedure and thus a scope.

 

DYNAMIC SCOPE

 

EVALUATION OF DYNAMIC SCOPING

Several problems come from dynamic scoping:

 

The referencing environment of a statement is the collection of all names that are visible in the statement.

A named constant is a variable that is bound to a value only at the time it is bound to storage; its value cannot be changed by assignment or by an input statement.