CS代考计算机代写 Java AI scheme algorithm computer architecture Fortran javascript data structure concurrency Haskell assembly PowerPoint Presentation

PowerPoint Presentation

© M. Winter
COSC 2P05 – Programming languages
1.*

COSC 2P05
Programming Languages
Instructor:
Michael Winter
Office: MCC J323
Email: mwinter@brocku.ca
Lecture: Mon & Thu, 14:00-15:30 online in Lifesize
Course web page: www.cosc.brocku.ca/~mwinter/Courses/2P05/
Textbook:

Sebesta, Robert W.
Concepts of Programming Languages (12th edition)
Pearson, 2019
ISBN: 9780135102268

*

© M. Winter
COSC 2P05 – Programming languages
1.*

Course Work
Marking Scheme
Midterm 1 Feb 11, 14:00-15:30 20%
Midterm 2 Mar 18, 14:00-15:30 20%
Final Exam Apr 12, 13:00-15:00 60%

Both tests and the final exam will be online in Lifesize during the regular lecture time.

© M. Winter
COSC 2P05 – Programming languages
1.*

Course Outline
* Feb 15-19 is Reading Week.
Week Date Chapter Topic
1 Jan 11/14 1, 2 Introduction, Evolution of programming languages
2 Jan 18/21 2 Evolution of programming languages
3 Jan 25/28 5, 6 Names, Bindings, Scope, Data types
4 Feb 01/04 6, 7 Data types, Expressions and assignments
5 Feb 08/11 8 Control structures (Midterm 1)
6* Feb 22/25 9, 10 Subprograms
7 Mar 01/04 11 Abstract data type
8 Mar 08/11 12 Object-oriented languages
9 Mar 15/18 13 Concurrency (Midterm 2)
10 Mar 22/25 15 Functional programming languages
11 Mar 29/Apr 01 15, 16 Functional programming languages, Logic programming languages
12 Apr 05/08 16 Logic programming languages, Review

© M. Winter
COSC 2P05 – Programming languages
1.*

Why Studying Programming Languages
Increased capacity to express ideas
Implementation of concepts learnt in another language that is not available in the given language
Improve background for choosing appropriate language
Knowing only one or two languages leads to using these languages even for problems they are poorly suited for
Increased ability to learn new languages
Knowing the fundamental concepts of programming languages makes it easy to learn new languages
Better understanding of the significance of implementation
Understanding concepts and their implementation allows using the language more intelligently; certain bugs can only be found if certain implementation details are known
Better use of languages that are already known
Knowing fundamental concepts may lead to use previously unknown (or unused) feature of a language
Overall advancement of computing
Better understanding of programming languages in the community leads to better lanaguages

© M. Winter
COSC 2P05 – Programming languages
1.*

Programming Domains
Scientific applications
Main domain in the early days of computing (FORTAN)
Business applications
Facilities needed: Reports, Various (precise) decimal numbers and operations, character data (COBOL)
Artificial Intelligence
Symbolic computation and lists (LISP)
System programming
Low-level features (PL I, C)
Web software
Dynamic web content, scripting (JavaScript, PHP)

© M. Winter
COSC 2P05 – Programming languages
1.*

Language Evaluation Criteria
Readability
How easy is it to understand a given program?
Early languages focused on machine readability rather than programmer readability
Important for maintenance and extension
Has to be considered in the context of the problem domain
Writability
How easy is it to write a program for a chosen problem?
Has to be considered in the context of the problem domain
Reliability
A program is reliable if it performs to its specification under all conditions
Program correctness

© M. Winter
COSC 2P05 – Programming languages
1.*

Language Evaluation Criteria

© M. Winter
COSC 2P05 – Programming languages
1.*

Readability
Simplicity
A language with a large number of basic constructs is more difficult to learn
Feature multiplicity
Operator overloading
Simplicity vs. high-level language
Orthogonality
Small number of primitive constructs can be combined in a small number of ways, each combination is legal and meaningful
Independent of context
Data types
Adequate data types are available, e.g., Booleans
Syntax Design
Identifier forms, special words, form and meaning

© M. Winter
COSC 2P05 – Programming languages
1.*

Writability
Simplicity
Misuse of unknown features
Orthogonality
Low orthogonality requires to memorize a lot of exceptions
Errors can go undetected if nearly all combinations of primitives are legal
Data types and Syntax design
See Readability
Support for abstraction
Ability to define and use structures in ways that allow many details to be ignored
Process abstraction: subprograms, polymorphism
Data abstraction: interfaces, references, recursive data types
Expressivity
Powerful but convenient constructions

© M. Winter
COSC 2P05 – Programming languages
1.*

