36
The ALGOL Family CSE341 Programming Languages

ALGOL ailesi programlama dilleri

Embed Size (px)

DESCRIPTION

Hamid Yeşilyayla, ödev

Citation preview

Page 1: ALGOL ailesi programlama dilleri

The ALGOL Family

CSE341

Programming Languages

Page 2: ALGOL ailesi programlama dilleri

Overview Historical perspective ALGOL Goals BNF (Backus-Naur Form) ALGOL 58 ALGOL 60 ALGOL 68 Success and Failure of ALGOL Conclusion

Page 3: ALGOL ailesi programlama dilleri

History

ALGOrithmic Language Developed in Europe by an international group,

consisting of 7 different countries, in the late 1950’s Very similar to FORTRAN Peter Naur and J.W. Backus worked on the project.

Was the debut of the BNF syntax. Designed specifically for programming scientific

computations

Page 4: ALGOL ailesi programlama dilleri

History (Continued)

Never became as commercially popular as FORTRAN or COBOL Was not compatible with IBM

Is considered the most important programming language in terms of influence on later language development

Many similar languages can (and are) referred to as “ALGOL-like” JAVA, C, C++, Pascal, Ada, FORTRAN, etc.

Page 5: ALGOL ailesi programlama dilleri

ALGOL Goals

To be as close as possible to standard math notation Also very readable without much more explanation

Should be possible to use it to describe algorithms in publications A form of it is still used today

Should be mechanically translatable into machine language programs

Page 6: ALGOL ailesi programlama dilleri

BNF (Backus-Naur Form)

Was first to use BNF (Backus-Naur Form) Same Backus that created Fortran

He also was one of the main creators of Algol And he created functional programming And won the Turing award in ’77

Right. Back to BNF BNF example:

<value> := <number> | <variable> | <expression> <number> := <integer> | <float> <integer> := <integer><digit> | <digit> <digit> := 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

Language was designed by committee Report is a “paradigm of brevity and clarity”

Most languages today require 1000’s of pages Brevity and clarity contributed to reputation as simple, elegant language

Page 7: ALGOL ailesi programlama dilleri

Three Language Versions

Reference language Used by the committee, described in the report, and used in

official Algol publications Publication language

Allowed for differences in the character set for different languages

Europeans and Americans couldn’t decide on which character to use for the decimal point!

Hardware representations Condensed languages for machine input

Page 8: ALGOL ailesi programlama dilleri

ALGOL 58The beginning June 1957 – ACM requested a committee to look

into a universal programming language European and American groups got together in

Zurich. No current language covers everything Creating more non-ideal languages doesn’t help the

situation Each passing month more people start using other

languages How can the logical structure of existing languages be

adjusted

Page 9: ALGOL ailesi programlama dilleri

ALGOL 58New Features Types

Integer Real Boolean

Formal vs Actual parameters Declaration for statements Switch Compound statements Begin end delimiters Three level language description Call by name

Page 10: ALGOL ailesi programlama dilleri

ALGOL 58Function vs Procedure Nature of the body

Expression Compound statement

Parameter evaluation mechanism Value of any actual parameter Text of any actual parameter

Identifier collision Non-parameter identifiers are global to the definition Communication only through parameters

Place of use An operand in an expression A statement or an operand in an expression

Page 11: ALGOL ailesi programlama dilleri

Call by name vs. by value

Call by name is default Call by name: re-evaluate the actual parameter on every

use For actual parameters that are simple variables, it’s

the same as call by reference For actual parameters that are expressions, the

expression is re-evaluated on each access No other language ever used call by name…

Page 12: ALGOL ailesi programlama dilleri

Call by name

begin integer n; procedure p (k: integer) begin print (k); n := n+1; print (k); end; n := 0; p (n+10);end;

parameter is n+10 (not just 10)

prints n+10, which is 10

parameter is n+10 (not just 10)

n is still 0; thus, n becomes 1

prints n+10, which is 11

n is set to 0

Page 13: ALGOL ailesi programlama dilleri

Example Computing Illustrate ( Compute The Mean ):

// the main program (this is a comment) begin

integer N; Read Int(N);

begin real array Data[1:N]; real sum, avg; integer i; sum:=0; for i:=1 step 1 until N do

