Subprograms and Programmer Defined Data Type

Slides:



Advertisements
Similar presentations
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 12P. 1Winter Quarter User-Written Functions.
Advertisements

Intermediate Code Generation
Programming Languages and Paradigms
CSI 3120, Implementing subprograms, page 1 Implementing subprograms The environment in block-structured languages The structure of the activation stack.
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Chapter 9 Subprograms Specification: name, signature, actions Signature: number and types of input arguments, number and types of output results –Book.
Chapter 5 ( ) of Programming Languages by Ravi Sethi
Subprogram Control - Data sharing Mechanisms to exchange data Arguments - data objects sent to a subprogram to be processed. Obtained through  parameters.
Chapter 7: User-Defined Functions II
Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.
PZ05A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ05A - Abstract data types Programming Language Design.
Encapsulation by Subprograms and Type Definitions
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
Chapter 9: Subprogram Control
PZ05B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ05B - Type equality Programming Language Design and.
Abstract Data Types and Encapsulation Concepts
 Introduction Introduction  Types of Function Types of Function  Library function Library function  User defined function User defined function 
Programming Languages
1 Chapter 5: Names, Bindings and Scopes Lionel Williams Jr. and Victoria Yan CSci 210, Advanced Software Paradigms September 26, 2010.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
C++ Programming: From Problem Analysis to Program Design, Fifth Edition, Fifth Edition Chapter 7: User-Defined Functions II.
CSC3315 (Spring 2008)1 CSC 3315 Subprograms Hamid Harroud School of Science and Engineering, Akhawayn University
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
Concepts of programming languages Chapter 5 Names, Bindings, and Scopes Lec. 12 Lecturer: Dr. Emad Nabil 1-1.
Chapter 3 Functions. 2 Overview u 3.2 Using C++ functions  Passing arguments  Header files & libraries u Writing C++ functions  Prototype  Definition.
1 Chapter 11 © 1998 by Addison Wesley Longman, Inc The Concept of Abstraction - The concept of abstraction is fundamental in programming - Nearly.
 Static  Example for Static Field  Example for Static Method  Math class methods  Casting  Scope of Declaration  Method Overloading  Constructor.
Methods.
Overview: Lecture 6: Dolores Zage. What is a program? n Operations that are to be applied to certain data in a certain sequence (definition holds for.
Programming Fundamentals Enumerations and Functions.
Abstract data types Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Implementing Subprograms
Memory Management.
Constructors and Destructors
Functions + Overloading + Scope
Data Types In Text: Chapter 6.
Run-Time Environments Chapter 7
Implementing Subprograms Chapter 10
Chapter 7: User-Defined Functions II
Abstract Data Types and Encapsulation Concepts
Type Checking Generalizes the concept of operands and operators to include subprograms and assignments Type checking is the activity of ensuring that the.
11.1 The Concept of Abstraction
Implementing Subprograms
User Defined Functions
PZ05A - Abstract data types
Abstract Data Types and Encapsulation Concepts
Chapter 5 Function Basics
CSC 533: Programming Languages Spring 2015
Constructors and Destructors
Abstract data types Programming Language Design and Implementation
Chapter 9 Subprograms Fundamentals of Subprograms
Defining Classes and Methods
Abstract data types Programming Language Design and Implementation
Defining Classes and Methods
Abstract data types Programming Language Design and Implementation
Type equality Programming Language Design and Implementation
Type equality Programming Language Design and Implementation
Types of loops definite loop: A loop that executes a known number of times. Examples: Repeat these statements 10 times. Repeat these statements k times.
Type equality Programming Language Design and Implementation
CSC 533: Programming Languages Spring 2018
Type equality Programming Language Design and Implementation
CSC 533: Programming Languages Spring 2019
CPS125.
Type equality Programming Language Design and Implementation
PZ05B - Type equality Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section 6.4 PZ05B.
SPL – PS3 C++ Classes.
11.1 The Concept of Abstraction
Chapter 11 Abstraction - The concept of abstraction is fundamental in
Presentation transcript:

Subprograms and Programmer Defined Data Type UNIT 3 Encapsulation by Subprogram Generic Subprogram 12/3/2018

ENCAPSULATION BY SUBPROGRAM A subprogram is a n abstract operation defined by the programmer. A subprogram have to views: Program Design Level Language Design Level At a program level subprogram represents a an abstract operation that programmer define rather than primitive operation that are built in to language Subprogram as an Abstract Operation: A subprogram definition has two parts: Specification Implementation Specification of a program 12/3/2018

ENCAPSULATION BY SUBPROGRAM Specification of a program: It includes: The name of the subprogram Signature(also known as proto type) giving the number of arguments ,their order, data type of each as well as number of result their order, and data type of each The action performed by the subprogram An example of a syntax: float FN(float X, int Y) That specifies the signature as: FN: real * integer -- real 12/3/2018

SUBPROGRAM IMPLEMENTATION A subprogram is implemented using the data structure and operations provided by the programming language. The implementation is defined by the subprogram body , thst consists of local data declaration defining the data structure used by sub program and statements defining the actions to be taken when subprogram is executed. The declaration and statements are usually encapsulated so that neither the local data nor statements are accessible to user of the subprogram: The user may only invoke the subprogram with a particular set of arguments And receives the output results 12/3/2018

SUBPROGRAM IMPLEMENTATION The syntax of a subprogram Signature of a subprogram Declaration of local data objects Sequence of statements defining the action of a subprogram Each invocation of a subprogram requires the arguments of the proper types Type checking may be same as in data types Static Type Checking Dynamic Type Checking 12/3/2018

SUBPROGRAM DEFINITION & INVOCATION During the execution of a program if a subprogram is called(invoked) an activation Of a subprogram is created. When a execution of subprogram is complete the activation is destroyed. If another call is made , a new activation is created .From a single subprogram it is possible to many activation may be created during program execution..A definition is information that present at the time of translation. An activation has a life time-the time during execution between call that creates it and returns that destroys it. 12/3/2018

SUBPROGRAM DEFINITION & INVOCATION To construct a particular activation of a subprogram it is required to split in to parts: A static part : Also known as code segment made with the help of constant and executable code. It should be invariant during execution of a subprogram and so a single copy may be shared by all act ovation A dynamic Part Known as activation record made with the help of parameter, function results and local data some other point like temporary storage areas , return point . The size and structure of activation record for a subprogram can be find out at translation time 12/3/2018

GENERIC SUBPROGRAM The specification of subprogram lists the number, order and data types of arguments. A generic subprogram is one with a single name but several different definitions defined be different signature. A generic subprogram is said to be overloaded Activation Record for FN Code segment for FN Activation Record for FN Activation Record for FN Shared Code and Separate Activation Records 12/3/2018

Typedef definition name TYPE DEFINITION Some language provides a flexibility that user can define their own data type. This mechanism is termed as Type Definition Like in Pascal type Rational =Record numerator :integer; denominator: integer; end var A,B,C: Rational; Syntax is : Typedef definition name typedef structRationalType {int numerator; int denominator;} Rational Rational A,B,C; in C langauge 12/3/2018

Assignment What is Encapsulation. Define subprogram