Reliability
Simplicity, Orthogonality, Data types, Syntax design, Support for abstraction and Expressivity
See Readability and/or Writability
Type checking
Simple test for type errors
Compile-time: more desirable, detect before run
Errors at run-time: costly and errors might not be detected
Exception handling
Intercept run-time errors
Aliasing
Two or more distinct names accessing the same memory cell
Dangerous feature

© M. Winter
COSC 2P05 – Programming languages
1.*

Influences on Language Design
Computer Architecture

Program Design Methodologies
Top-down design and stepwise refinement
Procedure-oriented vs. data-oriented
Language Categories
Imperative languages
Object-oriented languages
Visual languages
Logic programming languages
Functional programming languages

© M. Winter
COSC 2P05 – Programming languages
1.*

Implementation Methods
Compilation
Interpretation
Hybrid System

© M. Winter
COSC 2P05 – Programming languages
1.*

Compilation

© M. Winter
COSC 2P05 – Programming languages
1.*

Pure Interpretation

© M. Winter
COSC 2P05 – Programming languages
1.*

Hybrid Systems

© M. Winter
COSC 2P05 – Programming languages
1.*

Zuse’s Plankalkül
Developed in 1943-45 as part of his PhD
First published in 1972
Data types: bit, integer, floating-point type, arrays, records
For and while loops, no goto
Includes assertions, i.e., mathematical expressions that would be true during execution at the point in the code
Two-dimensional syntax

| A + 1 => A
V | 4 5
S | 1.n 1.n
Evolution of Programming Languages

© M. Winter
COSC 2P05 – Programming languages
1.*

© M. Winter
COSC 2P05 – Programming languages
1.*

FORTRAN
FORmula TRANslating system
First generally available heigh-level language
Goals
Reduce development & debugging costs
Efficient compilation
Features
Comments
No data-typing statements (implicit type convention)
Mathematical notation
Looping statement (DO)
Subroutines & functions
I/O formatting
Machine independence
but no standard

© M. Winter
COSC 2P05 – Programming languages
1.*

Reasons for success of FORTRAN
Easy to learn compared to assembly language/machine code
Supported by IBM
Most users and applications at the time were scientific
Simplified tedious tasks, e.g. I/O
FORTRAN IV, 77, 90, 95, 2003, 2008, 2018
Type declarations for variables
If construct
Subprograms as parameters
Dynamic arrays, pointers
Modules
Support for object-orientation

© M. Winter
COSC 2P05 – Programming languages
1.*

FORTRAN Program
C FORTRAN PROGRAM TO FIND MEAN OF N NUMBERS AND
C NUMBER OF VALUES GREATER THAN THE 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

© M. Winter
COSC 2P05 – Programming languages
1.*

! Fortran 95 Example program
! Input: An integer, List_Len, where List_Len is less
! than 100, followed by List_Len-Integer values
! Output: The number of input values that are greater
! than the average of all input values
Implicit none
Integer Dimension(99) :: Int_List
Integer :: List_Len, Counter, Sum, Average, Result
Result= 0
Sum = 0
Read *, List_Len
If ((List_Len > 0) .AND. (List_Len < 100)) Then ! Read input data into an array and compute its sum Do Counter = 1, List_Len Read *, Int_List(Counter) Sum = Sum + Int_List(Counter) End Do Fortran 95 Program © M. Winter COSC 2P05 – Programming languages 1.* ! Compute the average Average = Sum / List_Len ! Count the values that are greater than the average Do Counter = 1, List_Len If (Int_List(Counter) > Average) Then
Result = Result + 1
End If
End Do
! Print the result
Print *, ‘Number of values > Average is:’, Result
Else
Print *, ‘Error – list length value is not legal’
End If
End Program Example

© M. Winter
COSC 2P05 – Programming languages
1.*

BASIC (Beginner’s All Purpose Symbolic Instruction Code)
Designed as a language for liberal arts students in 1963, based on FORTRAN
Goals
Easy to learn for nonscience students
“Pleasant and friendly”
Fast turnaround for homework (Timesharing systems)
Allow free and private access
Consider user time more important than computer time
Features
Very small language
No input during run-time possible (batch-oriented)
Later versions: Visual BASIC

BASIC

© M. Winter
COSC 2P05 – Programming languages
1.*

REM Basic Example Program
REM Input: An integer, listlen, where listlen is less
REM than 100, followed by listlen-integer values
REM Output: The number of input values that are greater
REM than the average of all input values
DIM intlist(99)
result = 0
sum = 0
INPUT listlen
IF listlen > 0 AND listlen < 100 THEN REM Read input into an array and compute the sum FOR counter = 1 TO listlen INPUT intlist(counter) sum = sum + intlist(counter) NEXT counter REM Compute the average average = sum / listlen REM Count the number of input values that are > average
A BASIC Program

