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

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:
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
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
PZ05A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ05A - Abstract data types Programming Language Design.
G. Levine Chapter 6 Chapter 6 Encapsulation –Why do we want encapsulation? Programmer friendliness- programmer need not know about these details –Easier.
Run time vs. Compile time
PZ09A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ09A - Activation records Programming Language Design.
CSC321: Programming Languages Names Chapter 4: Names 4.1 Syntactic Issues 4.2 Variables 4.3 Scope 4.4 Symbol Table 4.5 Resolving References 4.6 Dynamic.
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.
1 CS2104- ADT/Inheritance Lecturer: Dr. Abhik Roychoudhury School of Computing Reading : Chapter 7.1, 7.2 of textbook.
CS 2104 Prog. Lang. Concepts Subprograms
1 Comp 104: Operating Systems Concepts Java Development and Run-Time Store Organisation.
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.
Implementing Subprograms What actions must take place when subprograms are called and when they terminate? –calling a subprogram has several associated.
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.
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.
RUNTIME ENVIRONMENT AND VARIABLE BINDINGS How to manage local variables.
Data Structure and Algorithm: CIT231 Lecture 3: Arrays and ADT DeSiaMore DeSiaMorewww.desiamore.com/ifm1.
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.
Implementing Subprograms
Data Types In Text: Chapter 6.
Names and Attributes Names are a key programming language feature
CS 326 Programming Languages, Concepts and Implementation
Chapter 6 – Data Types CSCE 343.
Type Checking, and Scopes
11.1 The Concept of Abstraction
Types of Programming Languages
Names.
Lecture 9 Concepts of Programming Languages
Implementing Subprograms
Names, Scopes, and Bindings: Scopes
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
Scope, Visibility, and Lifetime
Implementing Subprograms
CSC 533: Programming Languages Spring 2015
Subprograms and Programmer Defined Data Type
PZ09A - Activation records
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
UNIT V Run Time Environments.
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
Lecture 6: Names (Revised based on the Tucker’s slides) 5/27/2019
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
Implementing Subprograms
11.1 The Concept of Abstraction
Lecture 9 Concepts of Programming Languages
Chapter 11 Abstraction - The concept of abstraction is fundamental in
Presentation transcript:

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

Abstract data types 2 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 function prototype  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

Abstract data types 3

4 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 (Algebraic data types): f(g(A,S)) = A

Abstract data types 5 Algebraic Data Types Algebraic data type modeling –A stack of integer push : stack x element  stack pop : stack  stack top : stack  integer U {undefined} empty : stack  Boolean size : stack  integer newstack :  stack

Abstract data types 6 Algebraic Data Types (cont.)  Functions and constraints – pop(push(S,I))  S – pop(newstack)  stack_empty_error – top(push(S,I))  I – top(newstack)  stack_empty_error – empty(newstack)  true – empty(push(newstack,I))  false – size(newsatck)  0 – size(push(S,I))  size(S) + 1  만약 stack 의 크기에 제한이 있다면 –size(S) is equal to limit_of_stack, push(S,I)  stack_full_error

Abstract data types 7 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.

Abstract data types 8 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.

Abstract data types 9 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.

Abstract data types 10 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.

Abstract data types 11 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.

Abstract data types 12 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.

Abstract data types 13 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).

Abstract data types 14 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.  조심 : static type 과는 다르다 !!!

Abstract data types 15 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 not the lifetime of a variable by nesting procedures:

Abstract data types 16 Binding  Scope rule –Lexical binding (deep binding) C, COMMON LISP –Shallow binding (dynamic scope binding) LISP, SNOBOL4, APL, COMMON LISP  Binding time –Runtime (dynamic) binding –Compile time (static) binding

Abstract data types 17 Example main() int a; ① procedure first int a; ② begin call second; end procedure second begin a := 10; ③ end begin call first; end  ③의 a 는 ①의 a 일까, ②의 a 일까 ? 만약 deep binding 을 사용하 면 ①의 a 가 되며, shallow 바인딩을 사용한다면 ②의 a 가 된다.