Transcript Chapter 1

Chapter 2
Impact of Machine Architectures
1
前言:
昔日機器昂貴,如今則是聘請程式設計師之花費最昂貴,因
此程式語言應當具有正確易寫之特質.
The data typing features of ML, the class object of C++, and
the package specification of Ada all take their toll(花費) on
execution speed, but all have the advantage of easing the
correctness problem of writing good programs. However,
how do we design such languages ?
In developing a programming language, the architecture of
the software influences the design of a language in two ways:
(1) The underlying computer on which programs will execute;
and (2) the execution model, or virtual computer, that
supports that language on the actual hardware.

Computer = H/W + S/W
Program = Algorithm + Data Structure.
而Program 藉著Computer之助得以儲存
與執行計算

Abstract Computer:Only exists in our heads or on the
papers.
當 abstract computer 完全用 H/W implement出來,謂
之Actual(Hardware, Physical) computer.
Virtual Computer
Actual (Hardware) Computer
Software-simulated Computer
 Virtual computer 實例
H/W
Virtual Computer
Cyber
OS
VAX/VMS
Simulator
RSX-11M
PDP-11 Simulator
A programming language is implemented by construction of a
translator, which translates programs in the language into machine
language programs that can be directly executed by some
computer. The computer that executes the translated programs
may either be a hardware computer or a virtual computer
composed partially of hardware and partially of software.
A computer consists of six major components that correspond
closely to the major aspects of a programming language as
follows:
(對應於PL之觀點;
Computer之結構可以分成6大部分:)
1.Data: primitive data types
2.Primitive operations:+, *, go, stop, ..etc.
3.Sequence control:by the interpreter & PC.
4.Data access: a computer incorporates a means of
designating operands and a mechanism for retrieving
operands from a given operand designator.
5.Storage management: to balance those variant speeds
appropriately, various storage mngmt facilities are used.
6.Operating environment: to communicate external envir.
◎Firmware Computers(用語言的觀點)


Programming language in high level
若HLL之每一個指令可以直接被
computer之H/W執行,則謂此computer
為Hardware computer.(e.g.,Reduce-2)
Hardware computer
H/W computer較complex, cost較高
flexibility較差 in a variety of
computing tasks.
A common alternative to the strict hardware realization of a computer is the
firmware computer simulated by a microprogram running on a special
microprogrammable hardware computer.
Firmware computer 是使用microprogram simulates
在一架特殊的microprogrammable H/W 上的
computer. 通常the microprogram itself resides in
a special read-only memory in the host computer
and is executed AT HIGH SPEED.
Microprogram simulation of a computer is
sometimes termed EMULATION.
We also refer to the resulting computer as a virtual computer because it is
simulated by the microprogram; without this microprogrammed simulation, the
machine would not exist.
◎Translators & Virtual Architectures
Practical considerations tend to favor actual computers with rather
Low-level machine languages on the basis of speed, flexibility, and cost.
Program
execution 有兩種方法
1. Translation (compilation)
(obj prog or m.l.p)
Source prog.
compiler
Assembly-lang prog
preprocessor
assembler
Extended form
computer
of HLL
link editor
Object prog.
Executable form
loader
Translation of a high-level source language into
executable machine language programs often involves more
than one translation step. For example, it is not uncommon to
have C++ programs first translated into C programs, compiled
into assembly language, assembled to produce relocatable
machine code, and finally link-edited and loaded to produce
executable machine code.
2. S/W simulation (interpretation)
無需 source prog
obj prog
execute
而是利用 simulation program (或interpreter)
executes the source program directly.
一 (+, A, B, C)
二 abc*d/+
+
a+b*c/d
=> abc*d/+
a
/
d
*
b
c
The translator would ordinarily process each program statements exactly
once, whereas the simulator might process some statements repeatedly (if they
were part of a loop) and might ignore others completely (if control never
reached them).
Pure translation and pure simulation form two extremes. In practice, pure
translation is seldom used except in cases where the input language is in fact
quite similar to the machine language, as in the case of assembly languages.
Pure simulation is also relatively rare except in the case of operating system
control languages or interactive languages. More commonly, a language is
implemented on a computer by a combination of translation and simulation, as
shown in Figure 2.3.
Translation + Simulation



process the program statements in logic sequence.
所以碰到 loop 之類的指令則需重複decode好幾遍.
intermediate form
source
interpreter
execute
interpreter 相當於compiler的syntax phase analyzer,
利用reduction去認識statement屬於哪一纇,再call適
當的action routine去產生intermediate form.
如 LISP, SNOBOL, APL
Advantage: 不需浪費space去存 obj code.
Disadvantage: 每次都要重新decode.




