Names and Scoping Flashcards
What is a name in the context of FMAL?
Identifiers for objects existing during the execution of a program
What is Environment?
The set of associations between names and denotable objects which exist at runtime at a specific program point and specific time during the execution
What is a block?
A textual region identified by some start and end signs, which can contain declarations local to that region.
Can be nested
Can be associated with a procedure(procedure bodies) and in-line blocks
Describe local, non-local and global associations of the environment
Local: associations of the current block
non-local: Those of the encompassing blocks
global: Those of the outermost block
A declaration in a block is visible in the block and all nested blocks unless there is a new declaration of the name in a nested block
There are five operations possible on associations with names in the environment
- Create an association when entering a block declaring the name
- Dereference (access the denotable object by name) inside this block
- Deactivate an association when entering a block where a new association for the name is created locally
- Reactivate an association when leaving this block
- Destroy an association when leaving the block declaring the name
There are four operations possible on denotable objects
- Create
- Access
- Modify
- Destroy
note: The lifetime of a denotable object can be longer than that of an associated name.
Describe static scope
The valid association for a name x at a point p of a program is the nearest association created for x by a declaration in the block where p belongs or an enclosing block. REMEMBER point p MOVES to a function when the function is called!!!
Describe dynamic scope
The valid association for a name x at a point p of a program is the most recent association created for x that is active at the particular time that control reaches p.
Think… function replaces the call of the function.