Presentation is loading. Please wait.

Presentation is loading. Please wait.

Names and Bindings Introduction Names Variables The concept of binding Chapter 5-a.

Similar presentations


Presentation on theme: "Names and Bindings Introduction Names Variables The concept of binding Chapter 5-a."— Presentation transcript:

1 Names and Bindings Introduction Names Variables The concept of binding Chapter 5-a

2 Introduction Imperative language is based on Von Neumann architecture, which consists of two important components – Cpu and memory. 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.

3 Names An identifier (or name) is used to identify the entities, e.g., variables Subprogram names, userdefined names, labels, Class name., in a programming language. Design Issues  The length of an identifier ( name )  Connection character  Case sensitivity  Reserved words or keywords?

4 Names 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.

5 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.

6 Attributes Variables A variable has the following properties, name, address, value, type, lifetime, and scope.  Name Variable Names are the most common names in programes. Names are often referred as identifiers.  Address The memory address with which it is associated. The same name may refer to different addresses at different time. If two variable names can be used to access the same memory location, they are called aliases.

7 Variables  Type The type of a variable defines the class of values that can be stored in a variable.  Value The actual value stored in a variable. Also called r-value.

8 Binding A binding is an association, such as between an attribute and an entity The binding can happen at various times.  Language design  Language implementation  Compilation  Linking  Loading  Execution Binding of Attributes to Variables  Static binding is at compile time, and dynamic binding at runtime.

9 Type Binding Static Type Binding  If type binding is static, a type may be specified with either an  explicit declaration—a program statement used for declaring the type of a variable.  implicit declaration—a default mechanism for specifying the type (typically the first appearance of the variable in the program).

10 Type Binding Dynamic Type Binding Specified through an assignment statement. Advantage: flexibility, easy writing - Disadvantages:  High cost (dynamic type checking and interpretation)  Type error detection by the compiler is difficult

11 Storage Binding and Lifetime Allocation binds storage and variable, deallocation remove this binding. The lifetime of a variable is from it is allocated memory till the memory is deallocated. Static Variables  Static variables are bound to memory cells before execution begins and remains bound to the same memory cell throughout execution.  Advantage: efficiency, history-sensitive.  Disadvantage: lack of flexibility.

12 Storage Binding and Lifetime Stack-dynamic Variables  Stack-dynamic: Storage bindings are created for variables when their declaration statements are elaborated.  Advantages: Allows recursion; conserves storage.  Disadvantages: - Overhead of allocation and deallocation - Subprograms cannot be history sensitive - Inefficient references (indirect addressing)

13 Storage Binding and Lifetime You can think of the heap as a bank of memory, much like a financial bank that maintains a reserve of money. A program can borrow (allocate) memory from the heap when additional storage space is required and then pay it back (deallocate) when it is no longer needed. Explicit Heap-Dynamic variables are nameless memory cells that are allocated and deallocated by explicit run-time instructions specified by the programmer. Implicit Heap-Dynamic variables are bound to heap storage only when they are assigned values.


Download ppt "Names and Bindings Introduction Names Variables The concept of binding Chapter 5-a."

Similar presentations


Ads by Google