1/56
Looks like no tags are added yet.
Imperative Languages
Abstractions of the von Neumann architecture, in that there is the memory and the processor.
Variable Types are Charactized By…
Must consider scope, lifetime, type checking, initialization, and type compatibility.
Design Issues for Names
Are names case sensitive and are special words reserved or keywords?
Name Length
If too short, they cannot be connotative.
C99: only recognizes first 63 characters, external names limited to 31.
C# and Java: no limit, all significant
C++: no limits, but implementers impose one
Special Characters
PHP: $
Perl: @, #, specifies value’s type
Ruby: @ are instance variables, @@ class variables
Case Sensitivity
Readability, where names look alike are different. C-based languages have this where others do not.
Special Words
Aid to readability that is used to delimit or separate statement clauses.
Keyword
Word that is special only in certain contexts.
Reserved Word
Special word that cannot be used as a user-defined name. If there are too many, collisions occur.
Variables
Abstraction of a memory cell that is characterized by name, address, value, type, lifetime and scope.
Name Attribute
Not all variables have them.
Address
Memory address with which a variable is associated, which may be different at different times and places.
Alias
When two variable names access the same memory location, such as pointers, reference variables. Harmful to readability.
Type
Determines the range of values of variables and the set operations defined for values of that type. Defines its size!
Value
Contents of the location with which the variable is associated.
L-Value
Variable’s address. X= 10, X is the L-value.
R-Value
Variable’s value. Y = x, x is the R-value. We only care about true value for calculation and printing.
L/R Value Examples
++++x is preincrement, and returns the L value
X++++ is postincrement, and returns the r value or the constant value
++x = 20 comes out as 20
Abstract Memory Cell
Physical cell or collection of cells associated with a variable.
Binding
Association between an entity and attribute, such as between a variable and its type.
Binding Time
Time at which a binding takes place.
Language Decision Time
Bind operating symbols to operations.
Language Implementation Time
Bind floating point to a representation.
Compile Time
Bind a variable to a type in C or Java.
Load Time
Bind a C or C++ static variable to memory cell.
Runtime
Bind a nonstatic local variable to a memory cell, dynamic.
Timeline
Language design - what does the operator + mean?
Language implementation - bind representations ( how big is an integer? How much heap space? How big is a float? Compiler designer makes these decisions when they write the compiler, but cannot override decisions of language design time )
Compile time - give a function name, variable a name, basically writing the code. Depending on the language, constants are bound here ( c calls it const, java calls it final )
Load time - allocating space and time for the code, the static variables, etc
Runtime - anything else
Static and Dynamic Binding
Static first occurs before runtime and remains unchanged, dynamic first occurs during execution or can change during execution,
Type Binding
If static, the type may be specified by either an explicit or an implicit declaration.
Explicit Declaration
Program statements used for declarating the types of variables.
Implicit Declaration
Default mechanism for specifying types of variables through default conventions, seen in Basic, Perl, Ruby, PHP with the trade off of writability at the cost of reliability.
Dynamic Type Binding
Specified through an assignment statement for the advantage of flexibility and the drawback of high cost and difficult type error detection.
Allocation
Getting a cell from some pool of available cells.
Deallocation
Putting a cell back into the pool.
Variable Lifetime
Time during which it is bound to a particular memory cell.
Static
Bound to memory cells before execution begins and remains bound to the same memory cell throughout execution for the pro of efficiency and history-sensitive subprogram support, but lack of flexibility in that no recursion.
Stack-Dynamic
Storage bindings are created for variables when their declaration statements are elaborated, meaning when the executable code is executed. If scalar, all attributes but address are statciclally bound.
Alllows recursion and conserves storage, but there is overhead of allocation/deallocation, subprograms are not history sensitive.
Explicit Heap Dynamic
Allocated/deallocated by explicit directives that are specified by the programmer and takes effect during executon, Referenced only in pointers and references.
Allows for dynamic storage but is inefficient and unreliable.
Implicit Heap Dynamic
Allocation/deallocation caused by assignment statements, which allow flexibility but are inefficient and loses error detection.
Scope
Range of statements over which it is visible. Scope rules of a language determine how references to names are associated with variables.
Local Variables
Those declared inside that unit.
Nonlocal Variables
Those visible in the unit but not declared there.
Global Variables
Special category of nonlocal.
Static Scope
Based on program text, connecting a name reference to a variable, then you must find the declaration.
Search Compiler Process
Search declarations, first locally, then increasingly larger, until one is found with the given name.
Static Ancestors
Enclosing static scopes to a specific scope, where the nearest ancestor is a static parent.
Hidden Variables
When a closer variable with the same name is in the unit.
Let Construct
First part binds names to values, second uses names defined in the first part.
Evaluation of Static Scoping
Works well in many situations, but in most cases, too much access is possible, and as a program evolves, the initial structure is destroyed and local variables often become global.
Dynamic Scope
Based on calling sequences of program units, not their textual layout. References to variables are connected to declarations by searching back through the chain of subprograms.
Dynamic Scope Evaluation
Convenient, but variables are visible to all subprograms it calls, impossible to static type check, and poor readability.
Referencing Environment
Statement is the collection of all names visible in the statement. In static scope, local variables plus all visible variables are in the enclosed scope. In dynamic, its the local variables plus all visible variables in active subprograms.
Active Subprogram
Execution has begun and not yet terminated.
Named Constants
Variable bound to a value only when bound to storage. Allows for better readability and modifiability, and used to parameterize programs.
Manifest Constants
Binding of values to named constants done statically.
Declaration order requirements in C++, Java, and C#
C++ requires names to be declared before they are used, so forward declarations or function prototypes are needed. Java and C# allow class members to be used before their declaration, but local variables must still be declared before use in all three languages.