181 likes | 777 Views
ALGOL 60. Design by committee of computer scientists: Naur, Backus, Bauer, McCarthy, van Wijngaarden, Landin, etc. Influence later languages : PL/I, Pascal, Algol68, (C)
E N D
ALGOL 60 • Design by committee of computer scientists: Naur, Backus, Bauer, McCarthy, van Wijngaarden, Landin, etc. • Influence later languages : PL/I, Pascal, Algol68, (C) • Formal definition for syntax (rules for well-formed programs - BNF); English for semantics (assignment of meaning to program text)
ALGOL DESIGN GOALS • Close as possible to mathematical notation • Use for describing computing processes • publication language (fonts, spacing, subscripts, etc. • reference language (official, but informal, documentation of the language) • hardware representation (machine character sets, etc.) • Mechanically translatable
ALGOL ISSUES • 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 STRUCTURES • 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 ANDCOMPOUND STATEMENTS • Compound statement: group of statements that can stand for a single statement syntactically • Block: a compound statement containing new declarations
WHAT'S IN A NAME? • A value? • A set of values? • A memory location? • A set of memory locations? • An essential decision that separate imperative from functional languages • And places strict requirements on symbol table design
EXAMPLE:LEXICAL VS. DYNAMIC SCOPING a: begin integer m; procedure P; m := 1; b: begin integer m; * P end ** P end Lexical scoping occurs when the binding of a variable reference to a declaration is made by searching upward in the set of nested blocks within the program source code (compile-time or static binding) Dynamic scoping occurs when the binding of a variable reference to a declaration is made by searching upward in the set of nested contexts in the program execution environ- ment (runtime binding) dynamic lexical * b a ** a a Algol uses lexical scoping
PARAMETER PASSING • Actual argument - an expression that appears within a procedure call. The expression may be simply a variable name {f(x + 3);} • Formal (dummy) argument - an identifier used within a procedure definition as a surrogate for the actual argument {f(int a) integer a; ...}
A PROBLEM WITH CALL BY NAME 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 EFFECTS For example: to get4.5, first evaluate the denominator (g(a)) which yields2and has the side effect of settingato2 begin integer a; integer procedure f(x, y); value y, x; integer y, x; a := f := x + 1; integer procedure g(x); integer x; x := g := a + 2; a := 0; outreal(1, a + f(a, g(a)) / g(a)) end Then, evaluate the numerator, first the a argument (2), then the g(a) nested call (yielding 4 and setting a to 4)
ALGOL PROBLEMS • 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 CONCEPTS • 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