COP 4020 Programming Languages I

84
COP 4020 Programmin Langu age 1 COP 4020 Programming Languages I Euripides Montagne University of Central Florida (Summer 2009)

description

COP 4020 Programming Languages I. Euripides Montagne University of Central Florida (Summer 2009). 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 - PowerPoint PPT Presentation

Transcript of COP 4020 Programming Languages I

Page 1: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

COP 4020 Programming Languages I

Euripides Montagne

University of Central Florida

(Summer 2009)

Page 2: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

Outline

1. Course Organization

2. Why studying programming languages?

Page 3: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

Instructor: Euripides Montagne

Tele.: 823-2684

email: [email protected] Office hours: MT from 2:30 p.m. to 4:00 p.m. (HEC 217)

W from 11:00 a.m. to 11:50 a.m. (HEC 217)

Who am I and where to find me?

COP 4020 Programming Language I

Page 4: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

Lecture meetings: MW 12:00 p.m. – 1:50 p.m.(HEC 103 )

Web page: http://www.cs.ucf.edu/courses/cop3402/sum2009/

COP 4020 Programming Language I

Course information

Page 5: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

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 Programming Language I

Course outline

Page 6: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

Grading Policy: (15%) Exam #1 (15%) Exam #2(15%) Exam #3 (25%) Final Exam (30%) Programming project.

“Late assignments will not be accepted”

COP 4020 Programming Language I Course outline (continued)

Page 7: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

Material: Required textbook: Concepts, Techniques, and Models of Computer Programming, P. van Roy and S. Haridi, MITpress, 2004, ISBN: 0-262-22069-5.

Other recommended source:Concepts of Programming Languages, 9th Edition, Robert W. Sebesta, Addison Wesley, 2010, ISBN: 0-13-607347-6

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/sum2009/

COP 4020 Programming Language I

Course outline (continued)

Page 8: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

COP 4020 Programming Language I

Who are your TAs?

Page 9: COP 4020  Programming Languages I

Lecture 1

History of Programming Languages

UNIVERSITY OF CENTRAL FLORIDA

Page 10: COP 4020  Programming Languages I

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.

Page 11: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

ASSEMBLERS

The earliest programming languages were oriented to control the behavior of computers. They reflected the structure of the underlying machine.

This view point change 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 allof them.

Page 12: COP 4020  Programming Languages I

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.

Page 13: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

PUNCH CARD

                                                                                    

                                                                                                                                                                                                          

                      

Page 14: COP 4020  Programming Languages I

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

Page 15: COP 4020  Programming Languages I

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

Page 16: COP 4020  Programming Languages I

Example of a Fortran ProgramC FORTRAN PROGRAM TO FIND MEAN OF N NUMBERS C AND NUMBER OF VALUES GREATER THAN MEAN

DIMENSION A(99)REAL MEANREAD (1,5)N

5 FORMAT (I2)READ (1,10) (A(I), I=1, N)

10 FORMAT (6F10.5)SUM = 0.0DO 15 I=1, N

15 SUM = SUM + A(I)MEAN = SUM/FLOAT(N)NUMBER = 0DO 20 I=1, NIF (A(I).LE.MEAN) GOTO 20NUMBER = NUMBER + 1

20 CONTINUEWRITE (2,25) MEAN, NUMBER

25 FORMAT (8H MEAN = , F10.5, 5X, 20H NUMBER OVER MEAN = , I5)STOPEND.

Page 17: COP 4020  Programming Languages I

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)

Page 18: COP 4020  Programming Languages I

FORTRAN 77:

• Offers features that are common to modern programming languages:

• Records• Modules• Pointers• Subprograms can be recursive

FORTRAN 90:

• IF-THEN-ELSE

Page 19: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

FORTRAN 95:

• FOR ALL construct to aid vectorization

FORTRAN 2003:• Object-oriented programming

• IEEE floating-point arithmetic

Page 20: COP 4020  Programming Languages I

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

Page 21: COP 4020  Programming Languages I

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>, …

Page 22: COP 4020  Programming Languages I

Example: COMMON/ Globalvar/X/Y/A(20)

program main real X, Ycommon /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, Ycommon /BLK/ X, Y statements return end

Page 23: COP 4020  Programming Languages I

System data and I/O buffers

Code and local data for main program

Code and local data for sub1

