840 likes | 1.2k Views
COP 4020 Programming Languages I. Euripides Montagne University of Central Florida (Summer 2014). Outline. Course Organization Why studying programming languages?. COP 4020 Programming Language I. Who am I and where to find me?. Instructor: Euripides Montagne Tele.: 823-2684
E N D
COP 4020 Programming Languages I Euripides Montagne University of Central Florida (Summer 2014) COP 4020 Programmin Language 1
Outline • Course Organization • Why studying programming languages? COP 4020 Programmin Language 1
COP 4020 Programming Language I Who am I and where to find me? Instructor:Euripides Montagne Tele.:823-2684 email: eurip@eecs.ucf.edu Office hours: MW 12:30 p.m. - 1:30 p.m. (HEC 217) TR 2:00 p.m. - 3:00 p.m. (HEC 217) COP 4020 Programmin Language 1
COP 4020 Programming Language ICourse information Lecture meetings: M-W 4:00 p.m. – 5:50 p.m.(HEC 117) Web page:http://www.cs.ucf.edu/courses/cop4020/sum2014/ COP 4020 Programmin Language 1
COP 4020 Programming Language ICourse outline Course Outline: This course is designed to provide a fundamental understanding of the design and implementation issues surrounding programming languages and their running environment. Students will be exposed different models of computer programming during the course, including: concurrent programming model, declarative computation model and relational model. Course Topics: History of programming languages. Fundamental concepts of programming languages, such as scope, binding, abstraction, encapsulation, typing etc. Run time environment. Lambda calculus. Declarative computation model. Concurrent programming model and message passing. Operational semantics, axiomatic semantics, and denotational semantics. Relational computation model. Prerequisites: COP 3530C COP 4020 Programmin Language 1
COP 4020 Programming Language I Course outline (continued) Grading Policy:(20%) Exam #1 (20%) Exam # 2 or Presentation (30%) Final Exam (30%) Programming projects. “Late assignments will not be accepted” COP 4020 Programmin Language 1
COP 4020 Programming Language ICourse outline (continued) Material: Required textbook: Essentials of Programming Languages, 3rd ed., D. Friedman and M. Wand, 2008, MIT Press. ISBN: 978-0-262-06279-4 The text will be supplemented with additional notes that will be provided for you via the course web site: http://www.cs.ucf.edu/courses/cop4020/sum2014/ COP 4020 Programmin Language 1
COP 4020 Programming Language IWho is your TA? GTA: Sungchul Jung Email: sungchul@knights.ucf.edu Office hours: Wednesday 2:00 to 4:00 pm Office:HEC 308 COP 4020 Programmin Language 1
UNIVERSITY OF CENTRAL FLORIDA Lecture 1History of Programming Languages
Class 1: History of Programming Languages • ASSEMBLY LANGUAGE • FORTRAN • ALGOL SIMULA • COBOL • PL/1 • BASIC • PASCAL • C • LISP • The so called High Level Programming Languages started their development in the mid 50s.
ASSEMBLERS The earliest programming languages were oriented to control the behavior of computers. They reflected the structure of the underlying machine. This view point changed mainly for two reasons: 1.- What was easy for a machine to reason about was not necessarily easy for a human being to reason about. 2.- The number of different kinds of machines( architectures) increased and the need arose for a common programming language with which to program all of them. COP 4020 Programmin Language 1
FORTRAN (FORmulaTRANslation) • Fortran was designed to develop scientific applications on the IBM 704(with punched card inputs) computer and the major role in its design was run-time efficiency. • Developed by John Backus and his group in 1954.
PUNCH CARD COP 4020 Programmin Language 1
Main features: • Comments • Assignment statements that allowed mathematical expressions of some complexity on the “right-hand” side • The simplicity of writing loops with the DO statement • Subroutines and functions: Not a new idea but it was implemented employing a symbolic notation • Formats for input and output: Difficult feature to implement on early computers • Machine independence: A fortran program could run on different machines
Main reasons for its popularity: • It made efficient use of programming time • Easy to learn (good for non-specialist programmers) • It was supported by IBM • It simplifies INPUT/OUTPUT
Example of a Fortran Program C FORTRAN PROGRAM TO FIND MEAN OF N NUMBERS C AND NUMBER OF VALUES GREATER THAN MEAN DIMENSION A(99) REAL MEAN READ (1,5)N 5 FORMAT (I2) READ (1,10) (A(I), I=1, N) 10 FORMAT (6F10.5) SUM = 0.0 DO 15 I=1, N 15 SUM = SUM + A(I) MEAN = SUM/FLOAT(N) NUMBER = 0 DO 20 I=1, N IF (A(I).LE.MEAN) GOTO 20 NUMBER = NUMBER + 1 20 CONTINUE WRITE (2,25) MEAN, NUMBER 25 FORMAT (8H MEAN = , F10.5, 5X, 20H NUMBER OVER MEAN = , I5) STOP END.
Development: • The first design of Fortran was made in 1954 (Fortran 0) • The first implementation was developed in 1957(Fortran I) • A better compiler was developed in 1958 (Fortran II) • After many revisions in 1962 a stable compiler (Fortran IV) • First NASI standard 1966 (Fortran 66) • After a major revision new features are added (Fortran 77) • A more modern Fortran is created in 1990 (Fortran 90)
FORTRAN 77: • IF-THEN-ELSE • String Handling • Offers features that are common to modern programming languages: • Records • Modules • Pointers • Subprograms can be recursive FORTRAN 90:
FORTRAN 95: • FOR ALL construct to aid vectorization FORTRAN 2003: • Object-oriented programming • IEEE floating-point arithmetic COP 4020 Programmin Language 1
FORTRAN 0 FORTRAN I(1957) COBOL(1960) ALGOL 58 FORTRAN II ALGOL 60 FORTRAN IV PL/1(1964) BASIC FORTRAN 66 FORTRAN 77 FORTRAN 90
Referencing in FORTRAN • All variables are local to each routine: The local environment of a subroutine consists of the variables, arrays, etc. declared at the start of the subprogram. The local environment is retained between calls because the activation record is allocated statically. • Global variables are created using the COMMON declaration: COMMON /<name>/<var or array>, <var or array>, <var or array>, …
Example: COMMON/ Globalvar/X/Y/A(20) program main real X, Y common /BLK/ X, Y statements stop End subroutine sub1 ( arguments) declarations of arguments real X, Y common /BLK/ X, Y statements return End subroutine sub2 ( arguments) declarations of arguments real X, Y common /BLK/ X, Y statements return end
FORTRAN Memory layout System data and I/O buffers Code and local data for main program BLK (common block) Code and local data for sub1 Code and local data for sub2 System I/O routine
Implementing FORTRAN 77 SubprogramsActivation Record COP 4020 Programmin Language 1
FORTRAN 77 Subprograms • FORTRAN 77 subprograms cannot be recursive. • Variables declared in subprograms are statically allocated. Therefore, both parts of a FORTRAN 77 Subprogram (the code and the local variables) have fixed sizes. • So the activation record of a FORTRAN 77 subprogram has a fixed size, and therefore can be statically allocated. COP 4020 Programmin Language 1
Return address Local variables Parameters FORTRAN 77 Activation Record Format COP 4020 Programmin Language 1
Return address Return address Return address Local variables Local variables Local variables Parameters Parameters Parameters FORTRAN 77 Code and Activation Records for Subprograms A, B, and C COMMON is a mechanism used by FORTRAN 77 for referencing nonlocal variables COMMON Storage MAIN Local variables A Data B C MAIN A Code B COP 4020 Programmin Language 1 C
ALGOL (ALGOrithmic Language) ALGOL was develop in 1958 as a committee effort to design a language for the description of computing processes in publications. The objectives of the language were stated as follows: • It should be close as possible to standard mathematical notation and be readable without too much additional explanation. • It should be mechanically translate into machine code.
ALGOL 58 ALGOL 60 ALGOL 68 ALGOL W SIMULA 67 PASCAL COP 4020 Programmin Language 1
Major Concepts introduced in ALGOL(1): • Language definition: a formal definition in Backus Naur Form (BNF) was used to define the syntax for the first time; this led to syntax-directed compilers. • ALGOL 60 was structured: It was the originally block structured language and variables were not visible outside the block in which they were declared. • Arrays could have variables bounds. • Contained several structured control statements:
Major Concepts introduced in ALGOL(2): • Sequence: S1,S2,…,Sn • Selection (IF-THEN-ELSE) • Iteration (For I:= 1 step 1 until n do) • First language to introduce recursive procedures. COP 4020 Programmin Language 1
Why ALGOL 60 did not supersede FORTRAN? • Compilers came out approximately three years after Fortran. • As it had more features than Fortran it was harder to learn. • IBM customers were happy with Fortran. • Fortran compilers were simpler to produce and more efficient. • Algol 60 had not official Input/output therefore they left this feature to the individual manufacturers.
Example of an Algol program: begin comment this program finds the mean of n numbers and the number of values greater than the mean; integer n; read(n); begin real array a[1:n]; integer i, number; real sum, mean; for i := 1 step 1 until n do read(a[i]); sum := 0.0; for i := 1 step 1 until n do sum := sum + a[i]; mean := sum/n; number := 0; for i := 1 step 1 until n do if a[i] > mean then number := number + 1; write (“MEAN = “, mean, “NUMBER OVER MEAN = “, number); end; end;
ALGOL 60 ALGOL W(1966) ALGOL68 SIMULA 67 BCPL PASCAL C MODULA C++ ADA(83) OBERON Eiffel(90) ADA(95) JAVA
The successor of ALGOL 60 was ALGOL W which was proposed by Wirth and Hoare in 1966 . • The more important changes and additions were(1): • Records and references allowed linked list, trees and graphs. • The case statement. • Changes which separate “for” and “While”. • Procedures and function parameters could be passed by values and by name. • Long real and complex data type were introduced (complex arithmetic)
The successor of ALGOL 60 was ALGOL W which was proposed by Wirth and Hoare in 1966 . The more important changes and additions were(2): • The bits data type gave low-level processing ability. • Some string facilities were included. • Assert statement were allowed and the assertion tested during a program run. • Concurrent execution was implemented (B6700) COP 4020 Programmin Language 1
The next step was ALGOL 68 which amid its interesting features introduced: • An economy of constructs: produce a core language with a small number of powerful constructs. • Orthogonality: This was its major design goal. There ware no interactions between constructs when they were combined. Having determined how a feature worked in one situation, it could be expected to behave in a similar way in any other situation.
Run-time stack • The run-time stack and the activation record allows us to have more than one instance (incomplete execution) of a subprogram at a given time. • Recursion adds the possibility of multiple simultaneous activations (incomplete execution) of a subprogram at a given time. COP 4020 Programmin Language 1
Program Stack program P0; var R1, T1: real; A1: array[0:5,0:20] of real; procedure P1( X: real; var T: real; Y: array[0:5,0:20] of real; procedure P2; var R2, T2: real; A2: array[0:5,0:20] of real; begin R2 := 5; T2 := 25; P1(R2, T2, A2); /* calls P1 */ end;(* P2 *) begin P2; /* calls P2 */ end; (* P1 *) begin P1(R1, T1, A1); /* calls P1 */ end;(* program *) COP 4020 Programmin Language 1
Working space for Procedure P0, the main program Program Stack program P0; var R1, T1: real; A1: array[0:5,0:20] of real; procedure P1( X: real; var T: real; Y: array[0:5,0:20] of real; procedure P2; var R2, T2: real; A2: array[0:5,0:20] of real; begin R2 := 5; T2 := 25; P1(R2, T2, A2); /* calls P1 */ end;(* P2 *) begin P2; /* calls P2 */ end; (* P1 *) begin P1(R1, T1, A1); /* calls P1 */ end;(* program *) Activation record for P0 COP 4020 Programmin Language 1
Working space for Procedure P0, the main program Memory for variable R1 Memory for variable T1 Program Stack program P0; var R1, T1: real; A1: array[0:5,0:20] of real; procedure P1( X: real; var T: real; Y: array[0:5,0:20] of real; procedure P2; var R2, T2: real; A2: array[0:5,0:20] of real; begin R2 := 5; T2 := 25; P1(R2, T2, A2); /* calls P1 */ end;(* P2 *) begin P2; /* calls P2 */ end; (* P1 *) begin P1(R1, T1, A1); /* calls P1 */ end;(* program *) Activation record for P0 COP 4020 Programmin Language 1
Working space for Procedure P0, the main program Memory for variable T1 Pointer to elements of A1 Memory for variable R1 Program Stack program P0; var R1, T1: real; A1: array[0:5,0:20] of real; procedure P1( X: real; var T: real; Y: array[0:5,0:20] of real; procedure P2; var R2, T2: real; A2: array[0:5,0:20] of real; begin R2 := 5; T2 := 25; P1(R2, T2, A2); /* calls P1 */ end;(* P2 *) begin P2; /* calls P2 */ end; (* P1 *) begin P1(R1, T1, A1); /* calls P1 */ end;(* program *) Activation record for P0 COP 4020 Programmin Language 1
Working space for Procedure P0, the main program Memory for variable T1 Pointer to elements of A1 Memory for variable R1 Reference to procedure P1 Program Stack program P0; var R1, T1: real; A1: array[0:5,0:20] of real; procedure P1( X: real; var T: real; Y: array[0:5,0:20] of real;) procedure P2; var R2, T2: real; A2: array[0:5,0:20] of real; begin R2 := 5; T2 := 25; P1(R2, T2, A2); /* calls P1 */ end;(* P2 *) begin P2; /* calls P2 */ end; (* P1 *) begin P1(R1, T1, A1); /* calls P1 */ end;(* program *) Activation record for P0 COP 4020 Programmin Language 1
Working space for Procedure P1 Working space for Procedure P0, the main program Memory for variable T1 Pointer to elements of A1 Memory for variable R1 Reference to procedure P1 Program Stack program P0; var R1, T1: real; A1: array[0:5,0:20] of real; procedure P1( X: real; var T: real; Y: array[0:5,0:20] of real;) procedure P2; var R2, T2: real; A2: array[0:5,0:20] of real; begin R2 := 5; T2 := 25; P1(R2, T2, A2); /* calls P1 */ end;(* P2 *) begin P2; /* calls P2 */ end; (* P1 *) begin P1(R1, T1, A1); /* calls P1 */ end;(* program *) Activation record for P1 Activation record for P0 COP 4020 Programmin Language 1
Working space for Procedure P1 Memory for variable X Working space for Procedure P0, the main program Memory for variable T1 Pointer to elements of A1 Memory for variable R1 Reference to procedure P1 Program Stack program P0; var R1, T1: real; A1: array[0:5,0:20] of real; procedure P1( X: real; var T: real; Y: array[0:5,0:20] of real;) procedure P2; var R2, T2: real; A2: array[0:5,0:20] of real; begin R2 := 5; T2 := 25; P1(R2, T2, A2); /* calls P1 */ end;(* P2 *) begin P2; /* calls P2 */ end; (* P1 *) begin P1(R1, T1, A1); /* calls P1 */ end;(* program *) Activation record for P1 Activation record for P0 COP 4020 Programmin Language 1
Working space for Procedure P1 Memory for variable X Pointer to variable T1 Working space for Procedure P0, the main program Memory for variable T1 Pointer to elements of A1 Memory for variable R1 Reference to procedure P1 Program Stack program P0; var R1, T1: real; A1: array[0:5,0:20] of real; procedure P1( X: real; var T: real; Y: array[0:5,0:20] of real;) procedure P2; var R2, T2: real; A2: array[0:5,0:20] of real; begin R2 := 5; T2 := 25; P1(R2, T2, A2); /* calls P1 */ end;(* P2 *) begin P2; /* calls P2 */ end; (* P1 *) begin P1(R1, T1, A1); /* calls P1 */ end;(* program *) Activation record for P1 Activation record for P0 COP 4020 Programmin Language 1
Working space for Procedure P1 Memory for variable X Pointer to variable T1 Indirect pointer to elements of A1 Working space for Procedure P0, the main program Memory for variable T1 Pointer to elements of A1 Memory for variable R1 Reference to procedure P1 Program Stack program P0; var R1, T1: real; A1: array[0:5,0:20] of real; procedure P1( X: real; var T: real; Y: array[0:5,0:20] of real;) procedure P2; var R2, T2: real; A2: array[0:5,0:20] of real; begin R2 := 5; T2 := 25; P1(R2, T2, A2); /* calls P1 */ end;(* P2 *) begin P2; /* calls P2 */ end; (* P1 *) begin P1(R1, T1, A1); /* calls P1 */ end;(* program *) Activation record for P1 Activation record for P0 COP 4020 Programmin Language 1
Working space for Procedure P1 Memory for variable X Pointer to variable T1 Indirect pointer to elements of A1 Reference to procedure P2 Working space for Procedure P0, the main program Memory for variable T1 Pointer to elements of A1 Memory for variable R1 Reference to procedure P1 Program Stack program P0; var R1, T1: real; A1: array[0:5,0:20] of real; procedure P1( X: real; var T: real; Y: array[0:5,0:20] of real;) procedure P2; var R2, T2: real; A2: array[0:5,0:20] of real; begin R2 := 5; T2 := 25; P1(R2, T2, A2); /* calls P1 */ end;(* P2 *) begin P2; /* calls P2 */ end; (* P1 *) begin P1(R1, T1, A1); /* calls P1 */ end;(* program *) Activation record for P1 Activation record for P0 COP 4020 Programmin Language 1
Working space for Procedure P2 Working space for Procedure P1 Reference to procedure P2 Pointer to variable T1 Memory for variable X Indirect pointer to elements of A1 Pointer to elements of A1 Working space for Procedure P0, the main program Memory for variable T1 Reference to procedure P1 Memory for variable R1 Program Stack program P0; var R1, T1: real; A1: array[0:5,0:20] of real; procedure P1( X: real; var T: real; Y: array[0:5,0:20] of real;) procedure P2; var R2, T2: real; A2: array[0:5,0:20] of real; begin R2 := 5; T2 := 25; P1(R2, T2, A2); /* calls P1 */ end;(* P2 *) begin P2; /* calls P2 */ end; (* P1 *) begin P1(R1, T1, A1); /* calls P1 */ end;(* program *) Activation record for P2 Activation record for P1 Activation record for P0 COP 4020 Programmin Language 1
Working space for Procedure P1 Reference to procedure P2 Indirect pointer to elements of A1 Pointer to variable T1 Memory for variable X Memory for variable R1 Pointer to elements of A1 Reference to procedure P1 Working space for Procedure P0, the main program Memory for variable T1 Program Stack program P0; var R1, T1: real; A1: array[0:5,0:20] of real; procedure P1( X: real; var T: real; Y: array[0:5,0:20] of real;) procedure P2; var R2, T2: real; A2: array[0:5,0:20] of real; begin R2 := 5; T2 := 25; P1(R2, T2, A2); /* calls P1 */ end;(* P2 *) begin P2; /* calls P2 */ end; (* P1 *) begin P1(R1, T1, A1); /* calls P1 */ end;(* program *) Working space for Procedure P2 Activation record for P2 Memory for the variable T2 Memory for the variable R2 Activation record for P1 Activation record for P0 COP 4020 Programmin Language 1