begin real val; Read Real(val); Data[i]:=if val<0 then -val else val

end;

for i:=1 step 1 until N do sum:=sum + Data[i];

avg:=sum/N; Print Real(avg)

end end

Page 14: ALGOL ailesi programlama dilleri

Example(Continued) I/O Illustrate: because ALGOL had no IO facilities. The following

code could run on an ALGOL implementation for a Burroughs A-Series mainframe.

BEGIN

FILE F (KIND=REMOTE);

EBCDIC ARRAY E [0:11];

REPLACE E BY "HELLO WORLD!";

WHILE TRUE DO

BEGIN

WRITE (F, *, E);

END;

END.

Page 15: ALGOL ailesi programlama dilleri

Problems with Algol58

Didn’t include a I/O libraryThus, each implementation had a different

means for I/OThis caused compatibility problemsAnd no standard way to write a Hello World

program

Page 16: ALGOL ailesi programlama dilleri

ALGOL 60 Basic Language of 1960

Simple imperative language + functions Successful syntax, BNF -- used by many successors

statement oriented begin … end blocks (like C { … } ) if … then … else

Recursive functions and stack storage allocation Type discipline was improved by later languages Very influential but not widely used in US

Tony Hoare: “Here is a language so far ahead of its time that it was not only an improvement on its predecessors but also on nearly all of its successors.”

Page 17: ALGOL ailesi programlama dilleri

ALGOL 60Proposed Changes The empty statement was adopted Modifications to operation hierarchy

Unary operators having higher precedence than binary operators was adopted Implied multiplication was rejected Relation sequences were rejected

The else clause was adopted Strings, lists, trees, matrices, and complex numbers were rejected as types Multiple assignment statements were adopted

Created a new problem, A[i] := i := e Recursion became possible in obvious ways Constants were rejected

Page 18: ALGOL ailesi programlama dilleri

ALGOL 60What’s New Block Call by value/name Typed procedures Declaration scope Dynamic arrays Side effects Global and local variables Step, until, while, if then else Activation records Recursive decent parsers No I/O

Page 19: ALGOL ailesi programlama dilleri

Algol 60 Sample

real 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/nend;

no array bounds

no ; here

set procedure return value by assignment

Page 20: ALGOL ailesi programlama dilleri

Algol Oddity

Question: Is x := x equivalent to doing nothing?

Interesting answer in Algol

integer procedure p;

begin

….

p := p

….

end; Assignment here is actually a recursive call

Page 21: ALGOL ailesi programlama dilleri

Problems with Algol60

Holes in type discipline Parameter types can be arrays, but

No array bounds Parameter types can be procedures, but

No argument or return types for procedure parameters Problems with parameter passing mechanisms

Pass-by-name “Copy rule” duplicates code, interacting badly with side effects

Pass-by-value expensive for arrays Some awkward control issues

goto out of block requires memory management

Page 22: ALGOL ailesi programlama dilleri

ALGOL 68 Considered difficult to understand

Idiosyncratic terminology Types were called “modes” Arrays were called “multiple values”

Used vW grammars instead of BNF Context-sensitive grammar invented by van Wijngaarden

Elaborate type system Complicated type conversions

Fixed some problems of Algol 60 Eliminated pass-by-name

Not widely adopted

Page 23: ALGOL ailesi programlama dilleri

ALGOL 68What’s New Many new types, called modes

Primatives Bits Bytes String Sema (a semaphore) Complex File Pipe Channel format

Additional Flex (Flexible array) Heap (space on the heap) Loc (local space on the stack) Ref (pointer) Long (bigger ints/reals) Short (smaller ints/reals)

Declaration of custom types/modes

Page 24: ALGOL ailesi programlama dilleri

Algol 68 Modes

Primitive modes Compound Modes

int --arrays Real --structures Char --procedures bool --sets string --pointers Compl(complex) bits bytes Sema (semaphore) Format (I/O) file

Rich, structured, and orthogonal type system is a major contribution of Algol 68.

Page 25: ALGOL ailesi programlama dilleri

Other Features of Algol 68

Storage management Local storage on stack Heap storage and garbage collection

Parameter passing Pass-by-value Use pointer types to obtain pass-by-reference

Assignable procedure variables

Page 26: ALGOL ailesi programlama dilleri

