Chapter 1
- 正交性
- 指只用该语言的一组相对少量的基本结构,经过相对少的结合步骤,就可构成该语言的控制结构和数据结构。而且,它的基本结构的任何组合都是合法和有意义的。
- 4 Language evaluation criteria:
- Writability, readability, reliability, cost.
- 4 Language categories:
- Imperative, functional, logic and object-oriented.
- Bottleneck for the speed of compilation:
- the speed of the connection between a computer’s memory and its processor.
- The major influences on language design have been “Machine architecture, software design methodologies”.
- The major methods of implementing programming languages are “compilation, pure interpretation, hybrid implementation”.
Chapter 2
-
In what year was Plankalkul designed?
-
-
In what year was that design published?
-
-
Why was the slowness of interpretation of programs acceptable in the early 1950s?
- Lack of floating point hardware .
-
What two important hardware features first appeared in the IBM 704 computers?
- Both indexing and floating-point instructions in hardware.
-
What was the primary application area of computers at the time FORTRAN was designed?
- Scientific.
-
What two professional organizations together designed ALGOL 60?
- ACM (美国计算机协会) and GAMM(应用数学与力学协会 德).
-
What missing language element of ALGOL 60 damaged its chances for wide-spread use?
- I/O and the character set.
-
What data structure appeared in COBOL that originated with Plankalkul?
- Record.
-
What user group was the target of the first version of BASIC?
- Non-science.
-
PL/I was designed to replace what two languages?
- FORTRAN and COBOL.
-
What features of SIMULA 67 are now important parts of some object-oriented languages?
- Class.
-
What Ada construct provides support for abstract data types?
- Package.
-
What three concepts are the basis for object-oriented programming?
- Data abstraction, inheritance, and dynamic type binding.
-
The first compiled high level language?
- FORTRAN
-
LIST has only 2 data types:
- atoms and lists, a pioneered functional programming
-
ALGOL 60 was the result of efforts to design a universal language, but was never widely used.
-
Reasons for the failure of ALGOL 60
-
Lack of I/O and the character set
-
too flexible to implement(pass by name)
-
FORTRAN
-
lack of support from IBM
-
-
First widely used language with time sharing
- BASIC
-
ALGOL 68 's design is based on the concept of orthogonality.
-
Ada is the result of the most extensive and most expensive language design effort ever undertaken.
-
Smalltalk: the concept of object-oriented programming.
Chapter 5
-
What is the potential danger of case-sensitive names?
- Names that look alike are different.
-
In what way are reserved words better than keywords ?
- A reserved word is a special word that cannot be used as a user-defined name.
- A keyword is a word that is special only in certain contexts.
-
What is an alias?
- If two variable names can be used to access the same memory location, they are called aliases.
-
What are the attributes of a variable?
- name, address, value, type, lifetime, scope.
-
What is the l-value of a variable? What is the r-value?
- The l-value of a variable is its address;
- the r-value of a variable is its value.
-
After language design and implementation, what are the four times bindings can take place in a program?
- Compile time, Link time, Load time, Run time.
-
Define static binding and dynamic binding.
- A binding is static if it first occurs before run time and remains unchanged throughout program execution.
- A binding is dynamic if it first occurs during execution or can change during execution of the program.
-
How is a reference to a nonlocal variable in a static-scoped program connected to its definition?
- Search process: search declarations, first locally, then in increasingly larger enclosing scopes, until one is found for the given name.
-
How is a reference to a nonlocal variable in a dynamic-scoped program connected to its definition?
- References to variables are connected to declarations by searching back through the chain of subprogram calls that forced execution to this point.
-
What is the referencing environment of a statement?
- The referencing environment of a statement is the collection of all names that are visible in the statement.
-
What is a static ancestor of a subprogram? What is a dynamic ancestor of a subprogram?
- Enclosing static scopes (to a specific scope) are called its static ancestors.
- Their callers are their dynamic ancestors.
-
Define name type compatibility, declaration equivalence, and structure type compatibility.
- 两个变量具有按名等价的类型当且仅当它们一起被说明,或者用相同的类型标识符说明,即对应的类型名相同;
- 两个变量具有按定义等价的类型当且仅当两个变量有完全相同的类型(包括相同的域名);
- 两个变量具有按结构等价的类型当且仅当变量的所有分量有相同类型的值集.
-
The lifetime of a variable is the time during which it is bound to a particular memory cell.
-
A programming language is strongly typed if type errors are always detected.
-
The scope of a variable is the range of statements over which it is visible.
-
Static scoping often encourages many globals.
-
A subprogram is active if its execution has begun but has not yet terminated.
-
A named constant is a variable that is bound to a value only when it is bound to storage. Its value can’t be changed by assignment or by an input statement.
Chapter 6
-
What is a descriptor?
- A descriptor (描述符)is the collection of attributes of a variable. Descriptors are used for type checking and by allocation and deallocation operations.
-
What are the advantages and disadvantages of decimal data types?
-
Decimal types are stored very much like character strings, using binary codes for the decimal digits.
-
Advantage: be capable of precisely storing decimal values.
-
Disadvantage: the range of values is restricted and their representation in memory is wasteful. (4个位对应一位数字)
-
-
What are the design issues for character string types?
- Should strings be simply a special kind of character array or a primitive type ?
- Should strings have static or dynamic length ?
-
A C++ reference type variable is a constant pointer that is always implicitly dereferenced.
-
The fundamental difference between C++ pointers and Java references is?
- C++ pointers refer to memory addresses, whereas Java references refer to class instances.
-
Data types that are not defined in terms of other types are called primitive data types.
-
A record is a possibly heterogeneous(异类的) aggregate(集合) of data elements in which the individual elements are identified by names.
-
The homogeneity(同种,同质) of elements in arrays versus the possible heterogeneity(异种,异质) of elements in records.
-
A union is a type that may store different type values at different times during program execution.
-
What are Dangling Pointers?
- A pointer that contains the address of a heap-dynamic variable that has been deallocated.
-
Dangers of dangling pointers
- The location may have been reallocated.
- The value of the new heap-dynamic variable will be destroyed.
- Storage manager to fail.
-
What are lost heap-dynamic variables?
- An allocated heap-dynamic variable that is no longer accessible to the user program. Such variables are called garbage.
Chapter 7
- Define functional side effect
- Functional side effect occurs when the function changes either one of its parameters or a global variable.
- Multiple use of an operator is called operator overloading.
- Problems of operator overloading:
- Harm to readability
- Some error undetected by the compiler
- What is short-circuit evaluation?
- A short-circuit evaluation of an expression is one in which the result is determined without evaluating all of the operands and/or operators.
- Define narrowing and widening conversions
- A narrowing(窄化) conversion converts a value to a type that cannot store even approximations(接近,近似值) of all of the values of the original type.
- A widening (宽化)conversion converts a value to a type that can include at least approximations of all of the values of the original type.
- Widening conversions are nearly always safe, whereas narrowing conversions are not.
- In all languages that allow mixed-mode assignment, the coercion takes place only after the right side expression has been evaluated.(强制转换仅仅发生于右边的表达式杯计算之后)
Chapter 8
- Two general categories of selection statements
- Two-way or n-way;
- Multiple selection.
- What is an iterative statement?
- One that causes a statement or collection of statements to be executed zero, one, or more times.
- What does an unconditional branch statement do?
- It transfers execution control to a specified place in the program.
Chapter 9
-
Two fundamental abstraction facilities in a programming language:
- Process abstraction
- Data abstraction
-
A subprogram is said to be active if it has begun but has not yet completed that execution.
-
Subprogram characteristics:
- A single entry point
- Only one subprogram in execution at any given time
- Control returns to the caller when the subprogram terminates.
-
The parameter profile of a subprogram is the number, order, and types of its formal parameter.
-
The protocol of a subprogram = The parameter profile + its return type.
-
The parameters in the subprogram header are called formal parameters.
-
What are positional parameters?
- The correspondence between actual and formal parameters is done by simple position.
-
What are keyword parameters?
- The name of the formal parameter to which an actual parameter is to be bound is specified with the actual parameter.
- The disadvantage to keyword parameters is that the user must know the names of formal parameters.
- The only restriction of keyword parameters is that after a keyword parameter appears in the list, ll remaining parameters must be keyworded.
-
All actual parameters after an absent actual parameter must be keyworded.
-
What are stack dynamic local variables?
- Stack dynamic local variables are bound to storage when the subprogram begins execution and unbound from storage when that execution terminates.
- Advantages: flexibility, the storage can be shared
- Disadvantages: time cost (allocate, deallocate, access), cannot be history sensitive.
-
Static local variables
- Advantages: efficient, history-sensitive
- Disadvantages: Inability to support recursion
-
Pass-by-result can lead to actual parameter collision.
-
Pass-by-reference is efficient in terms of time and space.
-
Constant parameters and in-mode parameters are not exactly alike, in that in-mode parameters can be changed, though changes are never reflected to callers, while constant parameters can never be assigned.
-
如果一个子程序由于异常而停止,并且异常传播到对子程序之外的异常处理程序,则引用方式和值-结果方式可能导致不同的效果。
-
What is an overloaded subprogram?
- It is a subprogram that has the same name as another subprogram in the same referencing environment.
- Every version of an overloaded subprogram must have a unique protocol(number, order, or types of its parameters, or its return type)
-
Parametric polymorphism is provided by a subprogram that takes a generic parameter that is used in a type expression that describes the types of the parameters of the subprogram.参数多态性由一个子程序提供,该子程序接受一个泛型参数,该泛型参数在描述子程序参数类型的类型表达式中使用。
-
What is a compilation units?
- The parts of program that can be compiled are sometimes called compilation units.
-
The most important characteristic of independent compilation is that the interfaces between the separately compiled units are not checked for type consistency.
-
What is separate compilation?
- Compilation units can be compiled at different times, but their compilations are not independent of each other if either accesses or uses any entities of the other.
-
What are non-local variables?
- The non-local variables of a subprogram are those that are visible within the subprogram but are not locally declared.
-
What are global variables?
- Global variables are those that are visible in all program units.
-
A coroutine(协同程序) is a special kind of subprogram, caller and called coroutines are on a more equal basis.
-
Coroutines have multiple entry points, which are controlled by themselves, while common subprogram has only one entry points.
-
Coroutines must be history sensitive, and thus have static local variables.
-
Aliasing can occur when pass-by-reference parameters are uesd.
-
Ada and C++ allow both subprogram and operator overloading.
-
Several access to non-local variables
- External declarations
- Global data blocks
- Extern modules
- Static and dynamic scoping
Chapter 10
-
The call mechanism of a subprogram
-
The return mechanism of a subprogram
-
The call and return actions require storage for :
- Status information about the caller
- Parameters
- Return address
- Functional value for function
-
A subprogram is active from the time it is called until the time that execution is completed.
-
A procedure is callable only when all of its static ancestor program units are active.
-
Displays are better if there are many references to distant non-local variables.
-
Static chaining is better if there are few references to distant nonlocal variables.
-
The deep access method provides fast subprogram linkage, but references to nonlocals, especially references to distant nonlocals are costly.
-
The shallow access method provides much faster references to nonlocals, especially distant nonlocals, but is more costly in terms of subprogram linkage.
Chapter 11
- An encapsulation is a grouping of subprograms and the data they manipulate.
- Encapsulation solves two problems: modularization and recompilation problem.
- An abstract data type (an encapsulation) , includes only the data representation of one specific data type and the subprograms that provide the operations for that type.抽象数据类型(封装)仅包括一个特定数据类型的数据表示形式以及为该类型提供操作的子程序。
- An abstract data type satisfies the two following conditions:
- The representation or definition of the type are contained in a single syntactic unit.
- The representation of objects of the type is hidden from the program units that uses the type.
- The two primary features of abstract data types are the packaging of data objects with their associated operations and information hiding.
- C++ data abstract is provided by class. Ada data abstract is provided by package.
Chapter 12
- Smalltalk was the first language to offer complete support for object-oriented programming.
- The reason why a language designer not include the multiple inheritance
- Complexity
- Efficiency
- The use of multiple inheritance can easily lead to complex program orgnazations:
- Design
- Maintenance
- Object-oriented programming languages support the paradigm(范例) with classes, methods, objects and message passing.
- Ada 95 provides support for object-oriented programming through tagged types, which can use inheritance.
Chapter 13
- Two distinct categories of concurrent unit control
- Physical concurrency: several program units execute simultaneously.
- Logical concurrency: interleaved fashion on a single processor.
- Cooperation synchronization is required between task A and task B when task A must wait for task B to complete some specific activity before task A can continue its execution.
- Competition synchronization is both task A and task B require the use of some resource that cannot simultaneously used.
- Purpose: to prevent two tasks from accessing a shared data structure at the same time
- Precondition: Mutually exclusive
- Three methods of providing mutually exclusive access:
- semaphores
- monitors
- message passing
- Tasks different states:
- New
- Runnable or ready
- Running
- Blocked
- Dead
- A semaphore is a data structure consisting of an integer and a queue that stores task descriptions.
- What are monitors?
- A structure, all synchronization operations on shared data be gathered into a single program unit.
- One of the most important features of monitors is that shared data is resident in the monitor rather than in any of the client units.
- Monitors are a better way to provide competition synchronization than semaphores.
- Message passing classification: synchronous(同步) and asynchronous(异步).
- What is a rendezvous?
- If task A wants to send a message to B, and B is willing to receive a message, the message can be transmitted. This actual transmission is called a rendezvous.
- Concurrent execution can be at the subprogram, or unit level or the statement level.
- Two of the primary facilities that concurrent languages must provide are mutually exclusive access to shared data structures(competition synchronization) and cooperation among tasks.