Principles of Programming Languages

Post on 03-Jul-2015

736 Views

Category:

Documents

2 Downloads

Preview:

Click to see full reader

DESCRIPTION

This slide has introduction to programming languages,Fortran,Algol and principles violated and adhered by Fortran and Algol

Transcript

Principles of Programming Languages

ContentIntroduction to programming languagesFortranAlgolPrinciples 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 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

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

Formalisms for ComputationCombinatory logic

Moses Schönfinkel (1889-1942)

Haskell Curry (1900-1982)

Post production systemsEmil Post (1897-1954)

Markov algorithmsAndrey Markov (1903-1979)

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

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.

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.

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

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.

Control StructuresGOTO statements IF statementsDO statementCONTINUE statement STOP and PAUSE statementsEND statement

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

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

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

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

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

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.

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

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 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.

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

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.

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

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.

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.

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

Thank you!

top related