Programming Languages: Design, Specification, and Implementation G22.2210-001 Rob Strom September 21, 2006.

Slides:



Advertisements
Similar presentations
1 Scheme and Functional Programming Aaron Bloomfield CS 415 Fall 2005.
Advertisements

Chapter 3 Functional Programming. Outline Introduction to functional programming Scheme: an untyped functional programming language.
CS ExCo Advanced in Topics Object-Oriented Programming.
Implementing Subprograms
(1) ICS 313: Programming Language Theory Chapter 10: Implementing Subprograms.
Chapter 8 Runtime Support. How program structures are implemented in a computer memory? The evolution of programming language design has led to the creation.
CS 330 Programming Languages 10 / 16 / 2008 Instructor: Michael Eckmann.
ALGOL 60 Design by committee of computer scientists: Naur, Backus, Bauer, McCarthy, van Wijngaarden, Landin, etc. Design by committee of computer scientists:
Cse321, Programming Languages and Compilers 1 6/12/2015 Lecture #17, March 12, 2007 Procedure Abstraction, Name Spaces, Scoping Rules, Activation Records,
1 Names, Scopes and Bindings. 2 Names Kinds of names Kinds of names Variables, functions, classes, types, labels, blocks, operators, tasks, etc. Variables,
Programming Languages: Design, Specification, and Implementation G Rob Strom September 14, 2006.
Variables Six properties: Binding times of properties:
Chapter 10 Storage Management Implementation details beyond programmer’s control Storage/CPU time trade-off Binding times to storage.
Run time vs. Compile time
Catriel Beeri Pls/Winter 2004/5 environment 68  Some details of implementation As part of / extension of type-checking: Each declaration d(x) associated.
The environment of the computation Declarations introduce names that denote entities. At execution-time, entities are bound to values or to locations:
Chapter 9: Subprogram Control
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
1 Run time vs. Compile time The compiler must generate code to handle issues that arise at run time Representation of various data types Procedure linkage.
Programming Languages: Design, Specification, and Implementation G Rob Strom October 19, 2006.
1 Contents. 2 Run-Time Storage Organization 3 Static Allocation In many early languages, notably assembly and FORTRAN, all storage allocation is static.
© 2003 G. Drew Kessler and William M. Pottenger1 Subroutines (Part 1) CSE 262, Spring 2003.
Chapter TwelveModern Programming Languages1 Memory Locations For Variables.
CS 403: Programming Languages Lecture 2 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Names and Binding In procedural programming, you write instructions the manipulate the “state” of the process where the “state” is the collection of variables.
Names Variables Type Checking Strong Typing Type Compatibility 1.
5-1 Chapter 5: Names, Bindings, Type Checking, and Scopes Variables The Concept of Binding Type Checking Strong Typing Type Compatibility Scope and Lifetime.
Functional Programming Universitatea Politehnica Bucuresti Adina Magda Florea
Programming Languages and Design Lecture 7 Subroutines and Control Abstraction Instructor: Li Ma Department of Computer Science Texas Southern University,
Runtime Environments Compiler Construction Chapter 7.
1 Names, Scopes and Bindings Aaron Bloomfield CS 415 Fall
Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.
10/16/2015IT 3271 All about binding n Variables are bound (dynamically) to values n values must be stored somewhere in the memory. Memory Locations for.
Chapter 3 :: Names, Scopes, and Bindings Michael L. Scott School of Computer & Information Engineering, Sangji University Kwangman.
Copyright © 2005 Elsevier Chapter 8 :: Subroutines and Control Abstraction Programming Language Pragmatics Michael L. Scott.
Names. 2 Variables  binding is an association between an entity (such as a variable) and a property (such as its value). A binding is static if the association.
1 Scope Rules (Section 3.3) CSCI 431 Programming Languages Fall 2003 A compilation of material developed by Felix Hernandez-Campos and Michael Scott.
Basic Semantics Associating meaning with language entities.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 8.
1 Records Record aggregate of data elements –Possibly heterogeneous –Elements/slots are identified by names –Elements in same fixed order in all records.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 9.
COMP3190: Principle of Programming Languages
Structure of Programming Languages Names, Bindings, Type Checking, and Scopes.
Concepts of programming languages Chapter 5 Names, Bindings, and Scopes Lec. 12 Lecturer: Dr. Emad Nabil 1-1.
1 Structure of Compilers Lexical Analyzer (scanner) Modified Source Program Parser Tokens Semantic Analysis Syntactic Structure Optimizer Code Generator.
ISBN Chapter 10 Implementing Subprograms.
CS 330 Programming Languages 10 / 23 / 2007 Instructor: Michael Eckmann.
Cs3180 (Prasad)L156HOF1 Higher-Order Functions. cs3180 (Prasad)L156HOF2 Equivalent Notations (define (f x y) (… body …)) = (define f (lambda (x y) (…
Subprograms - implementation. Calling a subprogram  transferring control to a subprogram: save conditions in calling program pass parameters allocate.
Names, Scope, and Bindings Programming Languages and Paradigms.
Programming Languages: Design, Specification, and Implementation G Rob Strom September 28, 2006.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Operational Semantics (Slides mainly.
1 Compiler Construction Run-time Environments,. 2 Run-Time Environments (Chapter 7) Continued: Access to No-local Names.
CSI 3125, Data Types, page 1 Data types Outline Primitive data types Structured data types Strings Enumerated types Arrays Records Pointers Reading assignment.
Code Generation Instruction Selection Higher level instruction -> Low level instruction Register Allocation Which register to assign to hold which items?
CS314 – Section 5 Recitation 9
Functional Programming
Data Types In Text: Chapter 6.
Names and Attributes Names are a key programming language feature
CS 326 Programming Languages, Concepts and Implementation
Type Checking, and Scopes
CS 326 Programming Languages, Concepts and Implementation
Implementing Subprograms
Names.
Names, Binding, and Scope
Chap. 8 :: Subroutines and Control Abstraction
Chap. 8 :: Subroutines and Control Abstraction
Bindings, Scope, and Extent
Types and Related Issues
Run-time environments
Presentation transcript:

Programming Languages: Design, Specification, and Implementation G Rob Strom September 21, 2006

Administrative Alternative mailing address for me: Everyone should subscribe to the class mailing list: Readings: Remainder of chapter 3 of Gelernter and Jagannathan; chapter 7; MIT Scheme documentation Gelernter textbook: we will notify about availability of photocopied notes Homework due end of class 4 (Scheme): Convert list of atoms to concrete tree according to the simple grammar Convert concrete tree to abstract tree

Invariants BigA = max(A(1..1))  1 <= N BigA = max(A(1..I-1))  I <= N BigA = max(1..I))  I <= N BigA = max(A(1..I-1))  A(I) > BigA  I <= N BigA = max(A(1..I-1))  BigA >= A(I)  I <= N BIGA = A(1) 5DO 20 I = 2, N 30IF (BIGA-A(I)) 10,21,21 10BIGA = A(I) 21 CONTINUE 20CONTINUE PRINT … BigA = max(A(1..I-1))  I-1 <= N A(I) = max(1..I))  I <= N BigA = max(1..I))  I <= N BigA = max(1..I-1))  I-1 <= N 1 <= N BigA = max(A(1..I-1))  I-1 N BigA = max(A(1..N))

