Organization of Programming Languages

Slides:



Advertisements
Similar presentations
Chapter 7 Introduction to Procedures. So far, all programs written in such way that all subtasks are integrated in one single large program. There is.
Advertisements

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.
Communication between modules, cohesion and coupling
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
(1) ICS 313: Programming Language Theory Chapter 10: Implementing Subprograms.
Chapter 10 Implementing Subprograms. Copyright © 2012 Addison- Wesley. All rights reserved. 1-2 Chapter 10 Topics The General Semantics of Calls and Returns.
Chapter 9 Subprogram Control Consider program as a tree- –Each parent calls (transfers control to) child –Parent resumes when child completes –Copy rule.
Chapter 6: User-Defined Functions I
1 Modularity In “C”. 2 What is Modularity?  Modularity, is the heart of the high level, structured languages.  Means breaking down a big problem into.
Run-Time Storage Organization
Chapter 9: Subprogram Control
Chapter 6: User-Defined Functions I
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
Chapter 9 Introduction to Procedures Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul -
1 Contents. 2 Run-Time Storage Organization 3 Static Allocation In many early languages, notably assembly and FORTRAN, all storage allocation is static.
CSC 8310 Programming Languages Meeting 2 September 2/3, 2014.
CMSC 104, Version 8/061L18Functions1.ppt Functions, Part 1 of 4 Topics Using Predefined Functions Programmer-Defined Functions Using Input Parameters Function.
Chapter 8 :: Subroutines and Control Abstraction
Fortran- Subprograms Chapters 6, 7 in your Fortran book.
C++ for Engineers and Scientists Second Edition Chapter 6 Modularity Using Functions.
Chapter 6: User-Defined Functions
C++ Programming: From Problem Analysis to Program Design, Fifth Edition, Fifth Edition Chapter 7: User-Defined Functions II.
Programming Languages Meeting 6 September 30, 2014 October 1, 2014.
Copyright © 2005 Elsevier Chapter 8 :: Subroutines and Control Abstraction Programming Language Pragmatics Michael L. Scott.
Chapter 7 Functions. Types of Functions Value returning Functions that return a value through the use of a return statement They allow statements such.
Chapter 6 Functions 6.1 Modular Design A valuable strategy when writing complex programs is to break down the program into several smaller modules. A module.
1 Functions, Part 1 of 2 Topics Using Predefined Functions Programmer-Defined Functions Using Input Parameters Function Header Comments.
Chapter 3 Functions. 2 Overview u 3.2 Using C++ functions  Passing arguments  Header files & libraries u Writing C++ functions  Prototype  Definition.
Functions Math library functions Function definition Function invocation Argument passing Scope of an variable Programming 1 DCT 1033.
By Mr. Muhammad Pervez Akhtar
Functions Functions, locals, parameters, and separate compilation.
Higher Computing Science 2016 Prelim Revision. Topics to revise Computational Constructs parameter passing (value and reference, formal and actual) sub-programs/routines,
ISBN Chapter 10 Implementing Subprograms.
Functions, Part 1 of 3 Topics  Using Predefined Functions  Programmer-Defined Functions  Using Input Parameters  Function Header Comments Reading 
Procedure Definitions and Semantics Procedures support control abstraction in programming languages. In most programming languages, a procedure is defined.
Programming Languages Meeting 3 September 9/10, 2014.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
Control Structure  What is control Structure?  Types of Controls  Use the control structure in VBScript.  Example Summery.
CSC 1010 Programming for All Lecture 5 Functions Some material based on material from Marty Stepp, Instructor, University of Washington.
A FIRST BOOK OF C++ CHAPTER 7 ARRAYS. OBJECTIVES In this chapter, you will learn about: One-Dimensional Arrays Array Initialization Arrays as Arguments.
Chapter 10 : Implementing Subprograms
Implementing Subprograms
Chapter 7: User-Defined Functions II
CS 326 Programming Languages, Concepts and Implementation
Principles of programming languages 4: Parameter passing, Scope rules
Functions, locals, parameters, and separate compilation
Chapter 5 Functions DDC 2133 Programming II.
User-Defined Functions
C++ for Engineers and Scientists Second Edition
CSCI 3370: Principles of Programming Languages Chapter 9 Subprograms
Chapter 9 :: Subroutines and Control Abstraction
User Defined Functions
Chap. 8 :: Subroutines and Control Abstraction
Chap. 8 :: Subroutines and Control Abstraction
Chapter 5 Function Basics
Functions.
Lecture 18 Arrays and Pointer Arithmetic
Implementing Subprograms
Topic 3-a Calling Convention 1/10/2019.
Chapter 9: Value-Returning Functions
Languages and Compilers (SProg og Oversættere)
Chapter 9 Subprograms Fundamentals of Subprograms
Communication between modules, cohesion and coupling
CS1100 Computational Engineering
ENERGY 211 / CME 211 Lecture 8 October 8, 2008.
Subprograms General concepts Parameter passing Functions
Lecture 3 - Instruction Set - Al
Presentation transcript:

