Names and Binding von Neumann Architecture memory where
Names and Binding
von. Neumann Architecture - memory where data and instructions are stored - processor where computations are carried out
Variables are abstractions for memory cells in the computer. Programmers think of variables as names for memory locations.
Variables can be characterized by a number of attributes including: - name - address - value - type - lifetime - scope
Variables: Names are associated with variables, but also with labels, subprograms, and formal parameters
Variables: Names Design Issues: - maximum name length - special or connector characters - case sensitivity - are the special words treated as reserved words or keywords?
Variables: 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
Variables can be characterized by a number of attributes including: - name - address - value - type - lifetime - scope
Variables: Address - the memory address with which a variable is associated, also called its l-value Example: x = number * 2;
Variables: 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
Variables can be characterized by a number of attributes including: - name - address - value - type - lifetime - scope
Variables: 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;
Variables can be characterized by a number of attributes including: - name - address - value - type - lifetime - scope
Variables: 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
Variables can be characterized by a number of attributes including: - name - address - value - type - lifetime - scope
Variables: 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)
Variables can be characterized by a number of attributes including: - name - address - value - type - lifetime - scope
Variables: 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
Binding
The 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.
Binding Times Binding can take place at • language design time • language implementation time • compile time • link time • load time • run time
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)
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
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
Storage Bindings and Lifetime Static variables Stack dynamic variables Explicit heap-dynamic variables Implicit heap-dynamic variables
Storage Bindings and Lifetime Static variables: • bound to memory locations before program execution begins • remain so until program execution ends. + Efficiencyall variables in Fortran IV Examples: + History sensitive subprogram variables static variables in C, C++, Java - Reduced flexibility
Storage Bindings and Lifetime Stack dynamic variables : • bound to memory locations when their declaration statements are elaborated + Enables recursion Examples: subprogram variables in + Shared space C, C++ Fortran 77 storage & 90, Pascal, - Run-time overhead for memory allocation/deallocation
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 Examples: new in Java, C++ or shrink - Difficulty of correctinmemory management malloc C - Run-time overhead for memory access, allocation, and deallocation
Storage Bindings and Lifetime Implicit heap-dynamic variables : • bound to memory locations when they are assigned values + Flexibilty, generic code development Examples: variables in many - Loss of ability to detect type errors interpretive environments - Run-time flex overhead for maintaining arrays in ALGOL 68 dynamic attributes
- Slides: 29