IA010: Principles of Programming Languages
|
|
- Horatio Sullivan
- 5 years ago
- Views:
Transcription
1 IA Subroutines 1 IA010: Principles of Programming Languages 5. Subroutines Jan Obdržálek obdrzalek@fi.muni.cz Faculty of Informatics, Masaryk University, Brno
2 Subroutines IA Subroutines 2 Subprograms, functions, procedures,... principal mechanism for control abstraction details of subroutine s computation are replaced by a statement that calls the subroutine increases readability: emphasizes logical structure, while hiding the low-level details facilitate code reuse, saving memory coding time subroutines vs OOP methods: differ in the way they are called methods are associated with classes and objects
3 Outline IA Subroutines 3 Fundamentals of subroutines Parameter-passing methods Overloaded and generic subroutines Functions specifics Coroutines
4 Fundamentals of subroutines IA Subroutines 4
5 Subroutine characteristics IA Subroutines 5 each subroutine has a single entry point the calling program unit is suspended during subroutine execution (so only one subroutine is in execution at any given time) control returns to the caller once subroutine execution is terminated alternatives: coroutines concurrent units
6 Basic definitions IA Subroutines 6 subroutine definition describes the interface and actions subroutine call an explicit request for the subroutine to be executed active subroutine has been executed, but has not yet completed its execution subroutine header part of the definition, specifies: the kind of the subroutine (function/procedure) a name (if not anonymous) a list of parameters parameter profile the number, order and types of formal parameters protocol parameter profile + return type
7 Procedures and functions IA Subroutines 7 procedures do not return values in effect define new statements as functions: can return a value using global variables two-way communication through parameters functions return values function call is, in effect, replaced by the return value as procedures: e.g. using the void return type modelled after mathematical function (the model is faithful if no side-effects are allowed)
8 Parameters Mechanism for passing data between a subroutine and its caller. (another option: through global variables) formal parameters (parameters) specified in the subroutine header sometimes called dummy variables actual parameters (arguments) specified in the subroutine call statement binding of actual parameters to formal parameters positional parameters by position (first to first,... ) keyword parameters the formal parameter name is explicitly given in a call (in any order) attack(weapon = my_weapon, force = my_force) when combined (e.g. Ada, Fortran95+, Python) once a keyword parameter appears, all remaining parameters must be keyworded IA Subroutines 8
9 Default parameter values A default value is used when the actual parameter is not given. both positional and keyword parameters def compute_pay(income, exemptions = 1, tax_rate) pay = compute_pay( , tax_rate = 0.15) once a default parameter is omitted, all remaining formal parameters must be keyworded positional parameters only parameters with default values must be listed last float compute_pay(float income, float tax_rate, int exemptions = 1) pay = compute_pay( , 0.15); once a default parameter is ommitted, all remaining must have default values IA Subroutines 9
10 Variable number of parameters IA Subroutines 10 problematic (type checking?) can be useful (e.g. printf in C) C the programmer must explicitly process the parameters: int printf(const char *format,...); accessed using va_list (stdarg.h) C# variable number of parameters of the same type public void DisplayList(params int[] list) { foreach (int next in list) { Console.WriteLine("Next value {0}", next); } }
11 Parameter-passing methods IA Subroutines 11
12 Parameter-passing methods Semantic models 1 in mode (receive data from the actual parameters) 2 out mode (transmit data to the actual parameters) 3 inout mode Example A subroutine takes two arrays list1 and list2, adds list1 to list2 and returns the result as revised list2. Also it returns a new array created from both arrays. in: list1, inout: list2, out: the new list Conceptual models copy the value transmit the access path (usually using a pointer or a reference) Implementation models coming next... IA Subroutines 12
13 Pass-by-Value IA Subroutines 13 for in mode parameters the value of the actual parametr initializes the corresponding formal parameter usually implemented using copying (write-protection required if implemented using the access path) advantages fast for scalar values disadvantages: space needs to be allocated for the formal parameter time and space needed to copy large objects (e.g. arrays)
14 Pass-by-Result IA Subroutines 14 for out mode parameters no value is passed to the subroutine the formal parameter acts as a normal variable after completion, its value is copied to the actual paramter the actual paramter must be a variable advantages and disadvantages: as for call-by value, plus parameter collision binding time choice
15 Pass-by-Result problems IA Subroutines 15 Parameter collision void Fixer(out int x, out int y) { // C# x = 17; y = 35; }... f.fixer(out a, out a); Binding time choice (call vs return) void DoIt(out int x, int index){ // C# x = 17; index = 42; }... sub = 21; f.doit(out list[sub], out sub);
16 Pass-by-Value-Result IA Subroutines 16 for inout mode parameters combination of the previous two sometimes called pass-by-copy disadvantages follow the from pass-by-value and pass-by result (time and space requirements)
17 Pass-by-Reference IA Subroutines 17 for inout mode parameters the access path (usually an address) is transmited the actual parameter is effectively shared with the subroutine advantages: very efficient (time and space) disadvantages: slower access (indirect addressing) risk of unintentionally changing actual parammeters (if used for one-way communication) can create aliases (see next slide)
18 Pass-by-Reference and aliases Collision between actual parameters: void foo(int &bar, int &baz)... foo(ouch, ouch) Collision between array elements: (for i=j) foo(list[i], list[j]) Collision between arrays and its elements: bar(list, list[i]) Collision between formal parameters and non-local variables: int *global; // C void main() {... sub(global);... } void sub(int *param) { IA Subroutines 18
19 Pass-by-Name IA Subroutines 19 for inout mode parameters very different from the previous models actual parameters are textually substituted for the formal parameters the referencing environment must also be passed to the subroutine inefficient, hard to implement complicated, decreases readability and reliability Algol60, also available (but not default) in Scala nowadays not used (exception: macros)
20 Jensen s device IA Subroutines 20 Exploits pass-by-name and side-effects. real procedure Sum(k, l, u, ak) value l, u; integer k, l, u; real ak; comment k and ak are passed by name; begin real s; s := 0; for k := l step 1 until u do s := s + ak; Sum := s end; the code above computes u k=l a k is general: summation over an array: Sum(i, 1, 100, V[i]) double summation: Sum(i,l,m, Sum(j,l,n,A[i,j])) summing squares: Sum(i,1,100,i*i)
21 Parameter passing in common PLs IA Subroutines 21 C pass-by-value pass-by-reference achieved using pointers if formal parameters are pointers to constants, the actual parameters are write-protected C++ also contains a reference type (implicitly dereferenced) (pass-by-reference semantics) write-protected if declared const void fun(const int &p1, int p2, int &p3) {... } Java pass-by-value for all parameters in effect pass-by-reference (objects are accessed only through references) object reference passed as a parameter cannot be changed in the subroutine (but the referenced object can) scalars cannot be passed by reference
22 Parameter passing in common PLs IA Subroutines 22 Ada, Fortran 95 each parameter can be specified to be in, out, or inout C# pass-by-value by default pass-by-reference can be requested using ref void sumer(ref int oldsum, int newone) {... }... sumer(ref sum, newvalue); out parameters: passed by reference (declared out)
23 IA Subroutines 23 Parameter passing in Python pass-by-assignment all data values are objects (each variable is a reference to an object) object references are passed by value assignment does not affect the caller def foo(x): x = x + 1 x = 42 foo(x) # x = 42 but for mutable objects the change is visible from the outside def bar(list): list[2] = 42 list = [1,2,3] bar(list) # list = [1,2,42]
24 IA Subroutines 24 Type checking parameters big impact on program reliability nowadays almost always enforced (exceptions: Perl, JavaScript, PHP) historically not: Fortran 77, early C in C89 it is possible to choose whether the parameters will be checked two ways of defining functions double sin(x) double x; {... } not type checked double sin(double x) {... } type checked C99 and C++ support only the second method
25 Passing multidimensional arrays IA Subroutines 25 subroutine needs to know the array dimensions for addressing (at least the number of columns) C/C++ separate compilation the mapping function is (address(m[i, j]) = address(m[0,0]) + i*columns + j) the number of columns can be given in the formal parameter: void fun(int matrix[][10]) {.. } void main() { int mat[5][10];... fun(mat);... } alternative: pass a reference to the array + its dimensions
26 Passing multidimensional arrays 2 IA Subroutines 26 Ada for unconstrained arrays we have information about index ranges: type Mat_Type is array (Integer range <>, Integer range <>) of Float; Mat_1 : Mat_Type(1..100, 1..20); function Sumer(Mat : in Mat_Type) return Float is Sum : Float := 0.0; begin for Row in Mat'range(1) loop for Col in Mat'range(2) loop Sum := Sum + Mat(Row, Col); end loop; -- for Col... end loop; -- for Row... return Sum; end Sumer;
27 Overloaded and generic subroutines IA Subroutines 27
28 Overloaded subroutines IA Subroutines 28 A subroutine is overloaded if there exists (in the same referencing environment) a different subroutine of the same name. overloaded subroutines must have a different protocol (number, order or types of parameters, or a different return type) examples: C++, Java, Ada, C# typical use case: constructors problem 1: coercion a call can match multiple parameter profiles in that case there must be some order on the subroutines complicated! (e.g. C++ [Stroustrup97]) problem 2: default values
29 Different kinds of polymorphism IA Subroutines 29 Ad hoc polymorphism Overloaded programs. When activated, the subroutine definition is chosen which corresponds to the actual parameters. Subtype polymorphism OOP. A variable of type T can contain an object of any subclass of T. Parametric polymorphism a subroutine has type expressions as formal parameters the concrete types are instantiated on activation (different activations may use different types) a single definition, independent of type subroutines of such kind are called generic subroutines
30 Generic functions in C++ Template functions template <class Type> Type max(type first, Type second) { return first > second? first : second; } when instatied, Type is replaced by a concrete type (e.g. int or char) for which > is defined implicit instantiation when a function is called when an address is obtained using & int a, b, c; char d, e, f;... c = max(a, b); f = max(d, e); a copy of code is generated for each of type used IA Subroutines 30
31 A generic sort function IA Subroutines 31 template <class Type> void generic_sort(type list[], int len) { int top, bottom; Type temp; for (top = 0; top < len - 2; top++) for (bottom = top + 1; bottom < len - 1; bottom++) if (list[top] > list[bottom]) { temp = list[top]; list[top] = list[bottom]; list[bottom] = temp; } //** end of if (list[top]... } //** end of generic_sort use: float flt_list[100];... generic_sort(flt_list, 100);
32 Generic functions as macros? IA Subroutines 32 Let s define the max function as a macro: #define max(a, b) ((a) > (b))? (a) : (b) this max seems to behave as a generic function but does not for well with side-effects: 1 take the following code: max(x++, y) 2 code generated by the preprocessor: ((x++) > (y)? (x++) : (y)) 3 x can be incremented twice!
33 Java 5.0 generic methods public static <T> T foo(t[] list) {... }... foo<string>(mylist); differences from C++ generic parameters must be classes (and arrays must have elements of a primitive type... ) just a single instance of the code (which operates on objects of the Object class) we can restrict the set of classes which can be used in place of the generic type public static <T extends Comparable> T doit(t[] list) {... } wildcard types void printcollection(collection<?> c) { for (Object e: c) { System.out.println(e); } } IA Subroutines 33
34 Generic methods in C# 2005 IA Subroutines 34 simillar to Java 5.0 no support for wildcard types the type can be omitted (if the compiler can infer the type from the actual parameter) class MyClass { public static T Foo<T>(T p1) {... } } Use: int myint = MyClass.Foo(17); string mystr = MyClass.Foo('apples'); // calls Foo<int> // calls Foo<string>
35 Functions specifics IA Subroutines 35
36 Functions specifics IA Subroutines 36 problems with side effects (if called in expressions) aliasing problems etc. solution (e.g. Ada): only in mode formal parameters return value type C: arrays and functions are not return types (pointers needed in these cases) Ada, Python, Ruby: value of any type can be returned (Ada cannot return functions, as functions are not types) Java and C#: methods cannot be returned (as methods are not types) number of returned values usually just one Ruby: 0 (nil), 1, >1 (array) F#: n-tuple
37 Coroutines IA Subroutines 37
38 Coroutines the master-slave relationship does not apply symmetric relationship among subroutines have multiple entry points remember their state between activations (history sensitive) can interrupt their execution by resuming a different coroutine sub coroutine_1(){... resume coroutine_2();... resume coroutine_3();... } there is only one coroutine active in any given moment typical scenarios: a card game systems simulation IA Subroutines 38
39 Coroutines II IA Subroutines 39 Example ([Sebesta]) historically in Simula and Modula-2 modern languages: e.g. Lua or Ruby (fibers)
Chapter 9. Subprograms
Chapter 9 Subprograms Chapter 9 Topics Introduction Fundamentals of Subprograms Design Issues for Subprograms Local Referencing Environments Parameter-Passing Methods Parameters That Are Subprograms Calling
More information9. Subprograms. 9.2 Fundamentals of Subprograms
9. Subprograms 9.2 Fundamentals of Subprograms General characteristics of subprograms A subprogram has a single entry point The caller is suspended during execution of the called subprogram Control always
More informationChapter 8. Fundamental Characteristics of Subprograms. 1. A subprogram has a single entry point
Fundamental Characteristics of Subprograms 1. A subprogram has a single entry point 2. The caller is suspended during execution of the called subprogram 3. Control always returns to the caller when the
More informationOrganization of Programming Languages CS 3200/5200N. Lecture 09
Organization of Programming Languages CS 3200/5200N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Control Flow Control flow = the flow of control, or execution
More informationProgramming Languages: Lecture 11
1 Programming Languages: Lecture 11 Chapter 9: Subprograms Jinwoo Kim jwkim@jjay.cuny.edu Chapter 9 Topics 2 Introduction Fundamentals of Subprograms Design Issues for Subprograms Local Referencing Environments
More informationChapter 9. Subprograms
Chapter 9 Subprograms Chapter 9 Topics Introduction Fundamentals of Subprograms Design Issues for Subprograms Local Referencing Environments Parameter-Passing Methods Parameters That Are Subprograms Calling
More informationChapter 9 Subprograms
Chapter 9 Subprograms 9.1 Introduction 366 9.2 Fundamentals of Subprograms 366 9.3 Design Issues for Subprograms 374 9.4 Local Referencing Environments 375 9.5 Parameter-Passing Methods 377 9.6 Parameters
More informationSubprograms. Bilkent University. CS315 Programming Languages Pinar Duygulu
1 Subprograms CS 315 Programming Languages Pinar Duygulu Bilkent University Introduction 2 Two fundamental abstraction facilities Process abstraction Emphasized from early days Data abstraction Emphasized
More informationSubprograms. Copyright 2015 Pearson. All rights reserved. 1-1
Subprograms Introduction Fundamentals of Subprograms Design Issues for Subprograms Local Referencing Environments Parameter-Passing Methods Parameters That Are Subprograms Calling Subprograms Indirectly
More informationCMSC 4023 Chapter 9. Fundamentals of Subprograms Introduction
9. 9.1. Introduction Two fundamental abstraction facilities Process abstraction Emphasized from early days Data abstraction Emphasized in the1980s 9.2. 9.2.1. General Subprogram Characteristics Each subprogram
More informationChapter 9 Subprograms
Chapter 9 Subprograms We now explore the design of subprograms, including parameter-passing methods, local referencing environment, overloaded subprograms, generic subprograms, and the aliasing and problematic
More informationUNIT V Sub u P b ro r g o r g a r m a s
UNIT V SubPrograms Outline Subprograms Parameter Passing Parameter correspondence Main Issues when designing subroutine in programming languages Parameter passing techniques Characteristics of Subprogram
More informationChapter 8 ( ) Control Abstraction. Subprograms Issues related to subprograms How is control transferred to & from the subprogram?
Control Abstraction Chapter 8 (81 84) Control Abstraction: Subroutines and parameters Programmer defined control structures Subprograms Procedures Functions Coroutines Exception handlers Processes Subprograms
More information11/29/17. Outline. Subprograms. Subroutine. Subroutine. Parameters. Characteristics of Subroutines/ Subprograms
Outline Subprograms In Text: Chapter 9 Definitions Design issues for subroutines Parameter passing modes and mechanisms Advanced subroutine issues N. Meng, S. Arthur 2 Subroutine A sequence of program
More informationSubroutines. Subroutine. Subroutine design. Control abstraction. If a subroutine does not fit on the screen, it is too long
Subroutines Subroutine = procedure (statement) - no return value - side effects function (expression) - return value - (no side effects in some languages) Subroutine Control abstraction Subroutine design
More informationProgramming Languages & Paradigms PROP HT Course Council. Subprograms. Meeting on friday! Subprograms, abstractions, encapsulation, ADT
Programming Languages & Paradigms PROP HT 2011 Lecture 4 Subprograms, abstractions, encapsulation, ADT Beatrice Åkerblom beatrice@dsv.su.se Course Council Meeting on friday! Talk to them and tell them
More informationSubprogram Concept. COMP3220 Principle of Programming Languages. Zhitao Gong Spring
Subprogram Concept COMP3220 Principle of Programming Languages Zhitao Gong 2016 Spring 1 / 30 Outline Introduction Closure Parameter Passing Summary 2 / 30 Introduction Tow fundamental abstractions process
More informationChapter 5. Names, Bindings, and Scopes
Chapter 5 Names, Bindings, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Scope Scope and Lifetime Referencing Environments Named Constants 1-2 Introduction Imperative
More informationCS 345. Functions. Vitaly Shmatikov. slide 1
CS 345 Functions Vitaly Shmatikov slide 1 Reading Assignment Mitchell, Chapter 7 C Reference Manual, Chapters 4 and 9 slide 2 Procedural Abstraction Can be overloaded (e.g., binary +) Procedure is a named
More informationStatement Basics. Assignment Statements
Statement Basics The meaning of a single statement executed in a state s is a new state s, which reflects the effects of the statement M stmt ( stmt, s) = s N. Meng, S. Arthur 1 Assignment Statements M
More informationNames, Bindings, Scopes
Names, Bindings, Scopes Variables In imperative l Language: abstractions of von Neumann machine Variables: abstraction of memory cell or cells Sometimes close to machine (e.g., integers), sometimes not
More information9/7/17. Outline. Name, Scope and Binding. Names. Introduction. Names (continued) Names (continued) In Text: Chapter 5
Outline Name, Scope and Binding In Text: Chapter 5 Names Variable Binding Type bindings, type conversion Storage bindings and lifetime Scope Lifetime vs. Scope Referencing Environments N. Meng, S. Arthur
More informationFundamentals of Programming Languages
Fundamentals of Programming Languages 1. DEFINITIONS... 2 2. BUILT-IN TYPES AND PRIMITIVE TYPES... 3 TYPE COMPATIBILITY... 9 GENERIC TYPES... 14 MONOMORPHIC VERSUS POLYMORPHIC... 16 TYPE IMPLEMENTATION
More informationCPS 506 Comparative Programming Languages. Programming Language
CPS 506 Comparative Programming Languages Object-Oriented Oriented Programming Language Paradigm Introduction Topics Object-Oriented Programming Design Issues for Object-Oriented Oriented Languages Support
More informationLecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction
Lecture 13: Object orientation Object oriented programming Introduction, types of OO languages Key concepts: Encapsulation, Inheritance, Dynamic binding & polymorphism Other design issues Smalltalk OO
More informationChapter 5 Names, Binding, Type Checking and Scopes
Chapter 5 Names, Binding, Type Checking and Scopes Names - We discuss all user-defined names here - Design issues for names: -Maximum length? - Are connector characters allowed? - Are names case sensitive?
More informationCOP4020 Programming Languages. Subroutines and Parameter Passing Prof. Robert van Engelen
COP4020 Programming Languages Subroutines and Parameter Passing Prof. Robert van Engelen Overview Parameter passing modes Subroutine closures as parameters Special-purpose parameters Function returns COP4020
More informationCS558 Programming Languages
CS558 Programming Languages Fall 2016 Lecture 4a Andrew Tolmach Portland State University 1994-2016 Pragmatics of Large Values Real machines are very efficient at handling word-size chunks of data (e.g.
More informationBinding and Variables
Binding and Variables 1. DEFINITIONS... 2 2. VARIABLES... 3 3. TYPE... 4 4. SCOPE... 4 5. REFERENCES... 7 6. ROUTINES... 9 7. ALIASING AND OVERLOADING... 10 8. GENERICS AND TEMPLATES... 12 A. Bellaachia
More informationLecture 4 Memory Management
Lecture 4 Memory Management Dr. Wilson Rivera ICOM 4036: Programming Languages Electrical and Computer Engineering Department University of Puerto Rico Some slides adapted from Sebesta s textbook Lecture
More informationCSCI312 Principles of Programming Languages!
CSCI312 Principles of Programming Languages! Chapter 5 Types Xu Liu! ! 5.1!Type Errors! 5.2!Static and Dynamic Typing! 5.3!Basic Types! 5.4!NonBasic Types! 5.5!Recursive Data Types! 5.6!Functions as Types!
More informationObject Oriented Paradigm
Object Oriented Paradigm History Simula 67 A Simulation Language 1967 (Algol 60 based) Smalltalk OO Language 1972 (1 st version) 1980 (standard) Background Ideas Record + code OBJECT (attributes + methods)
More informationCS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline
CS 0 Lecture 8 Chapter 5 Louden Outline The symbol table Static scoping vs dynamic scoping Symbol table Dictionary associates names to attributes In general: hash tables, tree and lists (assignment ) can
More informationChapter 10. Implementing Subprograms
Chapter 10 Implementing Subprograms Chapter 10 Topics The General Semantics of Calls and Returns Implementing Simple Subprograms Implementing Subprograms with Stack-Dynamic Local Variables Nested Subprograms
More informationCS558 Programming Languages Winter 2018 Lecture 4a. Andrew Tolmach Portland State University
CS558 Programming Languages Winter 2018 Lecture 4a Andrew Tolmach Portland State University 1994-2018 Pragmatics of Large Values Real machines are very efficient at handling word-size chunks of data (e.g.
More informationOrganization of Programming Languages CS320/520N. Lecture 06. Razvan C. Bunescu School of Electrical Engineering and Computer Science
Organization of Programming Languages CS320/520N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Data Types A data type defines a collection of data objects and
More informationType Bindings. Static Type Binding
Type Bindings Two key issues in binding (or associating) a type to an identifier: How is type binding specified? When does the type binding take place? N. Meng, S. Arthur 1 Static Type Binding An explicit
More informationFinal-Term Papers Solved MCQS with Reference
Solved MCQ(S) From FinalTerm Papers BY Arslan Jan 14, 2018 V-U For Updated Files Visit Our Site : Www.VirtualUstaad.blogspot.com Updated. Final-Term Papers Solved MCQS with Reference 1. The syntax of PHP
More informationNames, Scopes, and Bindings II. Hwansoo Han
Names, Scopes, and Bindings II Hwansoo Han Scope Rules A scope is textual region where bindings are active A program section of maximal size Bindings become active at the entry No bindings change in the
More informationPROCEDURES, METHODS AND FUNCTIONS
Cosc 2P90 PROCEDURES, METHODS AND FUNCTIONS (c) S. Thompson, M. Winters 1 Procedures, Functions & Methods The are varied and complex rules for declaring, defining and calling procedures, methods and functions
More informationSubprograms. Akim D le Étienne Renault Roland Levillain EPITA École Pour l Informatique et les Techniques Avancées
Subprograms Akim Demaille Étienne Renault Roland Levillain first.last@lrde.epita.fr EPITA École Pour l Informatique et les Techniques Avancées June 1, 2017 Subprograms 1 Routines 2 Argument passing 3 Functions
More informationInformatica 3 Syntax and Semantics
Informatica 3 Syntax and Semantics Marcello Restelli 9/15/07 Laurea in Ingegneria Informatica Politecnico di Milano Introduction Introduction to the concepts of syntax and semantics Binding Variables Routines
More informationSubprograms. COS 301 Programming Languages UMAINE CIS. COS 301 Programming Languages
Subprograms Topics Fundamentals of Subprograms Design Issues Parameter-Passing Methods Function Parameters Local Referencing Environments Overloaded Subprograms and Operators Generic Subprograms Coroutines
More informationLecture Overview. [Scott, chapter 7] [Sebesta, chapter 6]
1 Lecture Overview Types 1. Type systems 2. How to think about types 3. The classification of types 4. Type equivalence structural equivalence name equivalence 5. Type compatibility 6. Type inference [Scott,
More informationCPSC 3740 Programming Languages University of Lethbridge. Data Types
Data Types A data type defines a collection of data values and a set of predefined operations on those values Some languages allow user to define additional types Useful for error detection through type
More informationOutline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring
Java Outline Java Models for variables Types and type checking, type safety Interpretation vs. compilation Reasoning about code CSCI 2600 Spring 2017 2 Java Java is a successor to a number of languages,
More informationG Programming Languages Spring 2010 Lecture 4. Robert Grimm, New York University
G22.2110-001 Programming Languages Spring 2010 Lecture 4 Robert Grimm, New York University 1 Review Last week Control Structures Selection Loops 2 Outline Subprograms Calling Sequences Parameter Passing
More informationG Programming Languages - Fall 2012
G22.2110-003 Programming Languages - Fall 2012 Lecture 12 Thomas Wies New York University Review Last lecture Modules Outline Classes Encapsulation and Inheritance Initialization and Finalization Dynamic
More informationImperative Programming
Naming, scoping, binding, etc. Instructor: Dr. B. Cheng Fall 2004 1 Imperative Programming The central feature of imperative languages are variables Variables are abstractions for memory cells in a Von
More informationG Programming Languages - Fall 2012
G22.2110-003 Programming Languages - Fall 2012 Lecture 4 Thomas Wies New York University Review Last week Control Structures Selection Loops Adding Invariants Outline Subprograms Calling Sequences Parameter
More informationTYPES, VALUES AND DECLARATIONS
COSC 2P90 TYPES, VALUES AND DECLARATIONS (c) S. Thompson, M. Winters 1 Names, References, Values & Types data items have a value and a type type determines set of operations variables Have an identifier
More informationChapter 5 Names, Bindings, Type Checking, and Scopes
Chapter 5 Names, Bindings, Type Checking, and Scopes 長庚大學資訊工程學系 陳仁暉 助理教授 Tel: (03) 211-8800 Ext: 5990 E-mail: jhchen@mail.cgu.edu.tw URL: http://www.csie.cgu.edu.tw/jhchen All rights reserved. No part
More informationG Programming Languages - Fall 2012
G22.2110-003 Programming Languages - Fall 2012 Lecture 3 Thomas Wies New York University Review Last week Names and Bindings Lifetimes and Allocation Garbage Collection Scope Outline Control Flow Sequencing
More informationCS 315 Programming Languages Subprograms
CS 315 Programming Languages Subprograms Subprograms Definition header: name, parameters (formals), return type body: code E.g.: int triple (int x) return 3 * x; Call name, parameters (actuals) E.g.: triple(3)
More informationData Types. (with Examples In Haskell) COMP 524: Programming Languages Srinivas Krishnan March 22, 2011
Data Types (with Examples In Haskell) COMP 524: Programming Languages Srinivas Krishnan March 22, 2011 Based in part on slides and notes by Bjoern 1 Brandenburg, S. Olivier and A. Block. 1 Data Types Hardware-level:
More informationEvolution of Programming Languages
Evolution of Programming Languages 40's machine level raw binary 50's assembly language names for instructions and addresses very specific to each machine 60's high-level languages: Fortran, Cobol, Algol,
More informationWhere do we go from here?
Where do we go from here? C++ classes and objects, with all the moving parts visible operator overloading templates, STL, standards, Java components, collections, generics language and performance comparisons
More informationDesign Issues. Subroutines and Control Abstraction. Subroutines and Control Abstraction. CSC 4101: Programming Languages 1. Textbook, Chapter 8
Subroutines and Control Abstraction Textbook, Chapter 8 1 Subroutines and Control Abstraction Mechanisms for process abstraction Single entry (except FORTRAN, PL/I) Caller is suspended Control returns
More informationWeeks 6&7: Procedures and Parameter Passing
CS320 Principles of Programming Languages Weeks 6&7: Procedures and Parameter Passing Jingke Li Portland State University Fall 2017 PSU CS320 Fall 17 Weeks 6&7: Procedures and Parameter Passing 1 / 45
More informationData Abstraction. Hwansoo Han
Data Abstraction Hwansoo Han Data Abstraction Data abstraction s roots can be found in Simula67 An abstract data type (ADT) is defined In terms of the operations that it supports (i.e., that can be performed
More informationSoftware II: Principles of Programming Languages. Why Expressions?
Software II: Principles of Programming Languages Lecture 7 Expressions and Assignment Statements Why Expressions? Expressions are the fundamental means of specifying computations in a programming language
More informationReview of the C Programming Language
Review of the C Programming Language Prof. James L. Frankel Harvard University Version of 11:55 AM 22-Apr-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Reference Manual for the
More informationChapter 7. Expressions and Assignment Statements ISBN
Chapter 7 Expressions and Assignment Statements ISBN 0-321-49362-1 Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions Short-Circuit
More informationLecture 11: Subprograms & their implementation. Subprograms. Parameters
Lecture 11: Subprograms & their implementation Subprograms Parameter passing Activation records The run-time stack Implementation of static and dynamic scope rules Subprograms A subprogram is a piece of
More informationData Types. Every program uses data, either explicitly or implicitly to arrive at a result.
Every program uses data, either explicitly or implicitly to arrive at a result. Data in a program is collected into data structures, and is manipulated by algorithms. Algorithms + Data Structures = Programs
More informationInstantiation of Template class
Class Templates Templates are like advanced macros. They are useful for building new classes that depend on already existing user defined classes or built-in types. Example: stack of int or stack of double
More informationG Programming Languages Spring 2010 Lecture 6. Robert Grimm, New York University
G22.2110-001 Programming Languages Spring 2010 Lecture 6 Robert Grimm, New York University 1 Review Last week Function Languages Lambda Calculus SCHEME review 2 Outline Promises, promises, promises Types,
More informationChapter 7. Expressions and Assignment Statements
Chapter 7 Expressions and Assignment Statements Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions Short-Circuit Evaluation Assignment
More informationCSC 533: Organization of Programming Languages. Spring 2005
CSC 533: Organization of Programming Languages Spring 2005 Language features and issues variables & bindings data types primitive complex/structured expressions & assignments control structures subprograms
More informationChapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language
Categories of languages that support OOP: 1. OOP support is added to an existing language - C++ (also supports procedural and dataoriented programming) - Ada 95 (also supports procedural and dataoriented
More informationHANDLING NONLOCAL REFERENCES
SYMBOL TABLE A symbol table is a data structure kept by a translator that allows it to keep track of each declared name and its binding. Assume for now that each name is unique within its local scope.
More informationProperties of an identifier (and the object it represents) may be set at
Properties of an identifier (and the object it represents) may be set at Compile-time These are static properties as they do not change during execution. Examples include the type of a variable, the value
More informationChapter 11. Abstract Data Types and Encapsulation Concepts ISBN
Chapter 11 Abstract Data Types and Encapsulation Concepts ISBN 0-321-49362-1 Chapter 11 Topics The Concept of Abstraction Introduction to Data Abstraction Design Issues for Abstract Data Types Language
More informationLecture Notes on Programming Languages
Lecture Notes on Programming Languages 65 Lecture 07: Subprograms Subprograms are the building blocks for structuring your program into readable components that are easy to follow. Most programming languages
More informationOBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe
OBJECT ORIENTED PROGRAMMING USING C++ CSCI 5448- Object Oriented Analysis and Design By Manali Torpe Fundamentals of OOP Class Object Encapsulation Abstraction Inheritance Polymorphism Reusability C++
More informationPaytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value
Paytm Programming Sample paper: 1) A copy constructor is called a. when an object is returned by value b. when an object is passed by value as an argument c. when compiler generates a temporary object
More informationNOTE: Answer ANY FOUR of the following 6 sections:
A-PDF MERGER DEMO Philadelphia University Lecturer: Dr. Nadia Y. Yousif Coordinator: Dr. Nadia Y. Yousif Internal Examiner: Dr. Raad Fadhel Examination Paper... Programming Languages Paradigms (750321)
More informationAbstraction. Markus Roggenbach. 4. März 2004
Abstraction Markus Roggenbach 4. März 2004 Preliminary remark Preliminary remark 2 Aspects of Programming Languages Value Expression State(transformation) Command Context(transformation) Declaration Preliminary
More informationImplementing Subprograms
1 Implementing Subprograms CS 315 Programming Languages Pinar Duygulu Bilkent University CS315 Programming Languages Pinar Duygulu The General Semantics of Calls and Returns 2 The subprogram call and return
More informationPrinciples of Programming Languages
Ting Zhang Iowa State University Computer Science Department Lecture Note 16 October 26, 2010 Control Abstraction: Subroutines 1 / 26 Outline 1 Subroutines 2 Parameter Passing 3 Generic Subroutines 2 /
More informationReferences and pointers
References and pointers Pointers are variables whose value is a reference, i.e. an address of a store location. Early languages (Fortran, COBOL, Algol 60) had no pointers; added to Fortran 90. In Pascal,
More informationChapter 5. Variables. Topics. Imperative Paradigm. Von Neumann Architecture
Topics Chapter 5 Variables Imperative Paradigm Variables Names Address Types Assignment Binding Lifetime Scope Constants 2 Imperative Paradigm The most widely used and well-developed programming paradigm.
More informationSE352b: Roadmap. SE352b Software Engineering Design Tools. W3: Programming Paradigms
SE352b Software Engineering Design Tools W3: Programming Paradigms Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa SE352b: Roadmap CASE Tools: Introduction System Programming Tools Programming Paradigms
More informationTopics Covered Thus Far CMSC 330: Organization of Programming Languages
Topics Covered Thus Far CMSC 330: Organization of Programming Languages Names & Binding, Type Systems Programming languages Ruby Ocaml Lambda calculus Syntax specification Regular expressions Context free
More informationChapter 9 :: Subroutines and Control Abstraction
Chapter 9 :: Subroutines and Control Abstraction Programming Language Pragmatics, Fourth Edition Michael L. Scott Copyright 2016 Elsevier 1 Chapter09_Subroutines_and_Control_Abstraction_4e - Tue November
More informationLecture 7: Type Systems and Symbol Tables. CS 540 George Mason University
Lecture 7: Type Systems and Symbol Tables CS 540 George Mason University Static Analysis Compilers examine code to find semantic problems. Easy: undeclared variables, tag matching Difficult: preventing
More informationCS558 Programming Languages
CS558 Programming Languages Winter 2017 Lecture 7b Andrew Tolmach Portland State University 1994-2017 Values and Types We divide the universe of values according to types A type is a set of values and
More informationNames, Scopes, and Bindings. CSE 307 Principles of Programming Languages Stony Brook University
Names, Scopes, and Bindings CSE 307 Principles of Programming Languages Stony Brook University http://www.cs.stonybrook.edu/~cse307 1 Names, Scopes, and Bindings Names are identifiers (mnemonic character
More information22c:111 Programming Language Concepts. Fall Types I
22c:111 Programming Language Concepts Fall 2008 Types I Copyright 2007-08, The McGraw-Hill Company and Cesare Tinelli. These notes were originally developed by Allen Tucker, Robert Noonan and modified
More informationProgramming Languages, Summary CSC419; Odelia Schwartz
Programming Languages, Summary CSC419; Odelia Schwartz Chapter 1 Topics Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation Criteria Influences on Language Design
More informationOrganization of Programming Languages CS3200 / 5200N. Lecture 06
Organization of Programming Languages CS3200 / 5200N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Data Types A data type defines a collection of data objects
More informationCOSC 2P95. Procedural Abstraction. Week 3. Brock University. Brock University (Week 3) Procedural Abstraction 1 / 26
COSC 2P95 Procedural Abstraction Week 3 Brock University Brock University (Week 3) Procedural Abstraction 1 / 26 Procedural Abstraction We ve already discussed how to arrange complex sets of actions (e.g.
More informationExamples for Programming Language Features
CS 315 Examples 1 Examples for Programming Language Features Ch 1 Preliminaries 1.3 Language Evaluation Criteria 1.3.3 Reliability 1.3.3.1 Type Checking The following C program compiles and runs! foo (float
More informationAttributes, Bindings, and Semantic Functions Declarations, Blocks, Scope, and the Symbol Table Name Resolution and Overloading Allocation, Lifetimes,
Chapter 5 Basic Semantics Attributes, Bindings, and Semantic Functions Declarations, Blocks, Scope, and the Symbol Table Name Resolution and Overloading Allocation, Lifetimes, and the Environment Variables
More informationLecture 9: Parameter Passing, Generics and Polymorphism, Exceptions
Lecture 9: Parameter Passing, Generics and Polymorphism, Exceptions COMP 524 Programming Language Concepts Stephen Olivier February 12, 2008 Based on notes by A. Block, N. Fisher, F. Hernandez-Campos,
More informationNames, Scopes, and Bindings. CSE 307 Principles of Programming Languages Stony Brook University
Names, Scopes, and Bindings CSE 307 Principles of Programming Languages Stony Brook University http://www.cs.stonybrook.edu/~cse307 1 Names, Scopes, and Bindings Names are identifiers (mnemonic character
More informationConcepts of Programming Languages
Concepts of Programming Languages COMP322 Fall 2012/2013 1-1 Textbook ISBN 0-321-49362-1 Chapter 1 Preliminaries ISBN 0-321-49362-1 Chapter 1 Topics Reasons for Studying Concepts of Programming Languages
More informationDesign issues for objectoriented. languages. Objects-only "pure" language vs mixed. Are subclasses subtypes of the superclass?
Encapsulation Encapsulation grouping of subprograms and the data they manipulate Information hiding abstract data types type definition is hidden from the user variables of the type can be declared variables
More informationChapter 7 Expressions and Assignment statements
Chapter 7 Expressions and Assignment statements 1 7.1 Introduction Expressions are the fundamental means of specifying computations in a programming language Semantics of expressions are discussed in this
More informationProgramming Languages
Programming Languages Types CSCI-GA.2110-003 Fall 2011 What is a type? An interpretation of numbers Consists of a set of values The compiler/interpreter defines a mapping of these values onto the underlying
More information