7procedures_1115 - Procedures and Procedural Abstraction...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CSci 5106: Programming Languages Procedures and Procedural Abstraction Gopalan Nadathur Department of Computer Science and Engineering University of Minnesota Lectures in Fall 2010 Gopalan Nadathur Procedural Abstraction Procedures and Procedural Abstraction Mechanism for naming a parameterized block of code The main components of the feature Procedure definition An example in C-like syntax int square(int x) { return x * x; } Components of the abstract syntax: name, return type, formal parameters and their types, body Procedure call An example in C-like syntax: square(5) Abstract syntax components: name, actual parameters Syntactic wellformedness actually requires a matching between declared type and use This is a context sensitive feature that is typically treated in a “semantic analysis” phase by the compiler Gopalan Nadathur Procedural Abstraction Procedures and Restructuring the Machine Procedures impact along both organizational and the execution dimensions The effects of procedural abstraction on the organizational model Supports stepwise development based on problem decomposition Separates functionality from implementation details based on the principle of information hiding Provides the basis for realizing modularity The effects to the execution model Allows the granularity of atomic steps to be controlled by the user Provides for recursion that is a distinct way of thinking about computations Gopalan Nadathur Procedural Abstraction Issues to Study Concerning Procedures The main issues relate to the interaction between procedures and the rest of the program What are the mechanisms for parameter passing? Call-by-value Call-by-reference Call-by-value-result Call-by-name How is the name space managed? In particular, given a procedure or variable name Which declaration governs it? Scope Issue Which cell does it finally refer to? Activation Issue Given schemes for the above, how are they implemented? Gopalan Nadathur Procedural Abstraction
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Parameter Passing Mechanisms The main question is that of how actual and formal parameters match up during invocation The standard mechanisms Call-by-Value (CbV) Here we pass only the value of the actual parameter actuals can be arbitrary expressions if they are l-values, then they are unaffected by call Call-by-reference (CbR) Here the formal parameter becomes an alias for the actual parameter Actual must be an l-value for this to work Actual can be changed by the call Not directly supported in C, but can be simulated by pointers and taking addresses of variables Gopalan Nadathur Procedural Abstraction Call-by-Value vs Call-by-Reference Consider the following program written in pseudo-Pascal var i,j : integer; procedure swap(x,y : integer); var temp : integer; begin temp := x; x := y; y := temp; end; begin u := 5; v := 7; swap(u,v); end. What is the behaviour under the two parameter passing
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 05/06/2011.

Page1 / 7

7procedures_1115 - Procedures and Procedural Abstraction...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online