Organization of Programming Languages Meeting 21 March 7, 2016

Planning Ahead Quiz on Wednesday Multiple assignment statements Program functions Control structures Sequence If-then-else While-do For Associated functions: range, next

Functions, Methods, etc. Segmenting programs is an old technique producing program parts known by many names: Function Subroutine Procedure Method Operator Subprogram See Sebesta, Chapter 9, for his exposition of the topic

Functions (2) All segmentation strategies involve: Input values Local variables Output values We look in detail at the mechanisms provided by various programming languages using the semantic categories from before: Env, Ide, Loc, Store, V*, M, …

Functions (3) Syntax issues: Defining the function Using (invoking) the function

Defining Functions Need to specify: Name Parameters Kind: function, procedure, operator, … Type of output Parameters Type Mode

Output Values Produced in several ways Appear as parameter values: foofun(x,y) takes x and computes y Modes of y: result, reference Can handle arbitrary type as output

Output Values (2) Return in function name Follows structure in mathematics log(x) Easy to work with in expressions Implemented with RETURN statement Assignment to function name

Output Values (3) Side effect to global variable Action but no state change Print Write to file

Simple Functions Specialize to One or two arguments (parameters) of same type One value of same type as arguments Monadic or dyadic operators

Simple Functions (2) Implementation strategies Mix operators and functions Typical, mimics mathematics: 1+log(4) Operators only Use symbols for functions Monadic functions only Use list structure for several arguments

Subprogram Calls and Returns Need to specify for calls: Parameter passing mechanism (mode) Allocation of storage for local variables and binding to names Making global variables visible Saving execution status of calling program unit Transfer of control to subprogram code

Calls and Returns (2) Need to specify for return Moving values to output parameters Deallocating storage Resetting variable access Returning control to calling program

Semantics of Parameter Passing Consider five ways of parameter passing: Value Result Value-Result Reference (aka Location) Name

Semantics (2) In each case, we’ll assume a parameter list specified in the header of the procedure as (x1, x2, …). These are the formal parameters. We’ll assume a call foofun(a1,a2, …). The a’s are the actual parameters. Here’s what happens in each scenario.

Pass by Value Bind local parameters to locations: Element of Env becomes x1 -> loc 1 x2 -> loc 2 If x1 or x2 or … were bound to locations before invocation, those bindings are saved as part of the transfer of control

Pass by Value (2) Bind values of actual parameters to these locations. Assume a1 -> loc 50 -> v1 Then bind loc 1 to v1, changing the element of the Store Execute subprogram

Pass by Value (3) Break the bindings of the local parameters to locations. Either the element of Env shows x1 -> unbound or x1 -> location saved on entry

Pass by Result Bind local parameters to locations: Element of Env becomes x1 -> loc 1 x2 -> loc 2 If x1 or x2 or … were bound to locations before invocation, those bindings are saved as part of the transfer of control

Pass by Result (2) Execute subprogram Copy values of local parameters to locations of actual parameters x1 -> loc 1 -> v1 a1 -> loc 50 Bind loc 50 -> v1

Pass by Result (3) Break the bindings of the local parameters to locations. Either the element of Env shows x1 -> unbound or x1 -> location saved on entry

Pass by Value-Result Bind local parameters to locations: Element of Env becomes x1 -> loc 1 x2 -> loc 2 If x1 or x2 or … were bound to locations before invocation, those bindings are saved as part of the transfer of control

Pass by Value-Result (2) Bind values of actual parameters to these locations. Assume a1 -> loc 50 -> v1 Then bind loc 1 to v1, changing the element of the Store Execute subprogram

Pass by Value-Result (3) Copy values of local parameters to locations of actual parameters x1 -> loc 1 -> v1 a1 -> loc 50 Bind loc 50 -> v1

Pass by Value-Result (4) Break the bindings of the local parameters to locations. Either the element of Env shows x1 -> unbound or x1 -> location saved on entry

Pass by Reference Bind local parameters to locations of actual parameters: If a1 -> loc 50, a2 -> loc 51, … then Element of Env becomes x1 -> loc 50 x2 -> loc 51, etc If x1 or x2 or … were bound to locations before invocation, those bindings are saved as part of the transfer of control

Pass by Reference (2) Execute subprogram

Pass by Reference (3) Break the bindings of the local parameters to locations. Either the element of Env shows x1 -> unbound or x1 -> location saved on entry

Pass by Name Bind local parameters to rexp of actual parameters If a1 is given as string1 then x1 is assumed to be string1 etc If x1 or x2 or … were bound to locations before invocation, those bindings are saved as part of the transfer of control.

Pass by Name (2) Execute subprogram

Pass by Name (3) Break the bindings of the local parameters to strings (of code) Either the element of Env shows x1 -> unbound or x1 -> location saved on entry