Names, Scopes, and Bindings Flashcards
Covers Names, Scopes, and Bindings
Define Names
Mnemonic string used to represent something else; Sort of like tokens. Allows us to refer to variables, types, operations, etc… rather than low-level concepts like addresses.
Define Binding
Association between 2 things; a name and the thing it names.
What is Binding Time?
The point at which binding is created. Or, more generally, the point at which any implementation decision is made.
What is a regular expression?
Formal notation for the lexical structure to ensure clear rules.
What is the scope of the Binding?
The part of the program (textually) in which the binding is active.
Some things are defined during language design time. Name a few.
- Program structure
- Primitive types
- Constructors
Name some items that can be defined during the language implementation time.
- I/O
- Number of bits in primitive types
- How overflow is handled
- Organization of maximum size of stack and heap
What are some pros/cons defining more at language design time than implementation time.
- Portability
- Disallows architecture specific optimization
What are some pros/cons of binding in early stages VS later stages
- Greater efficiency
- Less flexibility
(T/F) The compiler is written during the programming language design time.
False. The compiler is written during the implementation phase.
At what point can programmers modify the programming language?
During the language implementation time.
What things are determined during program writing time?
- Algorithms
- Names
- Data Structures
What things are determined during link time?
- Layout of the whole program in memory
What is determined during load time?
- Choice of physical addresses
What things are determined during compile time?
The layout of statically defined data in memory
What things are determined during run time?
- Variable values
- Sizes of strings
- Start-up time
What is Static Binding?
Binding that happens before run time.
What is Dynamic Binding?
Binding that occurs during run time.
Compilers VS Interpreters: Which has early binding time?
Compilers
Name the 7 language times or phases that binding depends on.
- Design time
- Implementation time
- Program writing time
- Compile time
- Link time
- Load time
- Run time
Define Bindings Lifetime
The period of time between the creation and the destruction of a name-to-object binding.
Define Object Lifetime
The time between the creation and destruction of an object.
Name key events during an objects lifetime
- Creation of object
- Creation of bindings
- How objects are referenced using the bindings
- Temporary deactivation of binding
- Reactivation
- Destruction of both bindings and objects.
When does a dangling reference occur?
When a binding outlives the object.
What is the scope of a binding?
The region of the program in which the binding is active.
When does an object become garbage?
This happens when an object outlives its binding.
Depending on the lifetime of an object, what are the 3 ways to store them?
- Static
- Stack
- Heap
What happens to objects during Static storage allocation?
Objects are given an address that is maintained through the life of the program.
What happens to memory during Stack storage allocation.
Memory allocated in last-in, first-our order, usually in conjunction with subroutine calls and returns.
Describe Heap storage allocation
A region of storage in which sub-blocks can be allocated and deallocated at arbitrary times.
What are some examples of statically allocated memory?
- Global defines
- Code Language translation to machine
- Static variables
- Explicit constants
- Tables used for debugging
Give an example of when static allocation can be used for the whole program.
Static allocation can be used when a language does not support recursion.
List the objects and information commonly found in a stack frame.
- Arguments
- Return address
- Misc bookkeeping
- Local variables
- Temporaries
What is stack allocation typically used for?
- Parameters
- Local Variables
- Temporaries (intermediate values of expressions)
Why use a stack? Give three reasons.
- Allocate space for recursive routines
- Reuse space
- Space for active routines is less than space for all routines (like static allocation)
Stacks use two pointers to keep track of subroutine calls. What are they?
- SP - Stack Pointer
- FP - Frame Pointer
In a stack, what does the stack pointer point to?
First unused location of the stack. Top of the stack.
In a stack, what does the frame pointer point to?
Close to the return address of the subroutine.
In heap allocation, what is internal fragmentation?
This occurs when storage management allocates a block that is larger than required to hold a given object.