發展趨勢: 先利用interpreter去除programs之錯誤,
再利用compiler作optimization及save
obj code.
問: Define the term TRANLATOR?( 4 terms !)
polish form, prefix form 屬於 intermediate form
FORTRAN之operation:
(i) h/w operation: testing, arithmetic, linear array
accessing.
(ii) in-line simulation(即將要simulate的statement
代入於program中之相對應處): complex
arith. multi-dim array accessing.
(iii) s/w simulation by runtime routine: I/O call out
出去 (因routine 太大,為經濟效益)
1. Compiled languages: C, C++, FORTRAN, Pascal and Ada.
2. Interpreted languages: LISP, ML, Perl, Postcript, Prolog,
and Smalltalk.
Java and the WWW have changed some of these classified rules: Java , a
language more like C++ and Pascal than LISP, is nevertheless often processed
as an interpreted language with Java compiler producing an intermediate set of
byecodes for a Java virtual machine.
For Web applications, major inefficiency is due to the transmission time of
web pages over the network and not in host machine time. By transmitting the
bytecodes to the local machine, execution is often faster, even on a slow
computer, than transmitting the results from the Web server. However, the Web
server does not know the underlying machine architecture of the host computer.
In this case, the Web browser creates a Java virtual machine executes the
standard set of Java bytecodes.
◎ Virtual Computers & Binding Times

A computer is defined as an integrated set of
algorithms and data structures capable of storing
and executing programs. It may actually be
constructed through:
(1) a h/w realization.
(2) a f/w realization (i.e., by microprogramming
a suitable h/w computer).
(3) a virtual machine.
(4) some combination of above f/w & s/w.

Syntax & Semantics (of a language)
Syntax
static structure of a program
Semantics
dynamic structure of a program
例: (in Pascal)
Syntax: V: array[1..10] of real;
Semantics: if it is placed at the beginning of a
subprogram means to create on each
entry to that subprogram, and destroy
on exit, a vector that has storage for 10
real numbers and that can be referenced
by the name V during exe.
DEF: a computer that is partially or wholly simulated
by software or microprograms is termed a
VIRTUAL COMPUTER.

