PZ05A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, 2000 1 PZ05A - Abstract data types Programming Language Design.

Slides:



Advertisements
Similar presentations
Programming Languages and Paradigms
Advertisements

Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
Abstract Data Types Data abstraction, or abstract data types, is a programming methodology where one defines not only the data structure to be used, but.
Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.
Implementing Subprograms
Chapter 9 Subprogram Control Consider program as a tree- –Each parent calls (transfers control to) child –Parent resumes when child completes –Copy rule.
PZ10A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ10A - Heap storage Programming Language Design and.
PZ02A - Language translation
PZ06A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ06A - Inheritance Programming Language Design and Implementation.
Run time vs. Compile time
Semantics of Calls and Returns
PZ09A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ09A - Activation records Programming Language Design.
PZ04A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ04A - Scalar and composite data Programming Language.
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.
PZ05B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ05B - Type equality Programming Language Design and.
PZ01A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ01A -- Introduction Programming Language Design and.
1 CS2104- ADT/Inheritance Lecturer: Dr. Abhik Roychoudhury School of Computing Reading : Chapter 7.1, 7.2 of textbook.
PZ11A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ11A - Exception handling Programming Language Design.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
Names Variables Type Checking Strong Typing Type Compatibility 1.
CS 2104 Prog. Lang. Concepts Subprograms
Programming Languages and Design Lecture 7 Subroutines and Control Abstraction Instructor: Li Ma Department of Computer Science Texas Southern University,
1 Names, Scopes and Bindings Aaron Bloomfield CS 415 Fall
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.
CSC3315 (Spring 2008)1 CSC 3315 Subprograms Hamid Harroud School of Science and Engineering, Akhawayn University
PZ06C Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ06C - Polymorphism Programming Language Design and.
Polymorphism Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section 7.3.
Run-Time Storage Organization Compiler Design Lecture (03/23/98) Computer Science Rensselaer Polytechnic.
RUN-Time Organization Compiler phase— Before writing a code generator, we must decide how to marshal the resources of the target machine (instructions,
A.Alzubair Hassan Abdullah Dept. Computer Sciences Kassala University A.Alzubair Hassan Abdullah Dept. Computer Sciences Kassala University NESTED SUBPROGRAMS.
Concepts of programming languages Chapter 5 Names, Bindings, and Scopes Lec. 12 Lecturer: Dr. Emad Nabil 1-1.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
1 Chapter 11 © 1998 by Addison Wesley Longman, Inc The Concept of Abstraction - The concept of abstraction is fundamental in programming - Nearly.
Data Structure and Algorithm: CIT231 Lecture 3: Arrays and ADT DeSiaMore DeSiaMorewww.desiamore.com/ifm1.
ISBN Chapter 5 Names, Bindings, Type Checking, and Scopes.
PZ09A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ09A - Activation records Programming Language Design.
1 Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
1 CSC 533: Programming Languages Spring 2014 Subprogram implementation  subprograms (procedures/functions/subroutines)  subprogram linkage  parameter.
Abstract data types Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Data Types In Text: Chapter 6.
PZ11A Programming Language design and Implementation -4th Edition
Names and Attributes Names are a key programming language feature
CS 326 Programming Languages, Concepts and Implementation
Type Checking, and Scopes
11.1 The Concept of Abstraction
Types of Programming Languages
PZ06C - Polymorphism Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section 7.3 PZ06C.
PZ05A - Abstract data types
CSC 533: Programming Languages Spring 2015
Subprograms and Programmer Defined Data Type
PZ09A - Activation records
PZ04A - Scalar and composite data
Abstract data types Programming Language Design and Implementation
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.
Polymorphism Programming Language Design and Implementation
Abstract data types Programming Language Design and Implementation
Programming Languages and Paradigms
Polymorphism Programming Language Design and Implementation
Abstract data types Programming Language Design and Implementation
Polymorphism Programming Language Design and Implementation
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
CSC 533: Programming Languages Spring 2018
CSC 533: Programming Languages Spring 2019
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Polymorphism Programming Language Design and Implementation
11.1 The Concept of Abstraction
Chapter 11 Abstraction - The concept of abstraction is fundamental in
Presentation transcript:

PZ05A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ05A - Abstract data types Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section

PZ05A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, Development of data types FORTRAN, ALGOL - primitive data that mimics machine hardware COBOL, PL/I - Extend primitive data with collections of primitive objects, records Pascal, ALGOL-68 - Extends functionality with new types. Create functions that use those new types Age of encapsulation (Parnas)- Information hiding Create data type signatures Overloading Inheritance New languages: Alphard (Wulf, Shaw, LondonU) Euclid (Toronto) CLU (Liskov) Modula (Wirth) Smalltalk (Kay) Ada (DoD) Eiffel (Meyer) Object Orientation - Smalltalk-80, C++, Miranda, ML, FORTRAN-90, Ada-95

PZ05A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall,

PZ05A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, Types A type (data type) is a set of values that an object can have. An abstract data type (ADT) is a: data type Set of functions (operations) that operates on data of that type Each function is defined by its signature. Can also specify operations formally (see section 4.2.5) (Algebraic data types): f(g(A,S)) = A

PZ05A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, Example ADT ADT student: Operations: SetName: name x student  student GetName: student  name SetCourse: course x student  student GetCourse: student  course * GetCredits: student  integer In this example, Name and Course are undefined ADTs. They are defined by some other abstraction. Information hiding: We have no idea HOW a student object is stored, nor do we care. All we care about is the behavior of the data according to the defined functions.

PZ05A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, Information hiding Information hiding can be built into any language C example: typedef struct {i:int;... } TypeA; typedef struct {... } TypeB; P1 (TypeA X, other data) {... } - P1:other data  TypeA P2 (TypeB U, TypeA V) {... } - P2:TypeA  TypeB Problems with this structure: No enforcement of information hiding. In P2 can write V.i to access component i of of TypeA object instead of calling P1. Success depends upon conventions But advantage is that it can be done in Pascal or C. We will look at mechanisms later to enforce information hiding (Smalltalk, C++, Java, Ada). We will call this enforcement encapsulation.

PZ05A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, Implementation of subprogram storage Before looking at ADTs in detail, we first need to understand the usual method for subprograms to create local objects. Each subprogram has a block of storage containing such information, called an activation record. Consider the following C subprogram: float FN( float X, int Y) const initval=2; #define finalval 10 float M(10); int N; N = initval; if(N<finalval){... } return (20 * X + M(N)); } Information about procedure FN is contained in its activation record.

PZ05A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, Activation records Above left: Code produced by compiler for the execution of procedure FN. Above right: Data storage needed by procedure FN during execution. Compiler binds each identifier in FN with a storage location in activation record.

PZ05A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, Dynamic nature of activation records Each invocation of FN causes a new activation record to be created. Thus the static code generated by the compiler for FN will be associated with a new activation record, each time FN is called. As we will see later, a stack structure is used for activation record storage.

PZ05A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, Storage management Local data is stored in an area called an activation record (also called a stack frame). Address data is a two step process: 1. Get a pointer to the relevant activation record containing the declarations. 2. Find the offset in that activation record for the data item.

PZ05A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, Lifetime IMPORTANT: 1. The activation record pointer is determined at during program execution. It occurs frequently, so it should be an efficient calculation. 2. The offset within an activation record is fixed and determined during compilation. It should require no - or minimal - calculations. The lifetime of a variable is that period during program execution when the storage for the declared variable exists in some activation record (i.e., from the time the activation record for the declaring procedure is created until that activation record is destroyed). The scope of a variable is the portion of the source program where the data item can be accessed (i.e., the name of the item is a legal reference at that point in the program).

PZ05A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, Lifetimes (continued) Two models of data lifetimes: Static: Based upon the static structure of a program Dynamic: Based upon the execution of a program In general, static lifetimes are implemented in stacks; dynamic lifetimes implemented in heaps.

PZ05A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, Lifetimes of variables Lifetime of variable X is the period when the activation record for P exists. Note that we can change the scope, but the not lifetime of a variable by nesting procedures: