Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE3302 Programming Languages (notes continued)

Similar presentations


Presentation on theme: "CSE3302 Programming Languages (notes continued)"— Presentation transcript:

1 CSE3302 Programming Languages (notes continued)
Dr. Carter Tiernan CSE 3302 Programming Languages

2 Generality and Hierarchy: Algol-60
Close as possible to standard mathematical notation and readable Usable for describing computing processes Mechanically translatable to machine language CSE 3302 Programming Languages

3 Programming Languages
B C D 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 CSE 3302 Programming Languages

4 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 A B C D CSE 3302 Programming Languages

5 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 CSE 3302 Programming Languages

6 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 CSE 3302 Programming Languages

7 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. CSE 3302 Programming Languages

8 Algol: Stacks for management
B C D 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 D C A CSE 3302 Programming Languages

9 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 CSE 3302 Programming Languages

10 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 CSE 3302 Programming Languages

11 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 CSE 3302 Programming Languages

12 Programming Languages
Algol: Arrays Generalized Dynamic due to stack allocation Data Types Strong typing Coercions and conversions Type system as “safety feature” CSE 3302 Programming Languages

13 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 CSE 3302 Programming Languages

14 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” CSE 3302 Programming Languages

15 Programming Languages
Algol: More control Hierarchical structure Structured programming Recursion supported Instantiation of locals Every call creates a new activation record Conditional expression CSE 3302 Programming Languages

16 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 CSE 3302 Programming Languages

17 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 CSE 3302 Programming Languages

18 Language Design Issues
GO TO controversy Conceptual models System image Feature interaction CSE 3302 Programming Languages

19 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 CSE 3302 Programming Languages

20 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 CSE 3302 Programming Languages

21 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 CSE 3302 Programming Languages

22 Programming Languages
Algol: Lexics Lexical conventions Reserved words Keywords (Algol approach) Keywords in context Dangling else Style CSE 3302 Programming Languages

23 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 CSE 3302 Programming Languages

24 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 CSE 3302 Programming Languages

25 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 CSE 3302 Programming Languages

26 Second Generation Languages
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 2nd CSE 3302 Programming Languages


Download ppt "CSE3302 Programming Languages (notes continued)"

Similar presentations


Ads by Google