Each time the language is implemented on a different
computer, the implementor tends to see a slightly
different (and sometimes very different) virtual
computer in the language definition. Thus two
different implementations of the same language may
utilize a different set of data structures and operations
in the implementation, particularly for data structures
and operations that are HIDDEN in the program
syntax.
The implementor must also determine precisely what
is to be done during translation of a program and what
during execution.
★ 3 factors lead to differences among implementations
of the same language:
1. different implementor’s conception in language def.
2. different facilities provided by the host.
3. different tradeoff on simplifying the translator
or setting up more simple run-time structures.
◎ Hierarchies of Computers
Virtual computer
dfnd by prog’er
H.L.L virtual computer
Operating system virtual computer
Firmware virtual computer
Hardware Computer
◎BINDING & BINDING TIME
DEF:
The binding of a program element to a particular
characteristic or property as simply the choice of the
property from a set of possible properties. The time
during program formulation or processing when this
choice is made is termed the Binding Time.
Binding Time:
1.language definition time
2.implementation time
3.compile time
4.execution time (run time)
1. language definition time (define syntax & semantics of a language)
▽ define prog structure
▽ possible alternative statement forms
▽ data structure types
▽ key word, … etc.
2. language implementation time (design a compiler)
▽ number representation
▽ number range
▽ arithmetic operation
此部份是 machine dependent (即 not portable)
3.translation (compile) time
▽ In all languages, but especially those that are
compiled, important classes of bindings are
performed during translation. 又區分為:
(a) Bindings chosen by the programmer; 如
variable name, types of variables, program
statement structures, … etc
(b) Binding chosen by the translator; 如
the relative location of a data object in the
storage allocated for a procedure is generally
handled without knowledge or intervention by
the programmer.
(c) Bindings chosen by the loader;
bindings of subprograms to a
single executable program.
4. execution time( run time )
▽ 如[1] binding of variable to their values
[2] binding of variable to particular storage
locations (PASCAL之pointer variable)
2 subcategories:
(i) on entry to a subprogram and block.
(ii) at arbitrary points during execution.
◎ 今以一實例說明上述四種binding times:
X := X + 10
各種可能的 BINDING (TIME) 如下:
(1) Set of possible types for variable X:
[a] real ? integer ? boolean ? set ? char ?
(language definition time)
[b] user-defined type ? (translation time)
(2) type of variable X:
[a] 經由宣告 X : real;(如Pascal)(translation
time)
[b] 僅僅在執行時才知道;如LISP (execution
time)
(3) set of possible values for variable X:
此屬性在language implementation time時
binding.
why? Compiler designer should do this job.
(4) value of the variable X: (at execution time)
(5) representation of the constant 10:
[a] the choice of decimal (string “10”) representation in the program is usually made at
language definition time.
[b] the choice of a particular sequence of bits to
represent 10 at execution time is usually
made at language implementation time.
(6) properties of the operator “+”:
[a] the choice of the symbol “+” to represent the
addition operator is made at language
definition time.
[b] to make the determination of which operation is represented by “+” is made at
compile time.
◎ In summary, X:= X + 10
at lang. def. time: “+” is bound to “addition oprn”
at lang. impl. time: “+” is definded (how to add)
at translation time: “+” is bound to a particular
addition operation
at execution time: 其結果之值被決定.
★ 針對 binding times 之不同, 我們可以更瞭解語言
之異.
In ML/LISP, most of the bindings required in the
program will be set up at execution time while in
FORTRAN most will be set up at translation time.
Thus a ML/LISP version of the program would
spend most of its execution time creating and
destroying bindings, while in the FORTRAN
version most of the same bindings would be set up
once during translation, leaving only a few to be
handled during execution. As a result, the
FORTRAN version would EXECUTE MUCH
MORE EFFICIENTLY. But, FORTRAN is so
INFLEXIBLE in its handling of arrays, numbers,
and arithmetic, as compared to ML/LISP.
FORTRAN is a language with EARLY binding,
while ML/LISP is LATE binding which delays
most bindings until execution time.
Key point:
FORTRAN,
Pascal, and C
EFFICENCY VS.
ML,
LISP
FLEXIBILITY
In a language designed for both efficient execution and flexibility,
such as Ada. ,multiple operations are often available that allow
choices of binding times.
Often seemingly minor changes in a language may lead to major
changes in binding times. For example, in FORTRAN 90, the
change to allow recursion modifies many of the binding times of
important FORTRAN features. Because binding times are
implementation dependent, we place emphasis on knowing the
language implementation. When approaching your own local
implementation of a language, it is important to ask about the
binding times in that implementation. Are they the usual ones, or
have local modifications to the language caused the usual binding
times to be modified ?
1991: Sun’s Green team was expected to develop a language for
use on consumer digital devices. (working version only)
1993: the Mosaic Web Browser was released. This had the effect of
moving the Internet from the domain of the academic
researchers to the world at-large. The Green team
immediately saw the role of their language as a way to
enhance Web browsers. With Mosaic, and its underlying
HTML Web pages and URLs to navigate around the Web,
users could download information from distant sites.
However, there are 3 limitations to using the Web:
1. Transmission speeds to consumer homes were limited to about
33,000 bits per second in 1993. (Now 50,000 bps.)
2. If a site were popular, its own processing speed would be
severely impacted if many users were accessing its Web pages
at the same time.
3. Each Web object (e.g., document, picture, video, audio)
required a separate protocol in each Web browser. New formats
could not be added to the set until all browsers included this
new protocol.
Because most users of the Web were waiting for information to
appear on their screen, their own computers were often idle. A way
around the first two limitations would be to have some of the
information processed on the user’s machine and not on the Web server.
This could be accomplished by having the Web server download a small
application program (i,e., an applet) that would run on the user’s
computer, thus freeing up the Web server to process more users at the
same time. Similarly, the Web server could download an applet that
could handle any new protocols that were needed using this same
feature.
The Sun group saw the value of their development as an adjunct to
Web technology. However, to be effective, their language had to fulfill
several requirements: (1) Architectural independence. (2) Security.
A Java virtual machine was designed
and the applet would be compiled into
a series of bytecodes for it.
Not allow the server
to access user’s inf.
In 1994, Sun developed the HotJava browser that contained the
Java virtual machine to demonstrate its applicability. Finally on
May 23, 1995, Marc Andreessen, cofounder of Netscape
Communications, which at the time had a 70% market share of the
Web browser market, announced that Netscape had incorporated
the Java virtual machine as part of its Netscape browser. Since
that time, Java use has mushroomed. Although designed to
execute applets as part of a Web browser, it has also gained
acceptance as a general PL, often replacing C++ or C as a first PL
for student use.
C 
C++ 
Java
• Zuse’s Plankalkül 德國人 Zuse之PL名
• Minimal Hardware Programming:
Pseudocodes
• The IBM 704 and Fortran
• Functional Programming: LISP
• The First Step Toward Sophistication:
ALGOL 60 複雜;精密
• Computerizing Business Records: COBOL
• The Beginnings of Timesharing: BASIC
Copyright © 2009 Addison-Wesley. All rights reserved.
1-34
• Everything for Everybody: PL/I
• Two Early Dynamic Languages: APL and
SNOBOL(dynamic typing & storage alloc.)
• The Beginnings of Data Abstraction:
SIMULA 67(for simulation & O.R.)
• Orthogonal Design: ALGOL 68(new ideas)
• Some Early Descendants of the ALGOLs
(PASCAL) ref. to Page 95-97
• Programming Based on Logic: Prolog
• History's Largest Design Effort: Ada
Copyright © 2009 Addison-Wesley. All rights reserved.
1-35
• Object-Oriented Programming: Smalltalk
• Combining Imperative and ObjectOriented Features: C++
• An Imperative-Based Object-Oriented
Language: Java
• Scripting Languages
• A C-Based Language for the New
Millennium: C#
• Markup/Programming Hybrid Languages
Copyright © 2009 Addison-Wesley. All rights reserved.
1-36
Genealogy of Common Languages
Copyright © 2009 Addison-Wesley. All rights reserved.
1-37
Zuse’s Plankalkül
• Designed in 1945, but not published until
1972
• Never implemented
• Advanced data structures
– floating point, arrays, records
Copyright © 2009 Addison-Wesley. All rights reserved.
1-38
Plankalkül Syntax
• An assignment statement to assign the
expression A[4] + 1 to A[5]
| A + 1 => A
V | 4
5
S | 1.n
1.n
(subscripts)
(data types)
整數 n bits
Copyright © 2009 Addison-Wesley. All rights reserved.
1-39
Minimal Hardware Programming:
Pseudocodes
• What was wrong with using machine code?
–
–
–
–
Poor readability
Poor modifiability
Expression coding was tedious
Machine deficiencies--no indexing or floating
point
Copyright © 2009 Addison-Wesley. All rights reserved.
1-40
Pseudocodes: Short Code
• Short Code developed by Mauchly in 1949
for BINAC computers
– Expressions were coded, left to right
– Example of op-code vs. operations:
01 –
06 abs value
1n (n+2)nd power
02 )
03 =
04 /
07 +
08 pause
09 (
2n (n+2)nd root
4n if <= n
58 print and tab
20是開平方根 21則是開立方根
00 X0 03 20 06 Y0 代表 X0 = SQRT( ABS (Y0))
Copyright © 2009 Addison-Wesley. All rights reserved.
1-41
Pseudocodes: Speedcoding
• Speedcoding developed by Backus in 1954
for IBM 701
–
–
–
–
–
Pseudo ops for arithmetic and math functions
Conditional and unconditional branching
Auto-increment registers for array access
Slow!
Only 700 words left for user program
Copyright © 2009 Addison-Wesley. All rights reserved.
1-42
Pseudocodes: Related Systems
• The UNIVAC Compiling System
– Developed by a team led by Grace Hopper
– Pseudocode expanded into machine code
正如macro expansion
• David J. Wheeler (Cambridge University)
– developed a method of using blocks of relocatable addresses to solve the problem of
absolute addressing
Copyright © 2009 Addison-Wesley. All rights reserved.
1-43
IBM 704 and Fortran
• Fortran 0: 1954 - not implemented
• Fortran I:1957
– Designed for the new IBM 704, which had index registers
and floating point hardware
- This led to the idea of compiled programming
languages, because there was no place to hide the cost of
interpretation (no floating-point software)
浮動點計算之硬體問世後 連帶地讓軟體模擬之無效率昭然若揭 !
– Environment of development
•
•
•
•
Computers were small and unreliable
Applications were scientific
No programming methodology or tools
Machine efficiency was the most important concern
Copyright © 2009 Addison-Wesley. All rights reserved.
1-44
Design Process of Fortran
• Impact of environment on design of Fortran I
– No need for dynamic storage
– Need good array handling and counting loops
– No string handling, decimal arithmetic, or
powerful input/output (for business software)
Copyright © 2009 Addison-Wesley. All rights reserved.
1-45
Fortran I Overview
• First implemented version of Fortran
–
–
–
–
–
–
Names could have up to six characters
Post-test counting loop (DO)
Formatted I/O
User-defined subprograms
Three-way selection statement (arithmetic IF)
No data typing statements
Copyright © 2009 Addison-Wesley. All rights reserved.
1-46
Fortran I Overview (continued)
• First implemented version of FORTRAN
– No separate compilation
– Compiler released in April 1957, after 18
worker-years of effort
– Programs larger than 400 lines rarely compiled
correctly, mainly due to poor reliability of 704
– Code was very fast
– Quickly became widely used
Copyright © 2009 Addison-Wesley. All rights reserved.
1-47
Fortran II
• Distributed in 1958
– Independent compilation
– Fixed the bugs
Copyright © 2009 Addison-Wesley. All rights reserved.
1-48
Fortran IV
• Evolved during 1960-62
–
–
–
–
Explicit type declarations
Logical selection statement
Subprogram names could be parameters
ANSI standard in 1966
Copyright © 2009 Addison-Wesley. All rights reserved.
1-49
DIMENSION H(1000)
READ(5, 5010) N
5010 FORMAT(I5)
READ(5, 5020) (H(I), I=1,N)
5020 FORMAT(F10.1)
SUM = 0.0
DO 10 I=1, N
SUM = SUM + H(I)
10 CONTINUE
HMEAN = SUM/FLOAT(N)
HMAX = 0.0
Copyright © 2004 Pearson Addison-Wesley. All rights reserved.
2-50
HMIN = 1000.0
DO 20 I=1, N
IF(HMAX .LT. H(I)) HMAX = H(I)
IF(HMIN .GT. H(I)) HMIN = H(I)
20 CONTINUE
WRITE(6, 6000) N, HMEAN, HMAX, HMIN
6000 FORMAT(1H0, 2HN=, I5 /1H0, 5HMEAN=, F10.2
1
/1H0,5HMAX =, F10.2 /1H0, 5HMIN =, F10.2)
STOP
END
Copyright © 2004 Pearson Addison-Wesley. All rights reserved.
2-51
Fortran 77
• Became the new standard in 1978
– Character string handling
– Logical loop control statement
– IF-THEN-ELSE statement
Copyright © 2009 Addison-Wesley. All rights reserved.
1-52
Fortran 90
• Most significant changes from Fortran 77
–
–
–
–
–
–
Modules
Dynamic arrays
Pointers
Recursion
CASE statement
Parameter type checking
Copyright © 2009 Addison-Wesley. All rights reserved.
1-53
Latest versions of Fortran
• Fortran 95 – relatively minor additions, plus
some deletions
• Fortran 2003 - ditto
Copyright © 2009 Addison-Wesley. All rights reserved.
同上
1-54
Fortran Evaluation
• Highly optimizing compilers (all versions
before 90)
– Types and storage of all variables are fixed
before run time
• Dramatically changed forever the way
computers are used
• Characterized as the lingua franca of the
computing world
Copyright © 2009 Addison-Wesley. All rights reserved.
通用語
1-55
Functional Programming: LISP
• LISt Processing language
–
Designed at MIT by McCarthy
• AI research needed a language to
– Process data in lists (rather than arrays)
– Symbolic computation (rather than numeric)
• Only two data types: atoms and lists
• Syntax is based on lambda calculus
λ form means f = λ(x, y) x2 + y2 to be depicted as
(LAMBDA (x y) (PLUS (TIMES x x)(TIMES y y)))
Copyright © 2009 Addison-Wesley. All rights reserved.
1-56
LISP programming:
(append (lambda (lis1 lis2)
(cond (( null lis1) lis2)
(T (cons (car lis1)(append (cdr lis1) lis2 ))))))))
(reverse (lambda (lis)(reverse1 lis nil)))
(reverse1 (lambda (lis colvariable)
(cond ((null lis) colvariable)
( T (reverse1 (cdr lis)
(cons (car lis) colvariable)))))))
(length (lambda (lis)
(cond ((null lis) 0)
(T (add1 (length (cdr lis))))))))))
Copyright © 2004 Pearson Addison-Wesley. All rights reserved.
2-57
Some LISP programs
DEFINE((( FIB (LAMBDA (X)
(COND (( EQ X 0) 0)
(EQ X 1) 1)
(T (PLUS (FIB (PLUS X -1))
(FIB (PLUS X -2)))))))))
DEFINE ((( HANOI (LAMBDA (N X Y Z)
(COND ((EQ N 0) NIL)
(T (CONS (CONS
(HANOI (PLUS N -1) X Z Y)
(CONS X Y))
(HANOI (PLUS N -1) Z Y X)))))))
Copyright © 2009 Addison-Wesley. All rights reserved.
1-58
Representation of Two LISP Lists
Representing the lists (A B C
and (A (B C) D (E (F G)))
Copyright © 2009 Addison-Wesley. All rights reserved.
D)
Program code and data have exactly
the same form: parenthesized lists.
1-59
LISP Evaluation
• Pioneered functional programming
– No need for variables or assignment
– Control via recursion and conditional
expressions
• Still the dominant language for AI
• COMMON LISP and Scheme are
contemporary dialects of LISP
• ML, Miranda, and Haskell are related
languages
Copyright © 2009 Addison-Wesley. All rights reserved.
1-60
Scheme
• Developed at MIT in mid 1970s
• Small
• Extensive use of static scoping( so fun
regarded as parameter)
• Functions as first-class entities
• Simple syntax (and small size) make it ideal
for educational applications
Copyright © 2009 Addison-Wesley. All rights reserved.
1-61
COMMON LISP
• An effort to combine features of several
dialects of LISP into a single language
• Large, complex (both static & dynamic are
held, data types include records, arrays,
complex numbers and character strings)
Copyright © 2009 Addison-Wesley. All rights reserved.
1-62
The First Step Toward Sophistication:
ALGOL 60
• Environment of development
– FORTRAN had (barely) arrived for IBM 70x
– Many other languages were being developed, all
for specific machines
– No portable language; all were machinedependent
– No universal language for communicating
algorithms
• ALGOL 60 was the result of efforts to
design a universal language
Copyright © 2009 Addison-Wesley. All rights reserved.
世界語 共通語
1-63
Early Design Process
• ACM and GAMM(a German acronym for
Society for Applied Mathematics and
Mechanics) met for four days for design
(May 27 to June 1, 1958)
• Goals of the language
– Close to mathematical notation
– Good for describing algorithms
– Must be translatable to machine code
字母縮略字
Copyright © 2009 Addison-Wesley. All rights reserved.
1-64
ALGOL 58
•
•
•
•
•
•
•
•
•
•
Concept of type was formalized
Names could be any length
Arrays could have any number of subscripts
Parameters were separated by mode (in & out)
Subscripts were placed in brackets
Compound statements (begin ... end)
Semicolon as a statement separator
Assignment operator was :=
if had an else-if clause
No I/O - “would make it machine dependent”
Copyright © 2009 Addison-Wesley. All rights reserved.
1-65
ALGOL 58 Implementation
• Not meant to be implemented, but
variations of it were (MAD, JOVIAL)
• Although IBM was initially enthusiastic, all
support was dropped by mid 1959
Copyright © 2009 Addison-Wesley. All rights reserved.
1-66
ALGOL 60 Overview
• Modified ALGOL 58 at 6-day meeting in
Paris
• New features
– Block structure (local scope)
– Two parameter passing methods(by value & by
name)
– Subprogram recursion
– Stack-dynamic arrays
– Still no I/O and no string handling
Copyright © 2009 Addison-Wesley. All rights reserved.
1-67
ALGOL 60 Evaluation
• Successes
– It was the standard way to publish algorithms
for over 20 years
– All subsequent imperative languages are based
on it
– First machine-independent language
– First language whose syntax was formally
defined (BNF)
Copyright © 2009 Addison-Wesley. All rights reserved.
1-68
ALGOL 60 Evaluation (continued)
• Failure
– Never widely used, especially in U.S.
– Reasons
• Lack of I/O and the character set made programs
non-portable
• Too flexible--hard to implement
• Entrenchment of Fortran
• Formal syntax description
• Lack of support from IBM
挖壕溝 保護
Copyright © 2009 Addison-Wesley. All rights reserved.
1-69
Computerizing Business Records: COBOL
• Environment of development
– UNIVAC was beginning to use FLOW-MATIC
– USAF was beginning to use AIMACO
– IBM was developing COMTRAN
Copyright © 2009 Addison-Wesley. All rights reserved.
1-70
COBOL Historical Background
• Based on FLOW-MATIC
• FLOW-MATIC features
– Names up to 12 characters, with embedded
hyphens
– English names for arithmetic operators (no
arithmetic expressions)
– Data and code were completely separated
– The first word in every statement was a verb
Copyright © 2009 Addison-Wesley. All rights reserved.
1-71
COBOL Design Process
• First Design Meeting (Pentagon) - May 1959
• Design goals
– Must look like simple English
– Must be easy to use, even if that means it will be less
powerful
– Must broaden the base of computer users
– Must not be biased by current compiler problems
• Design committee members were all from
computer manufacturers and DoD branches
• Design Problems: arithmetic expressions?
subscripts? Fights among manufacturers
Copyright © 2009 Addison-Wesley. All rights reserved.
1-72
COBOL Evaluation
• Contributions
–
–
–
–
–
First macro facility in a high-level language
Hierarchical data structures (records)
Nested selection statements
Long names (up to 30 characters), with hyphens
Separate data division
Copyright © 2009 Addison-Wesley. All rights reserved.
1-73
COBOL: DoD Influence
• First language required by DoD
– would have failed without DoD
• Still the most widely used business
applications language
Copyright © 2009 Addison-Wesley. All rights reserved.
1-74
The Beginning of Timesharing: BASIC
• Designed by Kemeny & Kurtz at Dartmouth
• Design Goals:
–
–
–
–
–
Easy to learn and use for non-science students
Must be “pleasant and friendly”
Fast turnaround for homework
Free and private access
User time is more important than computer time
• Current popular dialect: Visual BASIC
• First widely used language with time
sharing
Copyright © 2009 Addison-Wesley. All rights reserved.
1-75
2.8 Everything for Everybody: PL/I
• Designed by IBM and SHARE
• Computing situation in 1964 (IBM's point
of view)
– Scientific computing
• IBM 1620 and 7090 computers
• FORTRAN
• SHARE (IBM scientic user group)
– Business computing
• IBM 1401, 7080 computers
• COBOL
• GUIDE user group
Copyright © 2009 Addison-Wesley. All rights reserved.
1-76
PL/I: Background
• By 1963
– Scientific users began to need more elaborate
I/O, like COBOL had; business users began to
need floating point and arrays for MIS
– It looked like many shops would begin to need
two kinds of computers, languages, and support
staff--too costly
• The obvious solution
– Build a new computer to do both kinds of
applications
– Design a new language to do both kinds of
applications
精緻的
Copyright © 2009 Addison-Wesley. All rights reserved.
1-77
PL/I: Design Process
• Designed in five months by the 3 X 3
Committee
– Three members from IBM, three members from
SHARE
• Initial concept
– An extension of Fortran IV
• Initially called NPL (New Programming
Language)
• Name changed to PL/I in 1965(National Physical Lab
in England)
Copyright © 2009 Addison-Wesley. All rights reserved.
1-78
PL/I: Evaluation
• PL/I contributions
–
–
–
–
–
First unit-level concurrency
First exception handling
Switch-selectable recursion
First pointer data type
First array cross sections(可以從二維陣列參照成一維向量)
• Concerns
– Many new features were poorly designed
– Too large and too complex
Copyright © 2009 Addison-Wesley. All rights reserved.
1-79
Pascal - 1971
• Developed by Wirth (a former member of
the ALGOL 68 committee)
• Designed for teaching structured
programming
• Small, simple, nothing really new
• Largest impact was on teaching
programming
– From mid-1970s until the late 1990s, it was the
most widely used language for teaching
programming
Copyright © 2009 Addison-Wesley. All rights reserved.
1-80
Program simple(input, output);
Var L1, L2, L3 : char;
number: integer;
procedure Hanoi( story: integer; P1, P2, P3: char);
begin
if story > 0 then
begin
Hanoi( story-1, P1, P3, P2);
writeln(‘Move piece’, story, ‘from ’,P1, ‘to ’, P3);
Hanoi( story-1, P2, P1, P3)
end
end;
Begin
readln( L1, L2, L3, number); Hanoi( number, L1, L2, L3)
End.
Copyright © 2004 Pearson Addison-Wesley. All rights reserved.
2-81
C - 1972
• Designed for systems programming (at Bell
Labs by Dennis Richie)
• Evolved primarily from BCPL, B, but also
ALGOL 68
• Powerful set of operators, but poor type
checking
• Initially spread through UNIX
• Many areas of application
Copyright © 2009 Addison-Wesley. All rights reserved.
1-82
Programming Based on Logic: Prolog
• Developed, by Comerauer and Roussel
(University of Aix-Marseille), with help from
Kowalski ( University of Edinburgh)
• Based on formal logic
• Non-procedural
• Can be summarized as being an intelligent
database system that uses an inferencing
process to infer the truth of given queries
• 缺點:Highly inefficient, small application
areas
Copyright © 2009 Addison-Wesley. All rights reserved.
1-83
History’s Largest Design Effort: Ada
• Huge design effort, involving hundreds of
people, much money, and about eight
years(需求建議書如下:)
–
–
–
–
–
Strawman requirements (April 1975)
Woodman requirements (August 1975)
Tinman requirements (1976)
Ironman equipments (1977)
Steelman requirements (1978)
• Named Ada after Augusta Ada
Byron(1815-1851), the first programmer
Copyright © 2009 Addison-Wesley. All rights reserved.
1-84
Ada Evaluation
• Contributions
–
–
–
–
Packages - support for data abstraction(see next page)
Exception handling - elaborate
Generic program units(used for several types)
Concurrency - through the tasking model
• Comments
– Competitive design
– Included all that was then known about software
engineering and language design
– First compilers were very difficult; the first really usable
compiler came nearly five years after the language design
was completed
Copyright © 2009 Addison-Wesley. All rights reserved.
1-85
In computing, an abstract data type (ADT) is a mathematical model for a certain class of
data structures that have similar behavior; or for certain data types of one or more
programming languages that have similar semantics. An abstract data type is defined
indirectly, only by the operations that may be performed on it and by mathematical
constraints on the effects (and possibly cost) of those operations[2].
For example, an abstract stack data structure could be defined by two operations: push, that
inserts some data item into the structure, and pop, that extracts an item from it; with the
constraint that each pop always returns the most recently pushed item that has not been
popped yet. When analyzing the efficiency of algorithms that use stacks, one may also
specify that both operations take the same time no matter how many items have been pushed
into the stack, and that the stack uses a constant amount of storage for each element.
Abstract data types are purely theoretical entities, used (among other things) to simplify
the description of abstract algorithms, to classify and evaluate data structures, and to
formally describe the type systems of programming languages. However, an ADT may be
implemented by specific data types or data structures, in many ways and in many
programming languages; or described in a formal specification language. ADTs are often
implemented as modules: the module's interface declares procedures that correspond to the
ADT operations, sometimes with comments that describe the constraints. This information
hiding strategy allows the implementation of the module to be changed without disturbing
the client programs.
Copyright © 2009 Addison-Wesley. All rights reserved.
1-86
Ada 95
To allow adding new components to
those inherited from a base class.
• Ada 95 (began in 1988)
–
–
–
–
Support for OOP through type derivation
Better control mechanisms for shared data
New concurrency features
More flexible libraries
• Popularity suffered because the DoD no
longer requires its use but also because of
popularity of C++
Copyright © 2009 Addison-Wesley. All rights reserved.
1-87
Copyright © 2009 Addison-Wesley. All rights reserved.
1-88
Object-Oriented Programming:
Smalltalk
• Developed at Xerox PARC, initially by Alan
Kay, later by Adele Goldberg
• First full implementation of an objectoriented language (data abstraction,
inheritance, and dynamic binding)
• Pioneered the graphical user interface
design(the first contribution done by
Smalltalk)
• The second contribution is to promote OOP
Copyright © 2009 Addison-Wesley. All rights reserved.
1-89
Combining Imperative and ObjectOriented Programming: C++
• Developed at Bell Labs by Stroustrup in 1980
• Evolved from C and SIMULA 67
• Facilities for object-oriented programming, taken
partially from SIMULA 67
• Provides exception handling
• A large and complex language, in part because it
supports both procedural and OO programming
• Rapidly grew in popularity, along with OOP
• ANSI standard approved in November 1997
• Microsoft’s version (released with .NET in 2002):
Managed C++
Copyright © 2009 Addison-Wesley. All rights reserved.
1-90
Related OOP Languages
• Eiffel (designed by Bertrand Meyer - 1992)
– Not directly derived from any other language
– Smaller and simpler than C++, but still has
most of the power
– Lacked popularity of C++ because many C++
enthusiasts were already C programmers
• Delphi (Borland)
– Pascal plus features to support OOP
– More elegant and safer than C++
Copyright © 2009 Addison-Wesley. All rights reserved.
1-91
An Imperative-Based Object-Oriented
Language: Java
• Developed at Sun in the early 1990s
– C and C++ were not satisfactory for embedded
electronic devices
• Based on C++
– Significantly simplified (does not include struct,
union, enum, pointer arithmetic, and half of
the assignment coercions of C++)
– Supports only OOP
– Has references, but not pointers
– Includes support for applets and a form of
concurrency
An applet is a program written in the Java programming language that can be included in an HTML page, much in the same
way an image is included in a page. When you use a Java technology-enabled browser to view a page that contains an applet, the
applet's code is transferred to your system and executed by the browser's Java Virtual Machine (JVM). For information and
examples on how to include an applet in an HTML page, refer to this description of the <APPLET> tag.
Copyright © 2009 Addison-Wesley. All rights reserved.
1-92
Java Evaluation
•
•
•
•
Eliminated many unsafe features of C++
Supports concurrency
Libraries for applets, GUIs, database access
Portable: Java Virtual Machine concept, JIT
compilers
• Widely used for Web programming
• Use increased faster than any previous
language
• Most recent version, 5.0, released in 2004
Copyright © 2009 Addison-Wesley. All rights reserved.
1-93
Scripting Languages for the Web
• Perl
– Designed by Larry Wall—first released in 1987
– Variables are statically typed but implicitly declared
– Three distinctive namespaces, denoted by the first character of a
variable’s name($ @ 及 %)
– Powerful, but somewhat dangerous
– Gained widespread use for CGI programming on the Web
– Also used for a replacement for UNIX system administration language
• JavaScript
– Began at Netscape, but later became a joint venture of Netscape and Sun
Microsystems
– A client-side HTML-embedded scripting language, often used to create
dynamic HTML documents
– Purely interpreted
– Related to Java only through similar syntax
• PHP
– PHP: Hypertext Preprocessor, designed by Rasmus Lerdorf
– A server-side HTML-embedded scripting language, often used for form
processing and database access through the Web
– Purely interpreted
Copyright © 2009 Addison-Wesley. All rights reserved.
1-94
Scripting Languages for the Web
• Python
•
– An OO interpreted scripting language
– Type checked but dynamically typed
– Used for CGI programming and form processing
– Supports lists, tuples(immutable lists), and hashes(associative arrays)
Lua
– An OO interpreted scripting language
– Type checked but dynamically typed
– Used for CGI programming and form processing
– Dynamically typed, but type checked
– Supports lists, tuples, and hashes, all with its single data structure,
the table
– Easily extendable
永遠不變的
Copyright © 2009 Addison-Wesley. All rights reserved.
1-95
Scripting Languages for the Web
• Ruby
– Designed in Japan by Yukihiro Matsumoto (a.k.a,
“Matz”)
– Began as a replacement for Perl and Python
– A pure object-oriented scripting language
- All data are objects
– Most operators are implemented as methods,
which can be redefined by user code
– Purely interpreted
Copyright © 2009 Addison-Wesley. All rights reserved.
1-96
A C-Based Language for the New
Millennium: C#
• Part of the .NET development platform
(2000)
• Based on C++ , Java, and Delphi
• Provides a language for component-based
software development
• All .NET languages use Common Type
System (CTS), which provides a common
class library
Copyright © 2009 Addison-Wesley. All rights reserved.
1-97
Markup/Programming Hybrid
Languages
• XSLT
– eXtensible Markup Language (XML): a metamarkup
language
– eXtensible Stylesheet Language Transformation (XSTL)
transforms XML documents for display
– Programming constructs (e.g., looping)
• JSP
– Java Server Pages: a collection of technologies to support
dynamic Web documents
– servlet: a Java program that resides on a Web server and is
enacted when called by a requested HTML document; a
servlet’s output is displayed by the browser
– JSTL includes programming constructs in the form of
HTML elements
Copyright © 2009 Addison-Wesley. All rights reserved.
1-98
Summary
• Development, development environment,
and evaluation of a number of important
programming languages
• Perspective into current issues in language
design
展望 洞察
Copyright © 2009 Addison-Wesley. All rights reserved.
1-99