CS374: Programming Language Principles - Binding and Scope

Activity Goals

The goals of this activity are:
  1. To define the various ways that names can be bound to items such as variables
  2. To explain interpreter or compiler binding of types
  3. To differentiate between strongly and weakly typed languages
  4. To define variable scope
  5. To relate scope to a function call stack

The Activity


Consider the activity models and answer the questions provided. First reflect on these questions on your own briefly, before discussing and comparing your thoughts with your group. Appoint one member of your group to discuss your findings with the class, and the rest of the group should help that member prepare their response. Answer each question individually from the activity, and compare with your group to prepare for our whole-class discussion. After class, think about the questions in the reflective prompt and respond to those individually in your notebook. Report out on areas of disagreement or items for which you and your group identified alternative approaches. Write down and report out questions you encountered along the way for group discussion.

Model 1: Binding


  1. Can foo be re-assigned at runtime? Would you say that it is statically or dynamically bound to its value? How about x?
  2. Do you think this is true of every language?
  3. What do you suppose is the difference between lexical scope and dynamic scope?
  4. How many bindings are there of the identifier x? If x is staically bound, it must be resolved by the compiler at compile time. How is the correct value obtained at each reference?
  5. What would happen if x is re-declared in foo after it has already been declared in languages like C and Java that specify and insist on proper types (these are called strongly typed languages)?

Model 2: Tracking Bindings


  1. What kinds of information are needed to specify a bound symbol?
  2. What kind of data structure would enable a dynamic number of bound variables in a routine?
  3. What revisions are needed to support additional data types?
  4. What revisions are needed to support scope, so that variables of the same name can exist in subroutines?

Model 3: Binding Functions


  1. How can polymorphism work in a statically bound language? How might this differ from a dynamically bound language?

Model 4: Virtual Inheritance


  1. A call to x->Eat(), where x is of type Animal but refers to a Llama, would output what?
  2. How would this differ if Eat was not virtual, and implemented in the class Animal?


I encourage you to submit your answers to the questions (and ask your own questions!) using the Class Activity Questions discussion board. You may also respond to questions or comments made by others, or ask follow-up questions there. Answer any reflective prompt questions in the Reflective Journal section of your OneNote Classroom personal section. You can find the link to the class notebook on the syllabus.