Programming Languages Lecture 5 - Names, Binding and Scopes

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/56

encourage image

There are no tags or description

Looks like no tags are added yet.

57 Terms

1
New cards

Imperative Languages

Abstractions of the von Neumann architecture, in that there is the memory and the processor.

2
New cards

Variable Types are Charactized By…

Must consider scope, lifetime, type checking, initialization, and type compatibility.

3
New cards

Design Issues for Names

Are names case sensitive and are special words reserved or keywords?

4
New cards

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

5
New cards

Special Characters

PHP: $
Perl: @, #, specifies value’s type

Ruby: @ are instance variables, @@ class variables

6
New cards

Case Sensitivity

Readability, where names look alike are different. C-based languages have this where others do not.

7
New cards

Special Words

Aid to readability that is used to delimit or separate statement clauses.

8
New cards

Keyword

Word that is special only in certain contexts.

9
New cards

Reserved Word

Special word that cannot be used as a user-defined name. If there are too many, collisions occur.

10
New cards

Variables

Abstraction of a memory cell that is characterized by name, address, value, type, lifetime and scope.

11
New cards

Name Attribute

Not all variables have them.

12
New cards

Address

Memory address with which a variable is associated, which may be different at different times and places.

13
New cards

Alias

When two variable names access the same memory location, such as pointers, reference variables. Harmful to readability.

14
New cards

Type

Determines the range of values of variables and the set operations defined for values of that type. Defines its size!

15
New cards

Value

Contents of the location with which the variable is associated.

16
New cards

L-Value

Variable’s address. X= 10, X is the L-value.

17
New cards

R-Value

Variable’s value. Y = x, x is the R-value. We only care about true value for calculation and printing.

18
New cards

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

19
New cards

Abstract Memory Cell

Physical cell or collection of cells associated with a variable.

20
New cards

Binding

Association between an entity and attribute, such as between a variable and its type.

21
New cards

Binding Time

Time at which a binding takes place.

22
New cards

Language Decision Time

Bind operating symbols to operations.

23
New cards

Language Implementation Time

Bind floating point to a representation.

24
New cards

Compile Time

Bind a variable to a type in C or Java.

25
New cards

Load Time

Bind a C or C++ static variable to memory cell.

26
New cards

Runtime

Bind a nonstatic local variable to a memory cell, dynamic.

27
New cards

Timeline

  1. Language design - what does the operator + mean?

  2. 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 )

  3. 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 )

  4. Load time - allocating space and time for the code, the static variables, etc

  5. Runtime - anything else 


28
New cards

Static and Dynamic Binding

Static first occurs before runtime and remains unchanged, dynamic first occurs during execution or can change during execution,

29
New cards

Type Binding

If static, the type may be specified by either an explicit or an implicit declaration.

30
New cards

Explicit Declaration

Program statements used for declarating the types of variables.

31
New cards

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.

32
New cards

Dynamic Type Binding

Specified through an assignment statement for the advantage of flexibility and the drawback of high cost and difficult type error detection.

33
New cards

Allocation

Getting a cell from some pool of available cells.

34
New cards

Deallocation

Putting a cell back into the pool.

35
New cards

Variable Lifetime

Time during which it is bound to a particular memory cell.

36
New cards

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.

37
New cards

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.

38
New cards

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.

39
New cards

Implicit Heap Dynamic

Allocation/deallocation caused by assignment statements, which allow flexibility but are inefficient and loses error detection.

40
New cards

Scope

Range of statements over which it is visible. Scope rules of a language determine how references to names are associated with variables.

41
New cards

Local Variables

Those declared inside that unit.

42
New cards

Nonlocal Variables

Those visible in the unit but not declared there.

43
New cards

Global Variables

Special category of nonlocal.

44
New cards
45
New cards

Static Scope

Based on program text, connecting a name reference to a variable, then you must find the declaration.

46
New cards

Search Compiler Process

Search declarations, first locally, then increasingly larger, until one is found with the given name.

47
New cards

Static Ancestors

Enclosing static scopes to a specific scope, where the nearest ancestor is a static parent.

48
New cards

Hidden Variables

When a closer variable with the same name is in the unit.

49
New cards

Let Construct

First part binds names to values, second uses names defined in the first part.

50
New cards

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.

51
New cards

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.

52
New cards

Dynamic Scope Evaluation

Convenient, but variables are visible to all subprograms it calls, impossible to static type check, and poor readability.

53
New cards

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.

54
New cards

Active Subprogram

Execution has begun and not yet terminated.

55
New cards

Named Constants

Variable bound to a value only when bound to storage. Allows for better readability and modifiability, and used to parameterize programs.

56
New cards

Manifest Constants

Binding of values to named constants done statically.

57
New cards

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.