260 likes | 393 Views
CSE3302 Programming Languages (notes continued). Dr. Carter Tiernan. Generality and Hierarchy: Algol-60. Close as possible to standard mathematical notation and readable Usable for describing computing processes Mechanically translatable to machine language. A. B. D. C. Algol Design.
E N D
CSE3302Programming Languages(notes continued) Dr. Carter Tiernan Programming Languages
Generality and Hierarchy:Algol-60 • Close as possible to standard mathematical notation and readable • Usable for describing computing processes • Mechanically translatable to machine language Programming Languages
A B D C Algol Design • Hierarchical structure / Nesting • (unlike C & C++) • Declarative and Imperative constructs • Variable, procedure, and switch • Computational and control-flow • Compilation handled differently than Fortran • Stack for run-time structures Programming Languages
A B D C Algol: Name Structures • Names are NOT statically bound • Block structure supports scoping • Blocks are compound statements with declarations • Scope - contour diagrams • Context • Inner blocks implicitly inherit access to variables in its immediately surrounding block Programming Languages
Algol: Blocks • Allows shared data to be easily organized with the subprograms that need it (but does allow indiscriminate access) • Scoping choices • Static: called in the environment of its definition (used exclusively in Algol) • Dynamic: called in the environment of its caller Programming Languages
Dynamic Scoping • Called in environment of caller • Can write general procedures that make use of variables and procedures supplied by caller’s environment • Vulnerable to being called from an environment without correct supporting procedures • Not generally used in current languages Programming Languages
Static Scoping • Called in the environment of its definition • Requires the user to pass parameters of local environment • Cannot behave differently based on call location only • Ensures that the static structure of the program more closely agrees with the dynamic behavior of the program. Programming Languages
A B D C D C A Algol: Stacks for management • Disjoint blocks allow conservation of memory on the stack • Assumption: a variable is retained only so long as the program is executing in the scope of that variable or in a block that will return to the scope of that variable • Blocks follow LIFO execution; ergo, a stack handles the activation records in a LIFO fashion Programming Languages
Responsible Design • Understand the programmers’ problem • Provide a high quality solution • Which is not necessarily the solution the programmers (or users) asked for • Responsible Design Principle • Caveat: If the user wants it and you don’t supply it (in their fashion), they may not accept your alternate (even if better) solution Programming Languages
Algol: Data Structures • Primitives are scalars • Boolean, integer, and real • No double precision because it’s machine dependent • No complex due to tradeoffs of usefulness vs. complexity • Limited string type that required procedures coded in some other language in order to be output or used Programming Languages
Zero-One-Infinity Principle • Supports regularity - easier to learn, remember, and master • Eliminates arbitrary numerical limits • Applies to arrays in • Number of dimensions • Start and end values for indices Programming Languages
Algol: Arrays • Generalized • Dynamic due to stack allocation Data Types • Strong typing • Coercions and conversions • Type system as “safety feature” Programming Languages
Algol: Control structures • Primitives • Assignment := • No input/output - handled with library routines • Structures • Regularize the FORTRAN structures • if condition then statement1 else statement2 • for initialization keyword test do statement Programming Languages
Algol: Control and nesting • All control structures can handle arbitrary number of bracketed statements • Compound statements formed with begin and end • Algol structuring led to Dijkstra’s letter, “GOTO Considered Harmful” Programming Languages
Algol: More control • Hierarchical structure Structured programming • Recursion supported • Instantiation of locals • Every call creates a new activation record • Conditional expression Programming Languages
Algol: Parameter passing • Passing by value • Local copy of parameter • Requires keyword value • Pass by name • Default mode • Based on substitution - Copy Rule • Not actually substituted for formal params Programming Languages
Algol: Pass by name • Compare to pass by reference • Name parameters bound to string • Jensen’s device • Use pass by name with index variable to cycle through array elements • Implementation - thunk • Compile parameter • Pass address of compiled parameter code • Inconsistent behavior Programming Languages
Language Design Issues • GO TO controversy • Conceptual models • System image • Feature interaction Programming Languages
Algol: Control (more) • Out of block GO TOs • Levels of activation must be popped • For-loop • For-list-elements reevaluated every pass • Step, until • While • Enumerated list • All of the above • Baroque Programming Languages
Algol: Control etal. • Switch declaration • Array of statement labels • Processes cases - not necessarily distinct • Best use recombines after cases • Difficult to correlate with dynamic structure • Baroque Programming Languages
Algol: Syntactic Structures • Machine independent / portable • Free-format • Programmers had to think about how it should look • Reflect the structure of the program • Independent of character sets • Reference language • Publication language • Hardware representation Programming Languages
Algol: Lexics • Lexical conventions • Reserved words • Keywords (Algol approach) • Keywords in context • Dangling else • Style Programming Languages
Backus-Naur Form (BNF) • Precise programming language descriptions • English difficult to read • Examples incomplete • Perceptual clarity with precision • Backus - syntactic categories • Naur added improvements to notation • Metalanguage Programming Languages
BNF • Terminals • Nonterminals • Defined in terms of nonterminals and terminals • Recursive definition allowed • Related to Chomsky language hierarchy • Context-free grammar • Regular (non-recursive) grammar Programming Languages
Design Criteria • Efficiency - scientific issues • Minimize resources • Maximize safety • Economy - social issues • Maximize social benefit • Minimize cost • Elegance - aesthetic issues • Function follows form • Manifest interactions Programming Languages
Second Generation Languages 2nd • Elaborations and generalizations of first generation languages • Stronger typing • Hierarchical structure • Blocks • Control flow • Recursion • Parameter passing modes • Free-format syntax • Machine independent conventions • Reserved word/ Keywords Programming Languages