CS 415 Programming Languages Algol Aaron Bloomfield Fall
CS 415: Programming Languages Algol Aaron Bloomfield Fall 2005
Historical perspective By mid/late 50’s a lot of PLs were out there Interest in universal language European and American groups got together in Zurich n n Result was Algol 58 8 people spent 8 days working on the language
Algol goals To be as close as possible to standard math notation n Also very readable without much more explanation Should be possible to use it to describe algorithms in publications n A form of it is still used today Should be mechanically translatable machine language programs into
3 language versions Reference language n Used by the committee, described in the report, and used in official Algol publications Publication language n n 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 n Condensed languages for machine input
More history Was first to use BNF (Backus-Naur Form) n 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 n n Right. Back to BNF example: <value> : = <number> | <variable> | <expression> <number> : = <integer> | <float> <integer> : = <integer><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” n n Most languages today require 1000’s of pages Brevity and clarity contributed to reputation as simple, elegant language
Algol language features Block structure And scope of variables within those blocks Explicit type declaration for variables Scope rules for local variables Dynamic lifetimes for variables Nested if-then-else expressions and statements Call by value and call by name Recursive subroutines Arrays with dynamic bounds User defined data types
Gotos Algol did include them But with (recursive) procedures and blocks, they weren’t needed as much Gotos were going out of vogue n People were realizing that it was a poor way to program Dijkstra’s 1968 letter to the ACM on the subjetct
Syntax and style Free format n Indentation style Algol defined the style of most successors n n Hierarchical structure Nesting of environments and control structures Identifiers could be more than 6 characters
Variables and types Data types: integer, real, boolean No implicit declarations No double precision types No complex number types Arrays could have more than three dimensions n n Could have dynamic bounds Can start at something other than 0/1
Binding of names to locations is done on entry to a block n Not at compile time, as in Fortran Stack is central run-time data structure
Blocks Can use a block of statements anywhere a single statement is needed begin declarations; statements; end
Blocks support structured programming Algol 60 if x = 3 begin y : = k : = end; then 9; 10; Fortran 100 IF (X. NEQ. 3) GOTO 100 Y = 9 K = 10. . .
Blocks allow nested scopes begin integer x; procedure squid; begin integer x; . . . end;
Blocks for efficient storage management begin. . . begin real array x[1: 1000]; . . . end; . . . begin real array y[1: 2000]; . . . end;
Control structures Goto If-then-else For loop Switch
Call by name vs. by value Call by name is default Call by name: re-evaluate the actual parameter on every use n n 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…
Call by name parameter is n+10 (not just 10) begin integer n; procedure p (k: integer) begin prints n+10, which is 10 print (k); n : = n+1; n is still 0; thus, n becomes 1 prints n+10, which is 11 print (k); end; n : = 0; n is set to 0 p (n+10); end; parameter is n+10 (not just 10)
Problems with Algol Didn’t include a I/O library n n n Thus, each implementation had a different means for I/O This caused compatibility problems And no standard way to write a Hello World program
Algol 68 Successor to Algol 60 Included may new features n n n Unions Operator overloading Casting Standardized input and output Parallel processing Rarely implemented by the compilers, though
Life of Algol 60 Didn’t achieve widespread use Extremely important in the history of PLs Successors: Pascal, Modula, Ada, others Produced important work on: n n n Lexical analysis Parsing Compilation techniques languages for block-structured
- Slides: 20