You are on page 1of 33

Principles of

Programming Languages
Content
Introduction to programming languages
Fortran
Algol
Principles violated and adhered by Fortran and Algol
Introduction of programming
languages
History of programming languages
 Algorithms
Abu Ja’far Muhammad ibn Musa al-Khorezmi
(790-850AD)

He was the chief mathematician in Kalif Al Mamun’s


“House of Wisdom”

He was the author “A compact introduction to calculation using


rules of completion and Reduction”, which describes the theory of
removing negative units from the equation by adding the same
quantity on the other side
“Calculus of Thought”
Gottfried Wilhelm Leibniz(1646 - 1716)
He invented the calculus and binary
system
“Calculus ratiocinator”: human reasoning can be
reduced to a formal symbolic language, in which
all arguments would be settled by mechanical
manipulation of logical concepts
Formalisms for Computation
Predicate logic
Gottlöb Frege (1848-1925)
Formal basis for proof theory and
automated theorem proving
Logic programming
 Computation as logical deduction
Turing machines
Alan Turing (1912-1954)
Imperative programming
 Sequences of commands, explicit state
transitions, update via assignment
Formalisms for Computation
Lambda calculus
Alonzo Church (1903-1995)
Formal basis for all functional
languages, semantics, type theory
Functional programming
 Pure expression evaluation, no
assignment operator
Recursive functions & automata
Stephen Kleene (1909-1994)
Regular expressions, finite-state
machines, PDAs
Formalisms for Computation
Combinatory logic
Moses Schönfinkel (1889-1942)
Haskell Curry (1900-1982)

Post production systems


Emil Post (1897-1954)

Markov algorithms
Andrey Markov (1903-1979)
Programming Language
Formal notation for specifying computations
Syntax (usually specified by a context-free grammar)
Semantics for each syntactic construct
Practical implementation on a real or virtual machine
 Translation vs. compilation vs. interpretation
 C++ was originally translated into C by Stroustrup’s Cfront

 Java originally used a bytecode interpreter, now native code

compilers are commonly used for greater efficiency


 Lisp, Scheme and most other functional languages are

interpreted by a virtual machine, but code is often precompiled


to an internal executable for efficiency
 Efficiency vs. portability
Low Level Languages
Machine code
Difficult to write programs.
Difficult to enter programs.
Difficult to check whether you got it right!
Assembly languages and Assemblers
Disadvantage: every different computer had a different
assembly language

Due to this first high level language FORTRAN was


implemented.
FORTRAN
Fortran is a 1st generation which is derived from IBM
Mathematical Formula Translating System) is
a general-purpose, procedural imperative programming
language that is especially suited to numeric
computation and scientific computing.

Successive versions have added


support for processing of character-
based data (FORTRAN 77), array
programming ,modular programming
and object-based
programming(Fortran 90), and object-
oriented and generic programming.
History of FORTRAN
Stands for IBM Mathematical FORmula TRANslation

System but abbreviated to FORmula TRANslation


FORTRAN was developed by a
IBM research team headed by
John Backus in 1954.
Was the first high-level
programming language

John Backus
1924-1988
Program Structure
A FORTRAN program is a collection of subprogram
definitions.
Subprograms may be a FUNCTION that returns values,
a SUBROUTINE that doesn’t return a value, and one
must be the “main program”
The initial release of FORTRAN for the IBM 704
contained 32 statements, including:
DIMENSION and EQUIVALENCE statements
Assignment statements
Three-way arithmetic IF statement.
IF statements for checking exceptions.
Control Structures
GOTO statements
IF statements
DO statement
CONTINUE statement
STOP and PAUSE statements
END statement
GOTO Statements
Three types of GOTO statements
* Basic GOTO 100
* Computed GOTO(1,2,3)E
* Assigned GOTO L,(1,2,3)

IF Statement DO Statement
 Contains IF, ELSE IF, ELSE, END  The DO statement is used to
IF
 Example establish a controlled loop
 IF(Q) THEN  Example DO
A=B  DO 10 I = 1,10,1
C=D
ELSE IF (R) THEN
E=F
G=H
ELSE
X=Y
Z=W
END IF
CONTINUE,STOP PAUSE, and
END STATEMENT
The CONTINUE statement serves as a point of reference in
a program
 No operational function is performed
 It is frequently used in DO loops to provide a terminal statement
The STOP and PAUSE statements do a similar task
 The STOP terminates execution
 The PAUSE terminates execution, but leaves the program in a
resumable state
The END statement marks the physical end of a program
FORTRAN SYNTAX
•Lines can only be 72 characters long
•Comments start with a !
•First 6 columns must be spaces
Unless it’s a comment
•No semi-colons after each line.

