PL Test 2 Ch 5, 6 PL Test 2 Ch 5

Question Answer
variable: set of attributes name, address, datatype, value, lifetime, scope
variables an abstraction of a memory cell
variable design issues length, special characters, case sensitivity, special words,
keyword a word that is special only in certain contexts
reserved word a special word that cannot be used as a user-define name
variable name not all variables have them
variable address the memory address with which it is associated
aliasing two variables point to the same address (harmful to readability)
variable type determines the range of values of variables and the t of operations that are defined for values of that type
variable value the contents of the location with which the variable is associated
l-value of a variable its address — can be variable, array index A[i], pointer
r-value of a variable its value
binding an association between an entity and an attribute, such as between a variable and its type or value, or between an operation and a symbol
binding time time when binding(association) takes place
Possible binding times language design time, language implementation time, compile time, load time, run time
static binding the binding first occurs before run time and remains unchanged throughout program execution
dynamic binding the binding is dynamic if it first occurs during execution or can change during execution of the program
explicit declaration is a program statement used for declaring the types of variables
implicit declaration a default mechanism for specifying types of variables through default conventions, rather than declaration statements
type inferencing used to determine types of variables (context) C# var
Dynamic type binding (python) flexible but high cost and type error detection is difficult
allocation getting a cell from some pool of available cells
deallocation putting a cell back into the pool
lifetime of a variable the time during which it is bound to a particular memory cell
static variables bound to memory cells before execution begins and remains bound to the same memory cell throughout execution — efficient but lacks flexibility
Stack-dynamic storage bindings are created for variables when their declaration statements are elaborated (executable code associated with it is executed) — allows recursion but overhead and subprograms cannot be history sensitive and inefficient references
explicit heap – dynamic allocated and de-allocated by explicit directives, specified by the programmer, which take effect during executions (new and delete) — provides dynamic storage management but inefficient and unreliable
implicit heap – dynamic allocation and deallocation caused by assignment statements — flexible but inefficient and has a loss of error detection
scope of a variable range of statements over which it is visible
local variables variables that are declared in that program unit
non-local variables variables that are visible in the unit but not declared in that program unit
global variables a special category of non-local variables
scope rules determine how references to names are associated with variables
static/lexical scope scope can be determined by simple examination of the code
dynamic scoping scope depends on the function calling sequence
referencing environment of a statement collection of all names that are visible in the statement
static-scoped language referencing environment it is the local variables plus all of the visible variables in all of the enclosing scopes
active subprogram if execution has begun but has not yet terminated
dynamic-scoped language referencing environment the referencing environment is the local variables plus all visible variables in all active subprograms
named constant a variable that is bound to a value only when it is bound to storage — used to parametermize programs — (readonly, const)
data type a collection of data objects and a set of predefined operations on those objects
descriptor the collection of the attributes of a variable
object represents an instance of a user-defined (abstract data) type
primative data types Those not defined in terms of other data types — integer, floating point, complex, boolean, character, enums, pointers/references
aggregate array, struct/class, dict/map, set, list
scalar values can be ordered — numeric, booleans, characters, pointers
ordinal type range of possible vales can be easily associated with the set of positive integers (each value has a unique predecessor and successor)
enumeration types all possible values, which are named constants are provided in the definition
array a homogeneous aggregate of data elements in which an individual element is identified by its position in the aggregate, relative to the first element
array indexing (sub-scripting) a mapping from indices to elements
heterogeneous array array in which the elements need not be of the same type
slice some substructure of an array; nothing more than a referencing mechanism
accessing multi-demensioned arrays Row major order (by rows) – used in most languagesColumn major order (by columns) – used in Fortran
associative array an unordered collection of data elements that are indexed by an equal number of values called keys
record a possibly heterogeneous aggregate of data elements in which the individual elements are identified by names
tuple a data type that is similar to a record, except that the elements are not named
union a type whose variables are allowed to store different type values at different times during execution
pointer variable has a range of values that consists of memory addresses and a special value, nil Two fundamental operations: assignment and dereferencing
pointer/reference issues aliasing, deallocation, dangling pointers, lost object
dangling pointer A pointer points to a heap-dynamic variable that has been deallocated
lost object (memory leak) when you don't have a pointer that points to a piece of memory — An allocated heap-dynamic variable that is no longer accessible to the user program
pointer/reference issues solution garbage collection — expensive and need to be careful with real-time applications
dangling pointer solutions tombstones extra heap cell that is a pointer to the heap-dynamic variable — tombstone is set to null upon deallocation, tombstones are never deleted, slower access times
dangling pointer solutions lock and key Pointer values are represented as (key, address) pairs– lock is set to special "illegal" value upon deallocation, slower access time (SEE NOTES)
reference counters maintain a counter in every cell that store the number of pointers currently pointing at the cell
Mark-Sweep The run-time system allocates storage cells as requested and disconnects pointers from cells as necessary; mark-sweep then begins
Type checking is the activity of ensuring that the operands of an operator are of compatible types
compatible type one that is either legal for the operator, or is allowed under language rules to be implicitly converted, by compiler- generated code, to a legal type
type error the application of an operator to an operand of an inappropriate type
Advantage of strong typing allows the detection of the misuses of variables that result in type errors
Name type equivalence means the two variables have equivalent types if they are in either the same declaration or in declarations that use the same type name
Structure type equivalence means that two variables have equivalent types if their types have identical structures

Leave a Reply

Your email address will not be published. Required fields are marked *