Post on 19-Dec-2015
ALGOL ALGOL 6060 Design by committee of computer Design by committee of computer
scientists: Naur, Backus, Bauer, scientists: Naur, Backus, Bauer, McCarthy, van Wijngaarden, Landin, etc.McCarthy, van Wijngaarden, Landin, etc.
Influence later languages : PL/I, Influence later languages : PL/I, Pascal, Algol68, (C)Pascal, Algol68, (C)
Formal definition for syntax (rules for Formal definition for syntax (rules for well-formed programs - BNF); English well-formed programs - BNF); English for semantics (assignment of meaning for semantics (assignment of meaning to program text)to program text)
ALGOL DESIGN ALGOL DESIGN GOALSGOALS Close as possible to mathematical Close as possible to mathematical
notationnotation Use for describing computing Use for describing computing
processesprocesses publication language (fonts, spacing, publication language (fonts, spacing,
subscripts, etc.subscripts, etc. reference language (official, but reference language (official, but
informal, documentation of the informal, documentation of the language)language)
hardware representation (machine hardware representation (machine character sets, etc.)character sets, etc.)
Mechanically translatableMechanically translatable
ALGOL ALGOL ISSUESISSUES• Formal syntax
• Control structures• Scope
− lexical; (dynamic)• Visibility
− block structuring• Lifetime
− static (own); automatic• Type checking
− except for procedure parameters• Parameter passing
− call by name; call by value• Attempt at precise semantics but ambiguities raised
CONTROL CONTROL STRUCTURESSTRUCTURES• if-then-else without endif (dangling else)
• Compound statement / nesting• Designational expressions and switches (yield
labels)• for loop / while
− values specified by re-evaluated expressions− for <variable> := for_list do− for_list ::= comma-separated list of elements
− element ::= arithmetic expression | A step B until C | E while B
BLOCKS ANDBLOCKS ANDCOMPOUND COMPOUND
STATEMENTSSTATEMENTS Compound statementCompound statement: group of : group of statements that can stand for a single statements that can stand for a single statement syntacticallystatement syntactically
BlockBlock: a compound statement : a compound statement containing new declarationscontaining new declarations
WHAT'S IN WHAT'S IN A NAME?A NAME?
A value?A value? A set of values?A set of values? A memory location?A memory location? A set of memory locations?A set of memory locations? An essential decision that separate An essential decision that separate
imperative from functional languagesimperative from functional languages And places strict requirements on symbol And places strict requirements on symbol
table designtable design
EXAMPLE:EXAMPLE:LEXICAL VS. DYNAMIC LEXICAL VS. DYNAMIC
SCOPINGSCOPING a: begin integer m; procedure P; m := 1; b: begin integer m;* P end** P end
dynamic lexical
* b a
** a a
Lexical scoping occurs when thebinding of a variable reference to adeclaration is made by searchingupward in the set of nested blockswithin the program source code(compile-time or static binding)
Dynamic scoping occurs when thebinding of a variable reference to adeclaration is made by searchingupward in the set of nested contextsin the program execution environ-ment (runtime binding)
Algol uses lexical scoping
PARAMETER PARAMETER PASSINGPASSING Actual argumentActual argument - an expression that - an expression that
appears within a procedure call. The appears within a procedure call. The expression may be simply a variable expression may be simply a variable name name {f(x + 3);}{f(x + 3);}
Formal (dummyFormal (dummy) argument - an ) argument - an identifier used within a procedure identifier used within a procedure definition as a surrogate for the actual definition as a surrogate for the actual argument argument {f(int a){f(int a) integer a; integer a; ... ...}}
A PROBLEM WITH CALL BY A PROBLEM WITH CALL BY NAMENAME
procedure SWAP(x, y); real x, y; begin real t; t := x; x := y; y := t; end;
i == 1; A[1] == 2; A[2] == 8;
SWAP(i, A[i]) t := i; (t == 1) i := A[i]; (i == 2) A[i] := t; (A[2] == 1)
AMBIGUITY: SIDE AMBIGUITY: SIDE EFFECTSEFFECTSbeginbegin
integer a;integer a;
integer procedure f(x, integer procedure f(x, y);y);
value y, x;value y, x;
integer y, x;integer y, x;
a := f := x + 1;a := f := x + 1;
integer procedure g(x);integer procedure g(x);
integer x;integer x;
x := g := a + 2;x := g := a + 2;
a := 0;a := 0;
outreal(1, a + f(a, outreal(1, a + f(a, g(a)) / g(a))g(a)) / g(a))
endend
Then, evaluate the numerator, first the a argument (2), then the g(a) nested call (yielding 4 and setting a to 4)
For example: to get 4.5, first evaluate the denominator (g(a)) which yields 2 and has the side effect of setting a to 2
ALGOL ALGOL PROBLEMSPROBLEMS• Premature implementation led to divisiveness
• Design by committee• No I / O• No types for procedure parameter
parameters• goto's out of blocks• for loop evaluation overly general• Dynamic own array bounds• Error handling not described• Dangling else• ...
ALGOL ALGOL CONCEPTSCONCEPTS• Formal syntax / precise semantics
• Scope / visibility / lifetime• Lexical / dynamic scoping• Type checking• Block structure / compound Statement• Control structures:
− compound statement, procedure, conditional, switch
− loop: list of elements, step, while• Parameter passing mechanisms:
− call by value, call by name