Structure

ALGOL68 is block structured w/ static scope rules ALGOL68's model of computation:

static stack: block/procedure AR's; local data objects heap: “heap” -- dynamic-- data objects

ALGOL68 is an expression-oriented language

Page 27: ALGOL ailesi programlama dilleri

Basic Syntax

Addition : “ + ” Subtraction : “ - ” Multiplication : “ * ” Division : “ / ” Exponentiation : “ ** ” Assignment : “ := ” Boolean Expressions

= , > , < , <= , >= , /=

Page 28: ALGOL ailesi programlama dilleri

Recursion

Algol 68 Supports recursion

Example:

real procedure factorial (n);

begin

if n = 1 then

factorial := 1;

else

factorial := n* factorial(n-1);

end;

Page 29: ALGOL ailesi programlama dilleri

Arrays

Three types of arrays: real, integer, Boolean Each array must contain all the same types All arrays are of type real unless specified Can have multidimensional arrays Declarations:

array name1[1:100]; (1D array of type real) real array name2(-3:6,20:40); (2D array of type real) integer array name3,name4(1:46);(2 1D arrays of type integer) Boolean array name5(-10:n); (1D array of type Boolean)

(Allocated Dynamically)

Page 30: ALGOL ailesi programlama dilleri

Block Structure

First language to implement a block structure Similar in form to pascal

begin

…..

end; Each block can have its own variables, visible only to

that block (local variables). After the block is exited the values of all the local variables are lost.

Page 31: ALGOL ailesi programlama dilleri

Block Structure example

Example:

begin

own integer i; integer j,k;

i := j + k;

end; The integer i will have the value of j+k stored the next time

the block is entered By using the “own” statement the variable will retain its

value for the next time the block is entered

Page 32: ALGOL ailesi programlama dilleri

Parameter Passing

Two types of parameter passing: by Value, by Name

Pass by Value works the same as in most other languages

Pass by Name is similar to pass by reference, but it adds flexibility

All parameters are pass by name unless otherwise specified Example: can make a call “sum(i,2,5,x+6)” to the procedure sum

procedure sum(i,j,k,l); value i,j,k;begin

i := i + j + k + lend;

(will execute as i := i + 2 + 5 + (x+6))

Page 33: ALGOL ailesi programlama dilleri

ALGOLSuccesses and Failures Programming computers – Partial Success

Core language is strong, no I/O is a serious shortcoming Publication of algorithms – Very Successful Stimulus to compiler design – Success with a seed of

corruption It only stimulated compiler design because it was difficult

Stimulated formal language research – Success Not the goal of the ALGOL effort

Description of ALGOL 60 – Failure Difficult to understand for the uninitiated reader Needs an informal explanation

Page 34: ALGOL ailesi programlama dilleri

Conclusion

General purpose algorithmic language with a clean consistent and unambiguous syntax.

Comprehensive fully-checked type-system covering structures, unions, pointers, arrays and procedures.

Procedures may be nested inside procedures and can deliver values of any type without you having to worry about where the storage is coming from.

User-defined operators including user-defined operator symbols.

Powerful control structures can deliver values of any type.

Page 35: ALGOL ailesi programlama dilleri

Conclusion (Continued)

Dynamic sized arrays know their current bounds. Array and structure displays can be used in any context. Parallel programming with semaphores. Complex arithmetic. Declarations can be interleaved with statements. Clear distinction between value semantics and reference

semantics. No distinction between compile-time constants and run-

time values.

Page 36: ALGOL ailesi programlama dilleri

References

Lindsey, C.H., “A History of ALGOL 68.” History of Programming Languages, ACM Press. 1993. 97-132

Naur, Peter, “Successes and failures of the ALGOL effort”, ALGOL Bulletin #28, Computer History Museum. 1986. 58-62

Thomson, C.M., “Algol 68 as a Living Language”, ALGOL Bulletin #47, Computer History Museum. 1981. 21-24

Perlis, Alan, “The American side of the development of Algol”, The first ACM SIGPLAN conference on History of programming languages, ACM Press. 1978. 3-14

Naur, Peter. “The European side of the last phase of the development of ALGOL 60”, The first ACM SIGPLAN conference on History of programming languages, ACM Press. 1978. 15-44