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

Slides:



Advertisements
Similar presentations
1) Scope a] Ada scope rules b] C scope rules 2) Parameter passing a] Ada parameter modes b) Parameter passing mechanisms COMP205 IMPERATIVE LANGUAGES 13.
Advertisements

Semantic Analysis Chapter 6. Two Flavors  Static (done during compile time) –C –Ada  Dynamic (done during run time) –LISP –Smalltalk  Optimization.
1 Compiler Construction Intermediate Code Generation.
CS 415: Programming Languages Algol Aaron Bloomfield Fall 2005.
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Chapter 5 Names, Bindings, and Scopes
CS ExCo Advanced in Topics Object-Oriented Programming.
Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 18.
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,
Copyright © 1995 by Addison-Wesley Publishing Co. 1 Names - Design issues: - Maximum length? - Are connector characters allowed? - Are names case sensitive?
Chapter 9: Subprogram Control
CSCE 330 Project Algol 68 Joe PuzioWael AL-Fayez Gaurav ShahRonak Patel.
ISBN Chapter 9 Subprograms and Functions –Design Issues –Local Referencing Environments –Parameter-Passing Methods –Parameters that are Subprogram.
1 Contents. 2 Run-Time Storage Organization 3 Static Allocation In many early languages, notably assembly and FORTRAN, all storage allocation is static.
Scope.
Imperative Programming
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.
COMP4730/2003/lec5/H.Melikian Names, Bindings,Type Checking and Scopes (Chapter 5) - Design issues: - Maximum length? - Are connector characters allowed?
CSC3315 (Spring 2009)1 CSC 3315 Programming Languages Hamid Harroud School of Science and Engineering, Akhawayn University
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.
Adapted from Prof. Necula UCB CS 1641 Overview of COOL ICOM 4029 Lecture 2 ICOM 4029 Fall 2008.
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 Names, Bindings, and Scopes. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Chapter 5 Topics Introduction Names Variables The Concept.
ISBN Chapter 5 Names, Bindings, and Scopes.
Basic Semantics Associating meaning with language entities.
ISBN Chapter 5 Names, Bindings, and Scopes.
COP4020 Programming Languages Names, Scopes, and Bindings Prof. Xin Yuan.
The Evolution of Programming Languages Day 2 Lecturer: Xiao Jia The Evolution of PLs1.
COMP3190: Principle of Programming Languages
Names, Bindings, and Scope Session 3 Course : T Programming Language Concept Year : February 2011.
Structure of Programming Languages Names, Bindings, Type Checking, and Scopes.
Ch. 5 Ch. 51 jcmt Summer 2003Programming Languages CSE3302 Programming Languages (more notes) Summer 2003 Dr. Carter Tiernan.
Concepts of programming languages Chapter 5 Names, Bindings, and Scopes Lec. 12 Lecturer: Dr. Emad Nabil 1-1.
Programming Languages and Design Lecture 6 Names, Scopes and Binding Instructor: Li Ma Department of Computer Science Texas Southern University, Houston.
Programming Languages: Design, Specification, and Implementation G Rob Strom September 21, 2006.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
Variables reference, coding, visibility. Rules for making names  permitted character set  maximum length, significant length  case sensitivity  special.
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.
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.
Names, Bindings, Type Checking and Scopes. Chapter 5 Topics Introduction Names Variables The Concept of Binding Type Checking Strong Typing Type Equivalence.
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.
Code Generation Instruction Selection Higher level instruction -> Low level instruction Register Allocation Which register to assign to hold which items?
CSE3302 Programming Languages (notes continued)
Names and Attributes Names are a key programming language feature
Type Checking, and Scopes
Review: Chapter 5: Syntax directed translation
Names, Bindings, and Scopes
FORTRAN 04 February 1999; CS655.
Midterm Review In Text: Chapters 1-3, 5, 15.
Scope of Variables.
Scope, Visibility, and Lifetime
Final Review In Text: Chapters 1-3, 5-12,
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Names and Binding In Text: Chapter 5.
Names, Bindings, and Scopes
ICOM 4029 Fall 2003 Lecture 2 (Adapted from Prof. Necula UCB CS 164)
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Chapter 3 Discussion Pages
Presentation transcript:

Programming Languages: Design, Specification, and Implementation G Rob Strom September 14, 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

Review: BNF, Concrete and Abstract Syntax Trees ( A + B * C ) * DA B C D f t ff t e t t f e e f t * + * expr ::= expr “+” term | expr “–” term | term term ::= term “*” factor | term “/” factor | factor factor ::= number | identifier | “(“ expr “)”

Use of types Operator overloading Polymorphism Conversion Implementation choices Error checking Differences: What’s typed? The value, the container, or the name If the name can refer to different containers must they all be the same type?

Types Integer Float (In COBOL: Decimal) Second-class: “Hollerith”

Fortran Example

Fortran: Name Spaces Global Procedures and Functions Common Blocks Statically Scoped Variables Name Spaces One global name space One per procedure/function Dynamically Scoped None

Fortran: Static and Runtime Naming; Scope PROGRAM MAIN … COMMON/ FOO/A,B,I/ BAR/C, D/ BAZ/E, F, J DIMENSION Z(999) … CALL SWAP(W, Z(200)) … SUBROUTINE SWAP(X,Y) COMMON/ FOO/OLDX /GORP/K TEMPX = X X = Y Y = TEMPX OLDX = TEMPX … FUNCTION N (I) COMMON/ BAZ/X/GORP/L NTEMP = I**2 – 3*I + 2 N = NTEMP * L …

References: Invisible but Significant EQUIVALENCE COMMON Binding

Control flow “Spaghetti” code GOTO and assigned GOTO Can jump anywhere except: To another procedure Inside a DO loop from outside the loop IF tests and jumps, not blocks DO loops and jumps

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

What can go wrong Syntax problems DO I = 1.3 Passing a constant CALL SWAP(2, 3) Unchecked Bounds Uninitialized Variables

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 in Algol 60 Call by name Dynamic array bounds Recursive creation of local stack variables Own variables Nested declarations, scopes Inner procedures

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

New things that can go wrong Unbounded memory Dangling references via pointers Dangling closures