1 / 16

CS 330 Organization of Programming Languages

CS 330 Organization of Programming Languages. Soundararajan Ezekiel Department of Computer Science Ohio Northern University ADA, Ohio 45810 e-mail: s-ezekiel@onu.edu http://www.onu.edu/user/FS/sezekiel. Implementing Subprograms. The General Semantics of Calls and Returns

Download Presentation

CS 330 Organization of Programming Languages

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 330 Organization of Programming Languages Soundararajan Ezekiel Department of Computer Science Ohio Northern University ADA, Ohio 45810 e-mail: s-ezekiel@onu.edu http://www.onu.edu/user/FS/sezekiel

  2. Implementing Subprograms • The General Semantics of Calls and Returns • Implementing FORTRAN 77 Subprograms

  3. 1.The General Semantics of Calls and Returns • the subprogram call and return operations of a language are together called its subprogram linkage • subprogram call has numerous action • 1. Mechanism for parameter passing • 2. If local variables are not static-- the call must cause storage • 3. Save the execution status of calling program unit • 4. Arrange to transfer control-- make sure that control return to the proper place • 5. Provide some mechanism to access non local variables

  4. Required action of subprogram return also complicated • move the local values of the associated formal parameters to the actual parameters • deallocate the storage used for local variables and restore the execution status of the calling program unit • control must be returned to the calling program unit

  5. 2. Implementing FORTRAN 77 subprograms • we will discuss simple situation in FORTRAN 77 subprograms • subprogram call requires the following actions • 1. Save the execution status of the current program unit • 2. Carry out the parameter passing process • 3. Pass the return address to the callee • 4. Transfer control to the callee

  6. The semantics of a FORTRAN 77 subprogram return requires the following actions • 1. If pass-by-value-result parameters are used, the current values of those parameters are moved to the corresponding actual parameters • 2. If the subprogram is a function, the functional value is moved to a place accessible to the caller • 3. The execution status of the caller is restored • 4. Control is transferred back to the caller • the call and return action require storage for the following • 1. Status information about the caller • 2. Parameters • 3. Return address • 4. Functional value for function subprogram

  7. Functional Programming Languages • Introduction • Mathematical Functions • Fundamentals of Functional Programming Languages • First Functional Programming Language: LISP • An Introduction to Scheme • COMMON LISP • ML • Haskell • Applications of Functional Languages • Comparison with other language

  8. Introduction • So far we talked about imperative languages and Object oriented language( Small talk) • The Object Oriented Programming Languages -- similar to Imperative languages • The reason for similarity -- von Neumann architecuture • The functional programming paradigm, which is based on mathematical functions, is the design for one of the most important nonimperative style of languages. • LISP began as purely functional language but soon acquired some important imperative features that increased its execution efficiency

  9. COMMON LISP extension of LISP • ML is a strongly typed functional languages with more conventional syntax than LISP • Haskell is partially based on ML but it is purely functional language • OBJECTIVE:- • Introduce the concept • Mathematics behind • It is difficult to acquire an actual feel for functional programming without some actual programming experience-- so we will do some simple programming in COMMON LISP

  10. Mathematical Functions • Mathematical function is a mapping of one set , called domain set , to another set called the range set • the function definitions specifies the domain and range sets, either explicitly or implicitly along with the mapping • One of the fundamental characteristics of mathematical functions is that the evaluation order of their mapping expressions is controlled by recursion and conditional expression rather than by the sequencing and iterative repetitions that are common in imperative programming languages

  11. Another important characteristics of mathematical functions is that because they have no side effect s, they always define the same value given the same set of arguments. • Side effect in programming languages connected to variables that model memory location • mathematical functions defines a value, rather than specifying a sequence of operations on values in memory to produce a value • There are no variables in the sense of imperative languages-- so no side effects

  12. Simple functions • cube(x) x*x*x, where x is a real number • name, domain and range are real numbers , the symbol  meaning “ is defined as” • when x= 2 it gives the value 8 • Alonzo Church • Born: 14 June 1903 in Washington, D.C., USA • Died: 11 Aug 1995 in Hudson, Ohio, USA

  13. Lambda expression • Lambda(x) x*x*x • it can more than one parameter • (Lambda(x) x*x*x)(2) • the answer will be 8

  14. Functional Forms • A higher order function or functional forms, is one that either takes functions as parameters or yields a function as its result or both • One common kind of functional form is functional composition-- which has two functional parameters and yields a function whose value is the first actual parameter function applied to the result of the second • Notation o as an operator • h  f o g • f(x)  x+2, g(x)  3*x h(x)  f(g(x)  (3*x)+2

  15. Construction • Construction is a functional form that takes a list of functions as parameter • When applied to an argument, a construction applies each of its functional parameters to that argument and collects the results in a list or sequence • Notation put all the function in [] like [f,g] • example g(x)  x*x h(x)  2*x i(x)  x/2 • then [g,h,i](4) (16, 8,2)

  16. Apply-to-all • apply-to-all is a functional form that takes a single function as a parameter • if applied to a list of arguments, apply-to-all applies its functional parameter to each of the values in the list argument and collects the result in a list or sequence • Notation alpha • h(x) x*x • alpha(h, (2,3,4)) yields ( 4,9,16) • There are many other functions -- This will be enough for us

More Related