principles of programming languages
DESCRIPTION
This slide has introduction to programming languages,Fortran,Algol and principles violated and adhered by Fortran and AlgolTRANSCRIPT
![Page 1: Principles of Programming Languages](https://reader033.vdocument.in/reader033/viewer/2022061611/5571fad24979599169933688/html5/thumbnails/1.jpg)
Principles of Programming Languages
![Page 2: Principles of Programming Languages](https://reader033.vdocument.in/reader033/viewer/2022061611/5571fad24979599169933688/html5/thumbnails/2.jpg)
ContentIntroduction to programming languagesFortranAlgolPrinciples violated and adhered by Fortran
and Algol
![Page 3: Principles of Programming Languages](https://reader033.vdocument.in/reader033/viewer/2022061611/5571fad24979599169933688/html5/thumbnails/3.jpg)
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
![Page 4: Principles of Programming Languages](https://reader033.vdocument.in/reader033/viewer/2022061611/5571fad24979599169933688/html5/thumbnails/4.jpg)
“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
![Page 5: Principles of Programming Languages](https://reader033.vdocument.in/reader033/viewer/2022061611/5571fad24979599169933688/html5/thumbnails/5.jpg)
Formalisms for ComputationPredicate logic
Gottlöb Frege (1848-1925)Formal basis for proof theory
and automated theorem proving
Logic programming Computation as logical deduction
Turing machinesAlan Turing (1912-1954)Imperative programming
Sequences of commands, explicit state transitions, update via assignment
![Page 6: Principles of Programming Languages](https://reader033.vdocument.in/reader033/viewer/2022061611/5571fad24979599169933688/html5/thumbnails/6.jpg)
Formalisms for ComputationLambda calculus
Alonzo Church (1903-1995)Formal basis for all functional
languages, semantics, type theory
Functional programming Pure expression evaluation, no
assignment operator
Recursive functions & automataStephen Kleene (1909-1994)Regular expressions, finite-
state machines, PDAs
![Page 7: Principles of Programming Languages](https://reader033.vdocument.in/reader033/viewer/2022061611/5571fad24979599169933688/html5/thumbnails/7.jpg)
Formalisms for ComputationCombinatory logic
Moses Schönfinkel (1889-1942)
Haskell Curry (1900-1982)
Post production systemsEmil Post (1897-1954)
Markov algorithmsAndrey Markov (1903-1979)
![Page 8: Principles of Programming Languages](https://reader033.vdocument.in/reader033/viewer/2022061611/5571fad24979599169933688/html5/thumbnails/8.jpg)
Programming LanguageFormal notation for specifying computations
Syntax (usually specified by a context-free grammar)
Semantics for each syntactic constructPractical 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
![Page 9: Principles of Programming Languages](https://reader033.vdocument.in/reader033/viewer/2022061611/5571fad24979599169933688/html5/thumbnails/9.jpg)
Low Level LanguagesMachine code
Difficult to write programs.Difficult to enter programs.Difficult to check whether you got it right!
Assembly languages and AssemblersDisadvantage: every different computer had a
different assembly language
Due to this first high level language FORTRAN was implemented.
![Page 10: Principles of Programming Languages](https://reader033.vdocument.in/reader033/viewer/2022061611/5571fad24979599169933688/html5/thumbnails/10.jpg)
![Page 11: Principles of Programming Languages](https://reader033.vdocument.in/reader033/viewer/2022061611/5571fad24979599169933688/html5/thumbnails/11.jpg)
FORTRANFortran 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.
![Page 12: Principles of Programming Languages](https://reader033.vdocument.in/reader033/viewer/2022061611/5571fad24979599169933688/html5/thumbnails/12.jpg)
History of FORTRAN
John Backus1924-1988
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
![Page 13: Principles of Programming Languages](https://reader033.vdocument.in/reader033/viewer/2022061611/5571fad24979599169933688/html5/thumbnails/13.jpg)
Program StructureA 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 statementsAssignment statementsThree-way arithmetic IF statement.IF statements for checking exceptions.
![Page 14: Principles of Programming Languages](https://reader033.vdocument.in/reader033/viewer/2022061611/5571fad24979599169933688/html5/thumbnails/14.jpg)
Control StructuresGOTO statements IF statementsDO statementCONTINUE statement STOP and PAUSE statementsEND statement
![Page 15: Principles of Programming Languages](https://reader033.vdocument.in/reader033/viewer/2022061611/5571fad24979599169933688/html5/thumbnails/15.jpg)
GOTO Statements
Three types of GOTO statements* Basic GOTO 100* Computed GOTO(1,2,3)E* Assigned GOTO L,(1,2,3)
IF StatementContains IF, ELSE IF, ELSE, END
IFExample
IF(Q) THENA=BC=D
ELSE IF (R) THENE=FG=H
ELSEX=YZ=W
END IF
DO StatementThe DO statement is used to
establish a controlled loopExample DO
DO 10 I = 1,10,1
![Page 16: Principles of Programming Languages](https://reader033.vdocument.in/reader033/viewer/2022061611/5571fad24979599169933688/html5/thumbnails/16.jpg)
CONTINUE,STOP PAUSE, and END STATEMENT
The CONTINUE statement serves as a point of reference in a programNo operational function is performed It is frequently used in DO loops to provide a terminal
statementThe STOP and PAUSE statements do a similar
taskThe STOP terminates executionThe PAUSE terminates execution, but leaves the
program in a resumable stateThe END statement marks the physical end of a
program
![Page 17: Principles of Programming Languages](https://reader033.vdocument.in/reader033/viewer/2022061611/5571fad24979599169933688/html5/thumbnails/17.jpg)
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.
![Page 18: Principles of Programming Languages](https://reader033.vdocument.in/reader033/viewer/2022061611/5571fad24979599169933688/html5/thumbnails/18.jpg)
FORTRAN ISSUESo A newline is a statement terminatoro Fortran language was described using English
Imprecise• Ad hoc
DO 10 I=1.10Assigns 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 blankso Lack of reserved words and inbuilt input/output functionso Three versions of GOTOo Mixed mode operationso Common block structure
![Page 19: Principles of Programming Languages](https://reader033.vdocument.in/reader033/viewer/2022061611/5571fad24979599169933688/html5/thumbnails/19.jpg)
AlgolDesigned during 1958-1960Algol 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
![Page 20: Principles of Programming Languages](https://reader033.vdocument.in/reader033/viewer/2022061611/5571fad24979599169933688/html5/thumbnails/20.jpg)
Algol 60 Samplereal procedure average(A,n);
real array A; integer n;
begin
real sum; sum := 0;
for i = 1 step 1 until n do
sum := sum + A[i];
average := sum/n
end;no ; here
no array bounds
set procedure return value by assignment
![Page 21: Principles of Programming Languages](https://reader033.vdocument.in/reader033/viewer/2022061611/5571fad24979599169933688/html5/thumbnails/21.jpg)
Major contributions of ALGOL:1) the assignment operation2) 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.
![Page 22: Principles of Programming Languages](https://reader033.vdocument.in/reader033/viewer/2022061611/5571fad24979599169933688/html5/thumbnails/22.jpg)
Data Types
• Three types of data, integer , real and string.
•Algol-60 had strong typing and keywords . Also it allows recursion.
![Page 23: Principles of Programming Languages](https://reader033.vdocument.in/reader033/viewer/2022061611/5571fad24979599169933688/html5/thumbnails/23.jpg)
Some Trouble Spots in Algol 60Type 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 methodsPass-by-name had various anomalies
“Copy rule” based on substitution, interacts with side effects
Pass-by-value expensive for arraysSome awkward control issues
Goto out of block requires memory management
![Page 24: Principles of Programming Languages](https://reader033.vdocument.in/reader033/viewer/2022061611/5571fad24979599169933688/html5/thumbnails/24.jpg)
Comparison between Fortran
and Algol
![Page 25: Principles of Programming Languages](https://reader033.vdocument.in/reader033/viewer/2022061611/5571fad24979599169933688/html5/thumbnails/25.jpg)
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.
![Page 26: Principles of Programming Languages](https://reader033.vdocument.in/reader033/viewer/2022061611/5571fad24979599169933688/html5/thumbnails/26.jpg)
Principles Violated in FortranDefense 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.
![Page 27: Principles of Programming Languages](https://reader033.vdocument.in/reader033/viewer/2022061611/5571fad24979599169933688/html5/thumbnails/27.jpg)
RegularityRegular rules, without exceptions, are easier to learn, use, describe, and implement
•Violated : FORTRAN - Can store strings in integers
Zero-One-InfinityThe only reasonable numbers in a programming language design are zero, one and infinity.
•Violation: Fortran 77 arbitrarily limits arrays to three dimensions.
Principles Violated in Fortran
![Page 28: Principles of Programming Languages](https://reader033.vdocument.in/reader033/viewer/2022061611/5571fad24979599169933688/html5/thumbnails/28.jpg)
Principles Adhered in Algol
Zero-One-Infinity:The only reasonable numbers in a programming language design are zero, one and infinity
Regularity:Regular rules, without exceptions, are easier to learn, use, describe, and implement.
Compliance: Arrays in Algol can have any number of dimensions and can have negative indices. .
Compliance: In Algol, a sequence of statements can replace a single statement using the block structure.
![Page 29: Principles of Programming Languages](https://reader033.vdocument.in/reader033/viewer/2022061611/5571fad24979599169933688/html5/thumbnails/29.jpg)
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 Adhered in Algol
![Page 30: Principles of Programming Languages](https://reader033.vdocument.in/reader033/viewer/2022061611/5571fad24979599169933688/html5/thumbnails/30.jpg)
Principles Violated in Algol
Information HidingModules 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.
![Page 31: Principles of Programming Languages](https://reader033.vdocument.in/reader033/viewer/2022061611/5571fad24979599169933688/html5/thumbnails/31.jpg)
Principles Violated in Algol
Violated : Indiscriminate AccessBlock 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.
![Page 32: Principles of Programming Languages](https://reader033.vdocument.in/reader033/viewer/2022061611/5571fad24979599169933688/html5/thumbnails/32.jpg)
Members Contributed……DIT-08-M2-1360 - P.H.C.L.PremachandraDIT-09-M4-1763 - D.A.Y.ThantriwattageDIT-09-M4-1786 - J.H.A.D.K.JayasekaraDIT-09-M4-1790 - S.D.Gunaratne
![Page 33: Principles of Programming Languages](https://reader033.vdocument.in/reader033/viewer/2022061611/5571fad24979599169933688/html5/thumbnails/33.jpg)
Thank you!