Names, Bindings, Types and Scope PowerPoint PPT Presentation

presentation player overlay
1 / 15
About This Presentation
Transcript and Presenter's Notes

Title: Names, Bindings, Types and Scope


1
Names, Bindings, Types and Scope
  • Juan Carlos Guzmán
  • CS 3123 Programming Languages Concepts
  • Southern Polytechnic State University

2
What is a Variable
  • A memory location?
  • An object?
  • Sebesta gives them six characteristics name,
    address, value, type, lifetime, scope
  • I do not agree, but . these are the features
    that we will first study in this course.

3
Constants
  • These do have the following properties
  • value
  • type
  • lifetime
  • They are usually called values

4
What is a Name
  • An identifier -- its a way to refer to an object
  • To which object a name refers?
  • Address
  • Aliases
  • When is the name valid?

5
Is a variable a constant?
  • No, a variable is a name
  • A constant is a computational object
  • They are related, but they are not the same!
  • You can name virtually any object, but there are
    restrictions.

6
Binding Time
  • Binding an association between an attribute and
    its entity
  • Binding Time when does it happen?
  • and, When can it happen?

7
When it can happen!
  • Static
  • Language design time
  • Language implementation time
  • Program Writing time
  • Compile Time
  • Link Time
  • Load Time
  • Dynamic
  • Run Time
  • At the start of execution (program)
  • When the function is called
  • When the expression is evaluated
  • When the data is accessed

8
Trade offs
  • The earlier the binding time, the more
    information the compiler has about the attribute
  • The later the binding time, the more flexible the
    entity may be
  • Ex. arrays

9
What do we bind?
  • What is the entity?
  • What is the attribute?

10
Types
  • static
  • type checking (implicit and explicit types)
  • type inference
  • strong typing
  • dynamic
  • type is bound at assignment
  • more flexible
  • more prone to errors

11
Lifetime
  • How long will last the object that I just
    created?

12
Storage
  • for how long do I need space?
  • static the space is available in the whole
    program
  • stack-allocation allocate on function call,
    deallocate on function return
  • heap-allocation
  • malloc, new
  • implicit
  • Garbage Collection

13
Scope
  • The region of the program in which a binding is
    active is its scope
  • Name scope
  • lexical scope (static)
  • dynamic scope

14
Name Scope
  • Information Hiding
  • procedures
  • modules
  • objects
  • overloading
  • separate compilation

15
Static vs. Dynamic Scope
  • Under lexical scope, sub1 will always reference
    the x defined in big
  • Under dynamic scope, the x it references depends
    on the dynamic state of execution
  • procedure big
  • var x integer
  • procedure sub1
  • begin sub1
  • ... x ...
  • end sub1
  • procedure sub2
  • var x integer
  • begin sub2
  • ...
  • sub1
  • ...
  • end sub2

begin big ... sub1 sub2
... end big
Write a Comment
User Comments (0)
About PowerShow.com