Code and local data for sub2

BLK (common block)

System I/O routine

FORTRAN Memory layout

Page 24: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

Implementing FORTRAN 77 Subprograms

Activation Record

Page 25: COP 4020  Programming Languages I

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.

Page 26: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

FORTRAN 77 Activation Record Format

Return address

Local variables

Parameters

Page 27: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

FORTRAN 77 Code and Activation Records for Subprograms A, B, and C

Return address

Local variables

Parameters

Return address

Local variables

Parameters

Return address

Local variables

Parameters

Local variables

COMMON Storage

COMMON is a mechanism used by FORTRAN 77 for

referencing nonlocal variables

MAIN

A

B

C

MAIN

A

B

C

Code

Data

Page 28: COP 4020  Programming Languages I

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.

Page 29: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

ALGOL 58

ALGOL 60

ALGOL 68 ALGOL W SIMULA 67

PASCAL

Page 30: COP 4020  Programming Languages I

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:

Page 31: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

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.

Page 32: COP 4020  Programming Languages I

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.

Page 33: COP 4020  Programming Languages I

Example of an Algol program:begincomment 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 thennumber := number + 1;

write (“MEAN = “, mean, “NUMBER OVER MEAN = “, number); end;end;

Page 34: COP 4020  Programming Languages I

ALGOL 60

ALGOL W(1966) ALGOL68 SIMULA 67 BCPL

PASCAL C

MODULA C++

ADA(83)

OBERON Eiffel(90)

ADA(95) JAVA

Page 35: COP 4020  Programming Languages I

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)

Page 36: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

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)

Page 37: COP 4020  Programming Languages I

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.

Page 38: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

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.

Page 39: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

program P0;var

