Names and Scope
This outline covers chapter four, and mentions a few additional things. You are responsible for all of it.
  1. Legal names.
    1. Characters: Usually letters and numbers, starting with a letter.
    2. Others may be allowed
      1. Underscore is common. COBOL allows a dash.
      2. Use may be limited.
        1. Not at the ends.
        2. Ada allows underscore, but not two in a row.
    3. Case-sensitivity.
    4. Special names
      1. Keywords (e.g. while): Otherwise legal identifiers.
      2. Predefined words (e.g. printf): May be redefined.
      3. Keyword-in-context.
        1. Words that can be identifiers or keywords, depending on placement.
        2. FORTRAN.
      4. Markers distinguish variables: $ in perl and php.
  2. Variables.
    1. Binding: Name, address, type and scope.
    2. l-value and r-value.
    3. Some languages make these uses explicit.
    4. References.
      1. Allows a variable to hold the l-value of another variable.
      2. May (C, C++, most compiled) or may not (Java, many scripting) require explicit deference.
  3. Scope.
    1. The collection of statements which can access that binding, without qualification.
    2. Usual delimiters: {, }, begin, end
    3. Static or dynamic.
      1. Static: determined by program layout.
      2. Dynamic: determined by call order. Obsolete.
    4. Disjoint or nested.
      Pascal Example
      Java Example
    5. Local and non-local references.
    6. Named scopes
      1. Scopes holding function bodies and control blocks are anonymous.
      2. Some types of scope are named.
        1. Classes. Contain data and operations defining a type, usually used to create an ADT.
        2. Modules.
          1. Contain and group type declarations and operations on those types.
          2. Is not a itself type.
        3. Name spaces. Contains any set of declarations, usually to contain a library.
        4. Terms are not fixed.
          1. Name spaces and modules differ mainly by intended use. They basically do the same thing.
          2. Modules usually have some form of access control, while name spaces usually do not.
          3. Java packages are modules under the above terminology.
          4. Ada has packages which are modules.
          5. Some scripting languages (Python in particular) treat a file as a name space, and call it a module.
      3. Allows qualified reference from outside.
      4. Modules class examples.
        1. Ada Integer Stack: Package Implementation Driver.
        2. Java Integer Stack: Class Driver.
        3. C++ Integer Stack: Class Implementation Driver.
      5. Forward reference.
        1. Usually, definition must precede reference.
        2. Java is an exception.
        3. Declaration before definition.
      6. Usually an implicit global scope, usually with some restrictions on what can go there.
    7. Resolving References.
      1. Start with current scope and work out through enclosing scopes.
      2. Names declared in a closer scope may hide outer ones of same name.
        1. Hidden name is invisible.
        2. Local declarations may hid parameters.
      3. Compiler keeps declarations in a symbol table.
        1. Usually a separate table for each scope.
        2. Nested scopes make a stack of tables.
    8. Overloading
      1. Giving multiple meanings to the same visible symbol.
      2. Most often functions or operators resolved by argument type.
        Usually not return type, except Ada.
      3. Allowing the user to create overloads is fairly new.
        1. Overloading function names.
        2. Overloading operators (C++ and some others).
    9. Lifetime: The interval during which the variable is allocated some storage.
      1. Typically determined by scope, but a declaration may override.
      2. Static: lifetime of the program.
        1. Global variables.
        2. Declared so, as static in C.
        3. C Static Declaration
      3. Local variables: lifetime of their defining scope.
        1. In a function: entry to exit of the enclosing block.
        2. In a class.
          1. Object (usual) variables: Lifetime of the object that contains them.
          2. Static (class) variables: Lifetime of the class itself.
            Often equals the lifetime of the program, but may not.
      4. Dynamic variables: from creation (new, malloc) to deletion (delete, free, gc cleanup).
    10. Closure
      1. Referencing environment: All the variables you can use.
        The sum of your scopes
      2. Closure: Executable code combined with a referencing environment to to run it in.
      3. Lisp lambda, passed function references in some languages.