cs 415: programming languages
DESCRIPTION
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 Result was Algol 58 8 people spent 8 days working on the language. - PowerPoint PPT PresentationTRANSCRIPT
CS 415: Programming Languages
Algol
Aaron Bloomfield
Fall 2005
Historical perspectiveHistorical perspective
By mid/late 50’s a lot of PLs were out thereBy mid/late 50’s a lot of PLs were out there
Interest in universal languageInterest in universal language
European and American groups got together in European and American groups got together in ZurichZurich Result was Algol 58Result was Algol 58 8 people spent 8 days working on the language8 people spent 8 days working on the language
Algol goalsAlgol goals
To be as close as possible to standard math To be as close as possible to standard math notationnotation Also very readable without much more explanationAlso very readable without much more explanation
Should be possible to use it to describe Should be possible to use it to describe algorithms in publicationsalgorithms in publications A form of it is still used todayA form of it is still used today
Should be mechanically translatable into Should be mechanically translatable into machine language programsmachine language programs
3 language versions3 language versions
Reference languageReference language Used by the committee, described in the report, and Used by the committee, described in the report, and
used in official Algol publicationsused in official Algol publications
Publication languagePublication language Allowed for differences in the character set for Allowed for differences in the character set for
different languagesdifferent languages Europeans and Americans couldn’t decide on which Europeans and Americans couldn’t decide on which
character to use for the decimal point!character to use for the decimal point!
Hardware representationsHardware representations Condensed languages for machine inputCondensed languages for machine input
More historyMore history
Was first to use BNF (Backus-Naur Form)Was first to use BNF (Backus-Naur Form) Same Backus that created FortranSame Backus that created Fortran
He also was one of the main creators of AlgolHe also was one of the main creators of AlgolAnd he created functional programmingAnd he created functional programmingAnd won the Turing award in ’77And won the Turing award in ’77
Right. Back to BNFRight. Back to BNF BNF example:BNF example:
<value> := <number> | <variable> | <expression><value> := <number> | <variable> | <expression><number> := <integer> | <float><number> := <integer> | <float><integer> := <integer><digit> | <digit><integer> := <integer><digit> | <digit><digit> := 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9<digit> := 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
Language was designed by committeeLanguage was designed by committeeReport is a “paradigm of brevity and clarity”Report is a “paradigm of brevity and clarity”
Most languages today require 1000’s of pagesMost languages today require 1000’s of pages Brevity and clarity contributed to reputation as simple, elegant Brevity and clarity contributed to reputation as simple, elegant
languagelanguage
Algol language featuresAlgol language features
Block structureBlock structureAnd scope of variables within those blocksAnd scope of variables within those blocksExplicit type declaration for variablesExplicit type declaration for variablesScope rules for local variablesScope rules for local variablesDynamic lifetimes for variablesDynamic lifetimes for variablesNested if-then-else expressions and statementsNested if-then-else expressions and statementsCall by value and call by nameCall by value and call by nameRecursive subroutinesRecursive subroutinesArrays with dynamic boundsArrays with dynamic boundsUser defined data typesUser defined data types
GotosGotos
Algol did include themAlgol did include them
But with (recursive) procedures and blocks, they But with (recursive) procedures and blocks, they weren’t needed as muchweren’t needed as much
Gotos were going out of vogueGotos were going out of vogue People were realizing that it was a poor way to People were realizing that it was a poor way to
programprogram
Dijkstra’s 1968 letter to the ACM on the subjetctDijkstra’s 1968 letter to the ACM on the subjetct
Syntax and styleSyntax and style
Free formatFree format Indentation styleIndentation style
Algol defined the style of most successorsAlgol defined the style of most successors Hierarchical structureHierarchical structure Nesting of environments and control structuresNesting of environments and control structures
Identifiers could be more than 6 charactersIdentifiers could be more than 6 characters
Variables and typesVariables and types
Data types: integer, real, booleanData types: integer, real, boolean
No implicit declarationsNo implicit declarations
No double precision typesNo double precision types
No complex number typesNo complex number types
Arrays could have more than three dimensionsArrays could have more than three dimensions Could have dynamic boundsCould have dynamic bounds Can start at something other than 0/1Can start at something other than 0/1
BindingBinding
Binding of names to locations is done Binding of names to locations is done on entry on entry to a blockto a block Not at compile time, as in FortranNot at compile time, as in Fortran
Stack is central run-time data structureStack is central run-time data structure
BlocksBlocks
Can use a block of statements anywhere a Can use a block of statements anywhere a single statement is neededsingle statement is needed
beginbegin
declarations;declarations;
statements;statements;
endend
Blocks support structured Blocks support structured programmingprogramming
Algol 60Algol 60if x = 3 thenif x = 3 then
beginbegin
y := 9;y := 9;
k := 10;k := 10;
end;end;
FortranFortran IF (X .NEQ. 3) GOTO 100IF (X .NEQ. 3) GOTO 100
Y = 9Y = 9
K = 10K = 10
100 ...100 ...
Blocks allow nested scopesBlocks allow nested scopes
beginbegin
integer x;integer x;
procedure squid;procedure squid;
beginbegin
integer x;integer x;
......
end;end;
end;end;
Blocks for efficient storage Blocks for efficient storage managementmanagement
beginbegin ...... beginbegin real array x[1:1000];real array x[1:1000]; ...... end;end; ...... beginbegin real array y[1:2000];real array y[1:2000]; ...... end;end;end;end;
Control structuresControl structures
GotoGoto
If-then-elseIf-then-else
For loopFor loop
SwitchSwitch
Call by name vs. by valueCall by name vs. by value
Call by name is defaultCall by name is default
Call by name: re-evaluate the actual parameter Call by name: re-evaluate the actual parameter on every useon every use For actual parameters that are For actual parameters that are simple variablessimple variables, it’s , it’s
the same as call by referencethe same as call by reference For actual parameters that are For actual parameters that are expressionsexpressions, the , the
expression is re-evaluated on each accessexpression is re-evaluated on each access
No other language ever used call by name…No other language ever used call by name…
Call by nameCall by name
beginbegin integer n;integer n; procedure p (k: integer)procedure p (k: integer) beginbegin print (k);print (k); n := n+1;n := n+1; print (k);print (k); end;end; n := 0;n := 0; p (n+10);p (n+10);end;end;
n is set to 0
parameter is n+10 (not just 10)
prints n+10, which is 10
n is still 0; thus, n becomes 1
prints n+10, which is 11
parameter is n+10 (not just 10)
Problems with AlgolProblems with Algol
Didn’t include a I/O libraryDidn’t include a I/O library Thus, each implementation had a different means for Thus, each implementation had a different means for
I/OI/O This caused compatibility problemsThis caused compatibility problems And no standard way to write a Hello World programAnd no standard way to write a Hello World program
Algol 68Algol 68
Successor to Algol 60Successor to Algol 60
Included may new featuresIncluded may new features UnionsUnions Operator overloadingOperator overloading CastingCasting Standardized input and outputStandardized input and output Parallel processingParallel processing
Rarely implemented by the compilers, thoughRarely implemented by the compilers, though
Life of Algol 60Life of Algol 60
Didn’t achieve widespread useDidn’t achieve widespread use
Extremely important in the history of PLsExtremely important in the history of PLs
Successors: Pascal, Modula, Ada, othersSuccessors: Pascal, Modula, Ada, others
Produced important work on:Produced important work on: Lexical analysisLexical analysis ParsingParsing Compilation techniques for block-structured Compilation techniques for block-structured
languageslanguages