© M. Winter
COSC 2P05 – Programming languages
1.*

FOR counter = 1 TO listlen
IF intlist(counter) > average
THEN result = result + 1
NEXT counter
REM Print the result
PRINT “The number of values that are > average is:”;
result
ELSE
PRINT “Error-input list length is not legal”
END IF
END

© M. Winter
COSC 2P05 – Programming languages
1.*

Developed for AI applications in 1958
Two kinds of data structures: atoms and lists
Atoms have the form of an identifier or a numeric literal
Functional programming language
List example: (A B C D)

Lisp

© M. Winter
COSC 2P05 – Programming languages
1.*

; Lisp Example function
; The following code defines a Lisp predicate function
; that takes two lists as arguments and returns True
; if the two lists are equal, and NIL (false) otherwise
(DEFUN equal_lists (lis1 lis2)
(COND
((ATOM lis1) (EQ lis1 lis2))
((ATOM lis2) NIL)
((equal_lists (CAR lis1) (CAR lis2))
(equal_lists (CDR lis1) (CDR lis2)))
(T NIL)
)
)
Lisp Program

© M. Winter
COSC 2P05 – Programming languages
1.*

Scheme
Developed in the mid-1970s
Static scope
Functions are fully treated as first-class entities
COMMON LISP
Created to incorporate several Lisp dialects into one common language
Allows static and dynamic scope
Large number of data types
ML
Functional programming language that also allows imperative programming
Haskell
Lazy evaluation
Use of monads

Related Languages

© M. Winter
COSC 2P05 – Programming languages
1.*

ALGOL 60
ALGOrithmic Language
Joint European-US Committee (GAMM and ACM)
Goals
Standard mathematical notation
Use to describe computing processes
Machine translatable
ALGOL 58 report
BNF
Features
Formal language definition
Block structure
Two different means of passing parameters (pass by value/name)
Arrays with variable bounds
Structured control statements
Recursion

© M. Winter
COSC 2P05 – Programming languages
1.*

Very successful in Europe
Became the only acceptable formal means of communicating algorithms
Reasons not widely used in North America
3 years after FORTRAN
More features, harder to learn
Compilation too complex for the time, less efficient
No standard I/O

© M. Winter
COSC 2P05 – Programming languages
1.*