Important . . . .

DO is highly optimized. So DO complies with the preservation on


Information Principle.
FORTRAN is fast.
Operator precedence was there.
FORTRAN ISSUES
o A newline is a statement terminator
o Fortran language was described using English
 Imprecise
• Ad hoc
DO 10 I=1.10
Assigns 1.10 to the variable DO10I
Early Fortrans didn’t care about spaces!
DO 10 I=1,10
Loops for I = 1 to 10

o Ignoring blanks
o Lack of reserved words and inbuilt input/output functions
o Three versions of GOTO
o Mixed mode operations
o Common block structure
Algol
Designed during 1958-1960
Algol introduces block structure, compound statements,
recursive procedure calls, nested if loops, and arbitrary
length identifiers.
The Algol-60 was a very simple and clear language.
BNF Notation was used for the language specification.
Algol-60 uses a hierarchical structure throughout its
design .This was a major contribution of Algol.
ALGOL-60 allows nested control structures(such as the
FOR-loop) and nested environments
Algol 60 Sample
real procedure average(A,n);
real array A; integer n; no array bounds
begin
real sum; sum := 0;
for i = 1 step 1 until n do
sum := sum + A[i];
average := sum/n no ; here
end;

set procedure return value by assignment


Major contributions of ALGOL:
1) the assignment operation
2) the block structure
the implementation of the block structure avoids
variable re-declaration
Syntax
• FOR-loop, a WHILE-loop and the SWITCH
statement was introduced to handle multiple
cases.
• Compared to first generation languages syntax was
greatly improved.
Data Types

• Three types of data, integer , real and string.

• Algol-60 had strong typing and keywords . Also it


allows recursion.
Some Trouble Spots in Algol 60
Type discipline improved by later languages
Parameter types can be array
 No array bounds
Parameter type can be procedure
 No argument or return types for procedure parameter
Parameter passing methods
Pass-by-name had various anomalies
 “Copy rule” based on substitution, interacts with side effects
Pass-by-value expensive for arrays
Some awkward control issues
Goto out of block requires memory management
Comparison between
Fortran
and
Algol
Principles Adhered in Fortran
Abstraction:
Avoid requiring something to be stated more than once, factor out
the recurring pattern.

• Compliance: Fortran supported subprograms.

Preservation of information:
Allow representation of information that the user might know and
the compiler might need.

• Compliance: Fortran programmers were able to see what


variables would be used for indexing in do loops and keep their
values in index registers for optimisation.
Principles Violated in Fortran
Defense in depth:
If an error gets through one line of defense then it should be
caught by the next line of defense


Violation: Fortran does not have exception handling or type
checking

Syntatic Consistency:
Things which look similar should be similar, and things which
look different should be different.


Violation: FORTRAN Uses * for multiplication and ** for
exponents.
Principles Violated in Fortran
Regularity
Regular rules, without exceptions, are easier to learn, use,
describe, and implement

•Violated : FORTRAN - Can store strings in integers

Zero-One-Infinity
The only reasonable numbers in a programming language design
are zero, one and infinity.

•Violation: Fortran 77 arbitrarily limits arrays to three


dimensions.
Principles Adhered in Algol

Zero-One-Infinity:
The only reasonable numbers in a programming language design
are zero, one and infinity
Compliance: Arrays in Algol can have any number of
dimensions and can have negative indices.
.

Regularity:
Regular rules, without exceptions, are easier to learn, use,
describe, and implement.
Compliance: In Algol, a sequence of statements can replace
a single statement using the block structure.
Principles Adhered in Algol
Syntactic Consistency:
Things which look similar should be similar, and things which
look different should be different.

•Compliance: Algol used := for assignment and = for


equality.
Principles Violated in Algol
Information Hiding
Modules should be designed so that ,The user has all the
information needed to use the module correctly, and nothing
more. The implementer has all the information needed to
implement the module correctly, and nothing more.
Principles Violated in Algol

Violated : Indiscriminate Access


Block that includes the declarations of the symbol table arrays
must also include all the users of the symbol table managers.
Managers must be visible to the users and the data structures must
be visible to the managers , we can see that the data structures
must be visible to the users. So that users of the symbol table can
directly access the symbol table without going through the
symbol table managers . Doing so creates a maintenance problem.
Members Contributed……
DIT-08-M2-1360 - P.H.C.L.Premachandra
DIT-09-M4-1763 - D.A.Y.Thantriwattage
DIT-09-M4-1786 - J.H.A.D.K.Jayasekara
DIT-09-M4-1790 - S.D.Gunaratne
Thank you!

You might also like