Wednesday, September 1, 2010

Blinding On Programming Languages

The blinding of a variable is the assignment to its attributes: names, addres, type, and value. In order to properly understand the semantics of a language, one should know the binding time of the attributes, whether it is associated at compile, load, or run time. The program source code is converted into machine code at compile time. At load time the relocatable machine code addresses are assigned to real addresses. Associations that occur during execution are said to occur at run time.

A static binding is one that occurs prior to run time and remains fixed troughtout execution. A dynamic binding is one that normally occurs or can change during run time.


1. Name Binding


Name binding generally occurs at compile time. If the language requires that variables be declared, binding can occur when the compiler sees the variable declaration.

2. Address Binding and Lifetime

As we will se later in this section when activation records are discussed, the address binding of global variables occurs at load time and is transparent to the user. Variables local to a procedure are commonly allocated space on the run-timr stack, hence addresses are boun at the time of activation during run time. Since variables provode an abstract notion of memory locations, ther is ni need to know the absolute address. While this is a bit more complicates in a virtual memory machine, this is still consistent with the user's view.
It is commonly found that a language may permit two identifiers to be bound to the same address. Consider in Pascal, for example, a procedure with a formal parameter which a var parameter. When the procedure is called, the formal parameter is then associated with the same address as the corresponding actual parameter.

To compilcate things further, it is also possible for the same name to be bound to different addresses. Suppose a program has a global variable called i. A procedure may also declare i as a local variable. Despite the duplicate name, these are clearly declared as two different variables. In the case of a recursive procedure, however, a local variable is likely to be associated with a different address each time the procedure is called.

Data objects can be created and destroyed during execution. When we call a Pascal procedure, the formal parameters and local variables are allocated when the procedure is called and are deallocated when it completes. The period of time that the object is bound to an address is called its lifetime.

3. Value Binding

Value binding of variables generally occurs at run time, since values may change while executing an assignment or read statement, for example. Not that, as we saw in section 1.1, the actual storage required for a value may be different for different primitive types. In this sense, value is something of an abstraction of memory cell: storage fot an item, independent of what actual storage is needed.
If the language supports initialized variables, such as the following Ada-like notation:

 var sum: integer :=0;

then the binding is still dynamic because the value can change. Constants may be handled differently if we have a syntax as simple a Pascal, so it may be possible to bind these at compile time. This is not always so with Ada constants, however, as some type issues may delay binding until run time.

4. Type Binding


Type binding is static in languages that require declaration of variables. Languages like Pascal, C, and Ada require explicit declarations. BASIC and FORTRAN, however, have some implicit typing. BASIC variable names like A are real A% is integer, A$ is string. FORTRAN variables starting with I through N default to integer type, while others default to real.

APL, SNOBOL4, and SETL2 are among the languages that support dynamic type binding. In SETL2, for example, a program may contain statements like:
   val := {1, 3, "hello", 6};


 val := 7;

While initially containing a set, val is later bound to the integer 7. The type must then be bound when the value is bound-at run time.

No comments:

Post a Comment