comment ALGOL 60 Example Program
Input: An integer, listlen, where listlen is less than
100, followed by listlen-integer values
Output: The number of input values that are greater than
the average of all the input values ;
begin
integer array intlist [1:99];
integer listlen, counter, sum, average, result;
sum := 0;
result := 0;
readint (listlen);
if (listlen > 0) ^ (listlen < 100) then begin comment Read input into an array and compute the average; An ALGOL 60 Program © M. Winter COSC 2P05 – Programming languages 1.* for counter := 1 step 1 until listlen do begin readint (intlist[counter]); sum := sum + intlist[counter] end; comment Compute the average; average := sum / listlen; comment Count the input values that are > average;
for counter := 1 step 1 until listlen do
if intlist[counter] > average
then result := result + 1;
comment Print result;
printstring(“The number of values > average is:”);
printint (result)
end
else
printstring (“Error-input list length is not legal”;
end

© M. Winter
COSC 2P05 – Programming languages
1.*

The Algol Family
ALGOL W
Tidied up ALGOL 60
Introduced
Records and references (linked structures)
Case statement
Multiple looping structures
Parameter passing: call-by-value, call-by-result, call-by-value/result, call-by-name
String support
Assert statement
Algol 68
IFIP working group
Highly orthogonal
Highly-formal specification

© M. Winter
COSC 2P05 – Programming languages
1.*

Pascal
Built on ALGOL W
Goals
Efficient implementation
For teaching good programming style
Widely used in universities and became common in industry
Features
Restrictions on goto’s
User-defined data types
Strings
Lacking features
No modules
Array parameters cannot be of variable length

© M. Winter
COSC 2P05 – Programming languages
1.*

{Pascal Example Program
Input: An integer, listlen, where listlen is less than
100, followed by listlen-integer values
Output: The number of input values that are greater than
the average of all input values }
program pasex (input, output);
type intlisttype = array [1..99] of integer;
var
intlist : intlisttype;
listlen, counter, sum, average, result : integer;
begin
result := 0;
sum := 0;
readln (listlen);
if ((listlen > 0) and (listlen < 100)) then begin { Read input into an array and compute the sum } A Pascal Program © M. Winter COSC 2P05 – Programming languages 1.* for counter := 1 to listlen do begin readln (intlist[counter]); sum := sum + intlist[counter] end; { Compute the average } average := sum / listlen; { Count the number of input values that are > average }
for counter := 1 to listlen do
if (intlist[counter] > average) then
result := result + 1;
{ Print the result }
writeln (‘The number of values > average is:’,
result)
end { of the then clause of if (( listlen > 0 … }
else
writeln (‘Error-input list length is not legal’)
end.

© M. Winter
COSC 2P05 – Programming languages
1.*

COBOL
COmmon Business Oriented Language
Probably the most used programming language
Based on FLOW-MATIC by UNIVAC
Business data processing
Usage of English as a programming language
Features
English-like syntax
Emphasis on file processing; records
4 divisions: identification, environment, data, procedure
Mandated by the DoD
Tight language control
Relatively unchanged in 25 yearrs

© M. Winter
COSC 2P05 – Programming languages
1.*

IDENTIFICATION DIVISION.
PROGRAM-ID. PRODUCE-REORDER-LISTING.

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. DEC-VAX.
OBJECT-COMPUTER. DEC-VAX.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT BAL-FWD-FILE ASSIGN TO READER.
SELECT REORDER-LISTING ASSIGN TO LOCAL-PRINTER.

DATA DIVISION.
FILE SECTION.
FD BAL-FWD-FILE
LABEL RECORDS ARE STANDARD
RECORD CONTAINS 80 CHARACTERS.
A COBOL Program

© M. Winter
COSC 2P05 – Programming languages
1.*

01 BAL-FWD-CARD.
02 BAL-ITEM-NO PICTURE IS 9(5).
02 BAL-ITEM-DESC PICTURE IS X(20).
02 FILLER PICTURE IS X(5).
02 BAL-UNIT-PRICE PICTURE IS 999V99.
02 BAL-REORDER-POINT PICTURE IS 9(5).
02 BAL-ON-HAND PICTURE IS 9(5).
02 BAL-ON-ORDER PICTURE IS 9(5).
02 FILLER PICTURE IS X(30).

FD REORDER-LISTING
LABEL RECORDS ARE STANDARD
RECORD CONTAINS 132 CHARACTERS.

01 REORDER-LINE.
02 RL-ITEM-NO PICTURE IS Z(5).
02 FILLER PICTURE IS X(5).
02 RL-ITEM-DESC PICTURE IS X(20).
02 FILLER PICTURE IS X(5).
02 RL-UNIT-PRICE PICTURE IS ZZZ.99.
02 FILLER PICTURE IS X(5).
02 RL-AVAILABLE-STOCK PICTURE IS Z(5).
02 FILLER PICTURE IS X(5).
02 RL-REORDER-POINT PICTURE IS Z(5).
02 FILLER PICTURE IS X(71).

© M. Winter
COSC 2P05 – Programming languages
1.*

WORKING-STORAGE SECTION.
01 SWITCHES.
02 CARD-EOF-SWITCH PICTURE IS X.
01 WORK-FIELDS.
02 AVAILABLE-STOCK PICTURE IS 9(5).

PROCEDURE DIVISION.
000-PRODUCE-REORDER-LISTING.
OPEN INPUT BAL-FWD-FILE.
OPEN OUTPUT REORDER-LISTING.
MOVE “N” TO CARD-EOF-SWITCH.
PERFORM 100-PRODUCE-REORDER-LINE
UNTIL CARD-EOF-SWITCH IS EQUAL TO “Y”.
CLOSE BAL-FWD-File.
CLOSE REORDER-LISTING.
STOP RUN.

100-PRODUCE-REORDER-LINE.
PERFORM 110-READ-INVENTORY-RECORD.
IF CARD-EOF-SWITCH IS NOT EQUAL TO “Y”
PERFORM 120-CALCULATE-AVAILABLE-STOCK
IF AVAILABLE-STOCK IS LESS THAN BAL-REORDER-POINT
PERFORM 130-PRINT-REORDER-LINE.

© M. Winter
COSC 2P05 – Programming languages
1.*

110-READ-INVENTORY-RECORD.
READ BAL-FWD-FILE RECORD
AT END
MOVE “Y” TO CARD-EOF-SWITCH.

120-CALCULATE-AVAILABLE-STOCK.
ADD BAL-ON-HAND BAL-ON-ORDER
GIVING AVAILABLE-STOCK.

130-PRINT-REORDER-LINE.
MOVE SPACE TO REORDER-LINE.
MOVE BAL-ITEM-NO TO RL-ITEM-NO.
MOVE BAL-ITEM-DESC TO RL-ITEM-DESC.
MOVE BAL-UNIT-PRICE TO RL-UNIT-PRICE.
MOVE AVAILABLE-STOCK TO RL-AVAILABLE-STOCK.
MOVE BAL-REORDER-POINT TO RL-REORDER-POINT.
WRITE REORDER-LINE.