R1, T1: real;A1: array[0:5,0:20] of real;

 procedure P1(

X: real;

varT: real;Y: array[0:5,0:20] of real;

 procedure P2;

varR2, T2: real;A2: array[0:5,0:20] of real;

beginR2 := 5;T2 := 25;P1(R2, T2, A2); /* calls P1 */

end;(* P2 *) 

beginP2; /* calls P2 */

end; (* P1 *) 

beginP1(R1, T1, A1); /* calls P1 */

end;(* program *)

Program Stack

Page 40: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

program P0;var

R1, T1: real;A1: array[0:5,0:20] of real;

 procedure P1(

X: real;

varT: real;Y: array[0:5,0:20] of real;

 procedure P2;

varR2, T2: real;A2: array[0:5,0:20] of real;

beginR2 := 5;T2 := 25;P1(R2, T2, A2); /* calls P1 */

end;(* P2 *) 

beginP2; /* calls P2 */

end; (* P1 *) 

beginP1(R1, T1, A1); /* calls P1 */

end;(* program *)

Program Stack

Working space for Procedure P0, the main program

Activation record for

P0

Page 41: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

program P0;var

R1, T1: real;A1: array[0:5,0:20] of real;

 procedure P1(

X: real;

varT: real;Y: array[0:5,0:20] of real;

 procedure P2;

varR2, T2: real;A2: array[0:5,0:20] of real;

beginR2 := 5;T2 := 25;P1(R2, T2, A2); /* calls P1 */

end;(* P2 *) 

beginP2; /* calls P2 */

end; (* P1 *) 

beginP1(R1, T1, A1); /* calls P1 */

end;(* program *)

Program Stack

Working space for Procedure P0, the main program

Memory for variable R1

Memory for variable T1

Activation record for

P0

Page 42: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

program P0;var

R1, T1: real;A1: array[0:5,0:20] of real;

 procedure P1(

X: real;

varT: real;Y: array[0:5,0:20] of real;

 procedure P2;

varR2, T2: real;A2: array[0:5,0:20] of real;

beginR2 := 5;T2 := 25;P1(R2, T2, A2); /* calls P1 */

end;(* P2 *) 

beginP2; /* calls P2 */

end; (* P1 *) 

beginP1(R1, T1, A1); /* calls P1 */

end;(* program *)

Program Stack

Working space for Procedure P0, the main program

Memory for variable T1

Pointer to elements of A1

Memory for variable R1

Activation record for

P0

Page 43: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

program P0;var

R1, T1: real;A1: array[0:5,0:20] of real;

 procedure P1(

X: real;

varT: real;Y: array[0:5,0:20] of real;)

 procedure P2;

varR2, T2: real;A2: array[0:5,0:20] of real;

beginR2 := 5;T2 := 25;P1(R2, T2, A2); /* calls P1 */

end;(* P2 *) 

beginP2; /* calls P2 */

end; (* P1 *) 

beginP1(R1, T1, A1); /* calls P1 */

end;(* program *)

Program Stack

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 Activation record for

P0

Page 44: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

program P0;var

R1, T1: real;A1: array[0:5,0:20] of real;

 procedure P1(

X: real;

varT: real;Y: array[0:5,0:20] of real;)

 procedure P2;

varR2, T2: real;A2: array[0:5,0:20] of real;

beginR2 := 5;T2 := 25;P1(R2, T2, A2); /* calls P1 */

end;(* P2 *) 

beginP2; /* calls P2 */

end; (* P1 *) 

beginP1(R1, T1, A1); /* calls P1 */

end;(* program *)

Program Stack

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

Working space for Procedure P1

Activation record for

P0

Activation record for

P1

Page 45: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

program P0;var

R1, T1: real;A1: array[0:5,0:20] of real;

 procedure P1(

X: real;

varT: real;Y: array[0:5,0:20] of real;)

 procedure P2;

varR2, T2: real;A2: array[0:5,0:20] of real;

beginR2 := 5;T2 := 25;P1(R2, T2, A2); /* calls P1 */

end;(* P2 *) 

beginP2; /* calls P2 */

end; (* P1 *) 

beginP1(R1, T1, A1); /* calls P1 */

end;(* program *)

Program Stack

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

Working space for Procedure P1

Memory for variable X

Activation record for

P0

Activation record for

P1

Page 46: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

program P0;var

R1, T1: real;A1: array[0:5,0:20] of real;

 procedure P1(

X: real;

varT: real;Y: array[0:5,0:20] of real;)

 procedure P2;

varR2, T2: real;A2: array[0:5,0:20] of real;

beginR2 := 5;T2 := 25;P1(R2, T2, A2); /* calls P1 */

end;(* P2 *) 

beginP2; /* calls P2 */

end; (* P1 *) 

beginP1(R1, T1, A1); /* calls P1 */

end;(* program *)

Program Stack

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

Working space for Procedure P1

Memory for variable X

Pointer to variable T1

Activation record for

P0

Activation record for

P1

Page 47: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

program P0;var

R1, T1: real;A1: array[0:5,0:20] of real;

 procedure P1(

X: real;

varT: real;Y: array[0:5,0:20] of real;)

 procedure P2;

varR2, T2: real;A2: array[0:5,0:20] of real;

beginR2 := 5;T2 := 25;P1(R2, T2, A2); /* calls P1 */

end;(* P2 *) 

beginP2; /* calls P2 */

end; (* P1 *) 

beginP1(R1, T1, A1); /* calls P1 */

end;(* program *)

Program Stack

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

Working space for Procedure P1

Memory for variable X

Pointer to variable T1

Indirect pointer to elements of A1

Activation record for

P0

Activation record for

P1

Page 48: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

program P0;var

R1, T1: real;A1: array[0:5,0:20] of real;

 procedure P1(

X: real;

varT: real;Y: array[0:5,0:20] of real;)

 procedure P2;

varR2, T2: real;A2: array[0:5,0:20] of real;

beginR2 := 5;T2 := 25;P1(R2, T2, A2); /* calls P1 */

end;(* P2 *) 

beginP2; /* calls P2 */

end; (* P1 *) 

beginP1(R1, T1, A1); /* calls P1 */

end;(* program *)

Program Stack

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

Working space for Procedure P1

Memory for variable X

Pointer to variable T1

Indirect pointer to elements of A1

Reference to procedure P2

Activation record for

P0

Activation record for

P1

Page 49: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

program P0;var

R1, T1: real;A1: array[0:5,0:20] of real;

 procedure P1(

X: real;

varT: real;Y: array[0:5,0:20] of real;)

 procedure P2;

varR2, T2: real;A2: array[0:5,0:20] of real;

beginR2 := 5;T2 := 25;P1(R2, T2, A2); /* calls P1 */

end;(* P2 *) 

beginP2; /* calls P2 */

end; (* P1 *) 

beginP1(R1, T1, A1); /* calls P1 */

end;(* program *)

Program Stack

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

Working space for Procedure P2

Activation record for

P0

Activation record for

P1

Activation record for

P2

Working space for Procedure P1

Memory for variable X

Pointer to variable T1

Indirect pointer to elements of A1

Reference to procedure P2

Page 50: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

program P0;var

R1, T1: real;A1: array[0:5,0:20] of real;

 procedure P1(

X: real;

varT: real;Y: array[0:5,0:20] of real;)

 procedure P2;

varR2, T2: real;A2: array[0:5,0:20] of real;

beginR2 := 5;T2 := 25;P1(R2, T2, A2); /* calls P1 */

end;(* P2 *) 

beginP2; /* calls P2 */

end; (* P1 *) 

beginP1(R1, T1, A1); /* calls P1 */

end;(* program *)

Program Stack

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

Working space for Procedure P2

Memory for the variable R2

Memory for the variable T2

Activation record for

P0

Activation record for

P1

Activation record for

P2

Working space for Procedure P1

Memory for variable X

Pointer to variable T1

Indirect pointer to elements of A1

Reference to procedure P2

Page 51: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

program P0;var

R1, T1: real;A1: array[0:5,0:20] of real;

 procedure P1(

X: real;

varT: real;Y: array[0:5,0:20] of real;)

 procedure P2;

varR2, T2: real;A2: array[0:5,0:20] of real;

beginR2 := 5;T2 := 25;P1(R2, T2, A2); /* calls P1 */

end;(* P2 *) 

beginP2; /* calls P2 */

end; (* P1 *) 

beginP1(R1, T1, A1); /* calls P1 */

end;(* program *)

Program Stack

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

Working space for Procedure P2

Memory for the variable R2

Memory for the variable T2

Pointer to the elements of A2

Activation record for

P0

Activation record for

P1

Activation record for

P2

Working space for Procedure P1

Memory for variable X

Pointer to variable T1

Indirect pointer to elements of A1

Reference to procedure P2

Page 52: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

Stack state while P2 is executing

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

Working space for Procedure P2

Memory for the variable R2

Memory for the variable T2

Pointer to the elements of A2

Activation record for

P0

Activation record for

P1

Activation record for

P2

P1 code

Elements of array A1

Working space for Procedure P1

Memory for variable X

Pointer to variable T1

Indirect pointer to elements of A1

Reference to procedure P2 P2 code

Elements of array A2

Page 53: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

FORTRAN 0 Flow-Matic (Grace Hopper-57)

FORTRAN I(1957) COBOL(1960) ALGOL 58

FORTRAN II ALGOL 60

FORTRAN IV

PL/1(1964) BASIC

FORTRAN 66

FORTRAN 77

FORTRAN 90

Page 54: COP 4020  Programming Languages I

COBOL (Common Business Oriented Language)

COBOL was based on the Flow-Matic language(1957), developed by Grace Hopper, and IBM's specification of its planned Commercial Translator.

COBOL is essentially a data processing language and that is the reason why it differs significantly from FORTRAN and ALGOL.

Several design principles guided the design of COBOL

– separate data & procedures– machine dependent statements in one place– Naturalness (English-like form)– ease of transcription to require media (cards at the time)– effectiveness of problem structure– ease of implementation (for compiler writers)– physically available character set (printable)– long data names

Page 55: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

COBOL-60 (First Compiler – Only Three DIVISIONS)

COBOL-68 (standardized version - (ANSI ) American National Standards Institute)

COBOL-74 (revisions to improve COBOL-68 and interaction with remote devices )

COBOL-85 (facilities for structured programming - DB2 and SQL support)

COBOL 2002 (Object Oriented Programming)

Page 56: COP 4020  Programming Languages I

Main features:

• The language is simple

• No pointers

• No user defined types

• Record data type

• Self documented

Page 57: COP 4020  Programming Languages I

A COBOL program is divided in four parts or divisions:

Division Name Contains• IDENTIFICATION Program identification.

• ENVIRONMENT Type of computer used.

• DATA Buffers, constants, work areas.

• PROCEDURE The processing (program logic).

Page 58: COP 4020  Programming Languages I

A COBOL program is divided in four parts:

• The identification division: Contains commentary and program documentation. 000100 INDENTIFICATION DIVISION.

000110 PROGRAM-ID. EXAMPLE-1-PROG.000120 AUTHOR. TIM R P BROWN.000130 INSTALLATION. XYZ GROUP.000140 DATE-WRITTEN. 5/15/06.000150 DATE-COMPILED.000160 SECURITY. LOCAL GROUP

Page 59: COP 4020  Programming Languages I

• The environment division: Contain machine-dependent program specifications. Thus, it specifies the connections between the COBOL program and the external data file.

000260 ENVIRONMENT DIVISION. 000270 CONFIGURATION SECTION. 000280 SOURCE-COMPUTER. IBM PC. 000290 OBJECT-COMPUTER. IBM PC. 000300 INPUT-OUTPUT SECTION.

000310 FILE-CONTROL.000320 SELECT INPUT-FILE ASSIGN TO 'input.dat‘000330 ORGANIZATION IS LINE SEQUENTIAL.000340 SELECT PRINT-FILE ASSIGN TO PRINTER.

Page 60: COP 4020  Programming Languages I

The data division: Gives a logical description of the data.000800 DATA DIVISION.000900 FILE SECTION.001000 FD SALESPERSON-FILE.001100 01 SALESPERSON-RECORD.001200 05 FILLER PIC XX.001300 05 SP-NUMBER PIC X(4).001400 05 SP-NAME PIC X(18).001500 05 FILLER PIC X(21).001600 05 SP-CURRENT-SALES PIC 9(5)V99.001700 05 SP-CURRENT-RETURNS PIC 9(4)V99.001800 FD REPORT-FILE.001900 01 REPORT-RECORD.002000 05 FILLER PIC X(10).002100 05 RT-NUMBER PIC X(4).002200 05 FILLER PIC X(6).002300 05 RT-NAME PIC X(18).002400 05 FILLER PIC X(6).002500 05 RT-CURRENT-SALES PIC ZZ,ZZZ.99.002600 05 FILLER PIC X(6).002700 05 RT-CURRENT-RETURNS PIC Z,ZZZ.99.002800 05 FILLER PIC X(65).002900 WORKING-STORAGE SECTION.003000 01 WS-EOF-FLAG PIC X.

Page 61: COP 4020  Programming Languages I

• The procedure division: Contains the algorithms necessary to solve the problem. 000900 PROCEDURE DIVISION.

000910 CONTROL-PARAGRAPH.000920 PERFORM READ-DATA-FILE000930 PERFORM CALULATE-PRICES000940 PERFORM PRINT-PRICE-REPORT000950 STOP RUN.

Page 62: COP 4020  Programming Languages I

Example of a COBOL program(Hello world):

000010 IDENTIFICATION DIVISION.000020 PROGRAM-ID. HELLO-WORLD-PROG.000030 AUTHOR. TIMOTHY R P BROWN.000040*The standard Hello world program000050 000060 ENVIRONMENT DIVISION.000070 000080 DATA DIVISION.000090 WORKING-STORAGE SECTION.000100 01 TEXT-OUT PIC X(12) VALUE 'Hello World!'.000110 000120 PROCEDURE DIVISION.000130 MAIN-PARAGRAPH.000140 DISPLAY TEXT-OUT000150 STOP RUN.

Page 63: COP 4020  Programming Languages I

Example program 2: 000100 ID DIVISION. 000200 PROGRAM-ID. ACCEPT1. 000300 DATA DIVISION. 000400 WORKING-STORAGE SECTION. 000500 01 WS-FIRST-NUMBER PIC 9(3). 000600 01 WS-SECOND-NUMBER PIC 9(3). 000700 01 WS-TOTAL PIC ZZZ9. 000800* 000900 PROCEDURE DIVISION. 001000 0000-MAINLINE. 001100 DISPLAY 'ENTER A NUMBER: '. 001200 ACCEPT WS-FIRST-NUMBER. 001300* 001400 DISPLAY 'ANOTHER NUMBER: '. 001500 ACCEPT WS-SECOND-NUMBER. 001600* 001700 COMPUTE WS-TOTAL = WS-FIRST-NUMBER + WS-SECOND-

NUMBER. 001800 DISPLAY 'THE TOTAL IS: ', WS-TOTAL. 001900 STOP RUN.

Page 64: COP 4020  Programming Languages I

Some basic commands to be used in the Procedure Division:

MOVE zero to I, J, K ADD a TO b.ADD c TO a GIVING c. COMPUTE x = a + b * c.SORT input-file ON ASCENDING KEY k

USING inventory-file GIVING sorted-inventory-file

DISPLAY totalcost.ACCEPT identifier.

Page 65: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

000020 IDENTIFICATION DIVISION.000040 PROGRAM-ID. MEAN.000060 AUTHOR. JOHN DOE.000080 * Program to find the mean and number of values greater than the mean000100000120 DATA DIVISION.000140 000160 WORKING-STORAGE SECTION.000180 01 N PIC 999 VALUE ZEROS.000200 01 I PIC 999 VALUE ZEROS.000220 01 NUMBER PIC 999 VALUE ZEROS.000240 01 MEAN PIC 999V999 VALUE ZEROS.000260 01 SUM PIC 999V999 VALUE ZEROS.000280 01 A PIC 999V999 OCCURS 100 TIMES VALUE ZEROS.000300000320000340 PROCEDURE DIVISION.000360000380 DISPLAY "ENTER NUMBER OF ARRAY ELEMENTS: ".000400 ACCEPT N.000420000440 ENTER-NUMBER.000460 ADD 1 TO I.000480 DISPLAY "ENTER NUMBER: ".000500 ACCEPT A(I).000520 IF I < N GO ENTER-NUMBER.000540 MOVE 0 TO I.000560 GO SUM-NUMBER.000580000600 SUM-NUMBERS.000620 ADD 1 TO I.000640 COMPUTE SUM = SUM + A(I).000680 IF I < N GO SUM-NUMBERS.000700 COMPUTE MEAN = SUM / N.000720 MOVE 0 TO I.000740 GO GREATER-NUMBER.000760000780 GREATER-NUMBER.000800 ADD 1 TO I.000820 IF A(I) > MEAN ADD 1 TO NUMBER.000840 IF I < N GO GREATER-NUMBER.000860 GO OEJ.000880 000900 EOJ.000920 DISPLAY "MEAN = ", MEAN.000940 DISPLAY "NUMBER OVER MEAN = ", NUMBER.000960 STOP RUN.000980001000

Page 66: COP 4020  Programming Languages I

COBOL continues to progress with work beingCOBOL continues to progress with work being

done in the Object-Oriented COBOL standard.done in the Object-Oriented COBOL standard.

Page 67: COP 4020  Programming Languages I

PROGRAMMING LANGUAGE 1 (PL/1)

In the early 1960s two categories of programmers could be distinguished:

Scientific programmers (Fortran)

Commercial programmers (COBOL)

A committee at IBM developed PL/1 based in the following principles:– Programmers’ time is an important asset and should not

be wasted.– There is a unity in programming which current division

between scientific and commercial languages did not reflect.

Page 68: COP 4020  Programming Languages I

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

Page 69: COP 4020  Programming Languages I

PROGRAMMING LANGUAGE 1 (PL/1) (Cont.)

Pl/1 combined ideas from Fortran, Algol, and COBOL:

FORTRAN: parameter passing mechanism, independently compiled subprograms, formatted input/output and COMMON blocks.

ALGOL: Block structure and structured statements.

COBOL: record input/output,, PICTURE type declaration, and heterogeneous data structures.

From elsewhere: list processing concepts, control structures and methods for storage management, exception handling by means of “ON-conditions” and concurrent execution of tasks (multi-tasking).

Page 70: COP 4020  Programming Languages I

Example of a PL/1 program:PROCEDURE OPTIONS (MAIN)/* Program to find the mean of n numbers and the number of values greater than the

mean */GET LIST (N)IF N > 0 THEN BEGIN;

DECLARE MEAN, A(n) DECIMAL FLOAT,SUM DEC FLOAT INITIAL(0), NUMBER FIXED INITIAL (0);

GET LIST (A);DO I = 1 TO N;

SUM = SUM + A(1); END;

MEAN = SUM/N;DO I = 1 TO N;

IF A(I) > MEAN THEN NUMBER = NUMBER +1;

END; PUT LIST (‘MEAN=’, MEAN, ‘NUMBER GRATER THAN MEAN=’, NUMBER);END;

Page 71: COP 4020  Programming Languages I

BASIC (Beginner’s All-purpose Symbolic Instruction Code)

It was originally designed at Dartmouth College by John Kemeny and Thomas Kurtz in the mid-1960s.

Page 72: COP 4020  Programming Languages I

FORTRAN 0

FORTRAN I(1957) COBOL(1960) ALGOL 58

FORTRAN II ALGOL 60

FORTRAN IV

PL/1(1964)

FORTRAN 66 BASIC(mid 60s)

FORTRAN 77

FORTRAN 90

Page 73: COP 4020  Programming Languages I

Main Features:

• Variables cannot be declared and are single letters.

• Variables are initialized to zero

• Easy to learn and use.

• It was interactive with commands as NEW to create a program or LIST, RUN, and SAVE.

Page 74: COP 4020  Programming Languages I

Example of BASIC program:10 REM THIS IS A BASIC PROGRAM FOR FINDING THE MEAN20 DIM A(99)30 INPUT N40 FOR I = 1 TO N50 INPUT A(I)60 LET S = S + A(I)70 NEXT I80 LET M = S/N90 LET K = 0100 FOR I = 1 TO N110 IF A(I) < M THEN 130120 LET K = K + 1130 NEXT I140 PRINT “MEAN IS”, M150 PRINT “NUMBER GREATER THAN MEAN IS”, K160 STOP170 END

Page 75: COP 4020  Programming Languages I

ALGOL COBOL

ALGOL 68 ALGOL W PL/1

PASCAL

ADA

Page 76: COP 4020  Programming Languages I

Pascal

• It was designed by Niklaus Wirth.• A teaching language• The language most used in the 1970s• Include run time environment (code, static

data, stack … heap)• It uses the concept of static array like in

Fortran.• New data types(define by the user) can be

built up from primitive data types.

Page 77: COP 4020  Programming Languages I

Object code

Static Data

Stack

Heap

Run time environment for:

Pascal

C

Ada

Java

Page 78: COP 4020  Programming Languages I

Example of a Pascal Program:• (*Pascal program for finding the mean*)• Program main (input, output);• type intlist = array [1 . . 99] of integer;• var• a : intlist;• i, n, number : integer;• sum, mean : real;• (*main program starts here *)• begin• number := 0;• sum := 0;• readln (n);• for I := 1 to n do• begin• readln(a[i]);• sum := sum + a[i]• end;• mean := sum/n;• for I := 1 to n do• if (a[i] > mean) then number := number + 1;• writeln (‘the number over mean is: ‘, number)• end.

Page 79: COP 4020  Programming Languages I

Outgoing results

Result of I / K

Address of x [ i ]

Result of I + J

Local Variables

Example for “temporary expression”

x[ i ] = (I + J) * (I/J + f( J ))

Static Link Dynamic Link

Formal Parameter

RA

SP

SF

Activation Record

(Stack Frame)

(Stack Pointer)

Page 80: COP 4020  Programming Languages I

Some comments of N. Wirth about language design

“Power of a language lies in its regularity and not in its abundant of Features”

“Character of a language is defined by what it prevents more than by what it allows to be expressed”

Page 81: COP 4020  Programming Languages I

C

Implemented by Dennis Ritchie in 1972

system programming

c – 1972

c – 1989 (ANSI)

c – 1992 (ISO)

Page 82: COP 4020  Programming Languages I

ALGOL 60

ALGOL W(1966) ALGOL68 SIMULA 67 BCPL

PASCAL C(1972)

MODULA C++

ADA(83)

OBERON Eiffel(90)

ADA(95) JAVA

Page 83: COP 4020  Programming Languages I

An Example of a C Program:/*C program for finding the mean*/main(){float a[100], mean, sum;/* the array a has 100 elements – a[0], .. a[99] */int n, i, number;scanf(“%d”, &n);for( i = 0; i < n; ++i)

scanf(“%f”, &a[ i ]);sum = 0.0;for( i = 0; i < n; ++i)

sum += a[ i ];mean = sum / n;number = 0;for( i = 0; i < n; ++i){

if( a[ i ] > mean)number++;

}printf(“ MEAN = %f \n”, mean);printf(“NUMBER OVER MEAN = %d\n”, number);}

* No nested procedures are allowed

Page 84: COP 4020  Programming Languages I

COP 4020 Programmin Language 1

COP 4020 Programming Languages I

THE END