Title: Names and Binding
1Names and Binding
2vonNeumann Architecture
- memory where data and instructions are
stored - processor where computations are
carried out
3Variables
Variables are abstractions for memory cells in
the computer. Programmers think of variables as
names for memory locations.
4Variables
Variables can be characterized by a number of
attributes including
- name
- name
- address
- value
- type
- lifetime
- scope
5Variables Names
Names are associated with variables, but also
with labels, subprograms, and formal parameters
6Variables Names
Design Issues
- maximum name length
- special or connector characters
- case sensitivity
- are the special words treated as reserved
words or keywords?
7Variables Names
Reserved word - a special word of a
programming language that cannot be used as
a name Keyword - a word that has special
meanings in certain contexts Predefined
name - have predefined meanings but can be
redefined by the user
8Variables
Variables can be characterized by a number of
attributes including
- name
- address
- address
- value
- type
- lifetime
- scope
9Variables Address
Address - the memory address with which a
variable is associated, also called
its l-value
Example x number 2
10Variables Address
Issues of complexity with the concept of
addresses
Same name, different address - example local
variables in different
functions
Same address, different name (alias) examples
variant records, unions, pointers, global
variables, equivalence statements
11Variables
Variables can be characterized by a number of
attributes including
- name
- address
- value
- value
- type
- lifetime
- scope
12Variables Value
The value of a variable is the contents of the
memory cell or cells associated with the
variable. Also referred to as the r-value
Example x number 2
13Variables
Variables can be characterized by a number of
attributes including
- name
- address
- value
- type
- type
- lifetime
- scope
14Variables Type
Determines
1. The range of values which can be stored
in a variable 2. The operations which can
legally be performed on the variable
15Variables
Variables can be characterized by a number of
attributes including
- name
- address
- value
- type
- lifetime
- lifetime
- scope
16Variables Lifetime
The lifetime of a program variable is the time
during which that variable has a particular
memory cell associated with it.
The lifetime of a variable may begin
- at the start of program execution
- when a function is called (local variables)
- when the variable is created dynamically
during program execution (new, malloc)
17Variables
Variables can be characterized by a number of
attributes including
- name
- address
- value
- type
- lifetime
- scope
- scope
18Variables Scope
The range of statements in which the variable is
visible The scope rules of a language determine
how a particular occurrence of a name is
associated with a variable
19Binding
20The Concept of Binding
A binding is the association of an entity with an
attribute or of a symbol with an operation. A
binding establishes the choice of a property from
a set of properties The time at which a binding
takes place is called binding time.
21 Binding Times
Binding can take place at
- language design time
- language implementation time
- compile time
- link time
- load time
- run time
22 Binding Times
X X 10
- set of allowable types for X (language design
time)
- set of possible values for X (language
implementation time)
- type of X (compile/translation time)
- value for X (run-time)
- physical address for X (load time)
23 Binding of Attributes to Variables
Static binding - occurs before run time and
remains unchanged throughout the
program Dynamic binding - occurs during run
time or can change during the course of
program execution
24 Type Binding
Type declarations - implicit and
explicit Dynamic type binding - the type of a
variable is bound when it is assigned a value in
an assignment statement
25 Storage Bindings and Lifetime
Static variables
Stack dynamic variables
Explicit heap-dynamic variables
Implicit heap-dynamic variables
26 Storage Bindings and Lifetime
Static variables
- bound to memory locations before
- program execution begins
- remain so until program execution ends.
Efficiency History sensitive subprogram
variables - Reduced flexibility
Examples all variables in Fortran IV
static variables in C, C, Java
27 Storage Bindings and Lifetime
Stack dynamic variables
- bound to memory locations when their
- declaration statements are elaborated
Enables recursion Shared storage space -
Run-time overhead for memory
allocation/deallocation
Examples subprogram variables in Fortran 77
90, Pascal, C, C
28 Storage Bindings and Lifetime
Explicit heap-dynamic variables
- bound to memory locations at run-time
- when specified by the programmer
- in some languages, deallocation is
- specified by the programmer
Enables structures to grow or shrink -
Difficulty of correct memory management -
Run-time overhead for memory access,
allocation, and deallocation
Examples new in Java, C
malloc in C
29 Storage Bindings and Lifetime
Implicit heap-dynamic variables
- bound to memory locations when they
- are assigned values
Flexibilty, generic code development - Loss of
ability to detect type errors - Run-time
overhead for maintaining dynamic attributes
Examples variables in many interpretive
environments flex arrays in
ALGOL 68