FORTRAN: Everything static Dimensions of arrays (although not necessarily visible to subroutines) Number of instances of storage blocks All programs both static and global (except statement functions) All I/O devices static and global

FORTRAN: Summary Introduces: Types with operator overloading Arrays Separate compilation 2 levels of name space: Global and Local Static name spaces Procedures and Functions: call by reference Specialized I/O Pragma (Frequency Statement) Differences w.r.t. modern languages: No Lexical level (tokens) No 1 st class char/string No 1 st class procedure No recursion No dynamic data No nesting No closures/objects Gotchas: Near unrestricted GOTO Name aliasing No checks for Type errors Overwriting constants Overwriting array bounds

Algol 60: Static and Runtime Naming; Scope PROCEDURE MAIN; … x := read(); BEGIN INTEGER ARRAY FOO[1:X]; … j := 20; blat(j, FOO(j)); … PROCEDURE blat(x,y); BEGIN x := 1000; y:= 1000 END … INTEGER PROCEDURE random; BEGIN OWN INTEGER seed; random := seed := some new value … END …

New features Call by name Dynamic array bounds Recursive creation of local stack variables Own variables Nested declarations, scopes Inner procedures

Call by name Requires access to the caller’s environment from within the environment where the name is used Equivalent to a “closure” with no parameters

Beyond: Algol 68; PL/I; C Fully dynamic storage – e.g. PL/I’s storage classes: STATIC – like FORTRAN (local & external) AUTOMATIC – like Algol 60 non-own CONTROLLED – dynamically allocated X BASED(Y) – dynamically allocated with pointer Exception checking and Exception Handlers

Memory Heap (PL/I) DCL 1 ARecordTemplate BASED(P), 2 AField FIXED, 2 AnotherField FLOAT; DCL Q Pointer; /* Untyped  */ ALLOCATE ARecordTemplate; Q=P; Q->AField = 2;

Closures (PL/I): A: PROCEDURE (…) DCL X FIXED INIT(3); … AddX: PROCEDURE (Y) RETURNS(FIXED); DCL Y FIXED; RETURN(X+Y); END AddX; Z = AddX(5); CALL AFunc(AddX); … AFunc: PROCEDURE(F); DCL F ENTRY; DCL X FIXED INIT(4); DCL Z FIXED; … Z = F(5); … END AFunc;

Closures AddX is a closure, that is: It is a function whose execution has access to an external environment (the variable X) If invoked from AFunc, it uses: AddX’s environment’s value of X (static binding) Not the most recent value of X on the stack, the one defined inside AFunc (dynamic binding) LISP was the earliest language to do closures, and it did them the other way (dynamic)

New things that can go wrong Memory fills with unaccessible cells Type-mismatches on references and entry variables Dangling references via pointers Dangling closures For an amusing critique of C vs PL/I see:

Scheme (define isort ( lambda (l) (letrec ( ; defines a list of bindings (here just 1) (insert ( ; inserts item x in sorted order to list l lambda (x l) (if (null? l) (list x) (if (<= x (car l)) (cons x l) (cons (car l) (insert x (cdr l)))) )))) ; the below is executed in the context of the bindings (if (null? l) nil (insert (car l) (isort (cdr l)))) ) ))

Essential features in Scheme 1 st class procedures Dynamically created procedures Based on lambda calculus over atoms and pairs; by convention, lists are pairs Continuations Automatic garbage collection Applicative style: binding, no update, no side effects (but there are exceptions to this) Static scoping, but no static typing! Simple syntax (afunction arg1 arg2 …) ; function application Special forms, e.g. (if … )