A Model Of CPS Translation And Interpretation

Size: px
Start display at page:

Download "A Model Of CPS Translation And Interpretation"

Transcription

1 A Model Of CPS Translation And Interpretation Ramon Zatara R. Stansifer Departamento de Sistemas y Computación Computer Science Department Instituto Tenológico de Culiacán Florida Institute of Technology Av. Juan de Dios Bátiz s/n. Col. Guadalupe University Blvd. Melbourne, FL Culiacán, S, México. CP Tel Phone Fax rzatara@itculiacan.edu.mx, ryan@cs.fit.edu ABSTRACT This paper presents a model of translation of functional languages. The source language of the translation is a simple extension of lambda expressions and the target language is a language contuation passg style (CPS). We have implemented, SML [5], the translation and the terpreters of both the source and target languages. These systems are based on the defitions of the CPS semantics by Appel [1]. The ma contribution is a compe and executable framework for a CPS compiler, allowg the study of a wide range of performance issues among different elements. Another contribution is the implementation of a succeed and fail contuation model. The approach elimates overhead when usg exception handlg and was described [3]. Categories and Subject Descriptors D.3.4 [Programmg Languages]: Processors Compilers. approach of succeed and fail contuation model. The traditional approach uses only one contuation. Figure 1. Model of translation-terpretation Intermediate Representation Of SML programs (Lambda code) Translator To CPS General Terms Algorithms, Measurement, Performance, Experimentation, Languages. Keywords Functional programmg languages, compilers, exception handlg, and contuation-passg style. Input CPS Program Evaluator Of CPS Value 1. INTRODUCTION Contuation-passg style is a style of programmg or a special notation sometimes employed as an termediate representation Functional Programmg compilers [1,2,6]. Its ma idea is to make every aspect of control flow and data flow explicit [1]. A CPS program never needs to use a stack because functions never return. Its ma advantage is, stead of havg a function return a value, a function take as an argument another function to which the result is given as an argument. Another advantage to usg CPS is that every termediate value of a computation is given a name. This allows an easy translation to mache code because every name can correspond to a mache register. However, CPS is not easy to understand. Some people consider it remarkably elusive (too many lambdas they say). Our implementation (translator and terpret) is a tool that allows a user to translate lambda code to CPS code and then execute it (see figure 1), thereby providg, an environment to make different kds of experiments with both (lambda and CPS) styles of programmg. One of the experiments we did was to modify the traditional method to handle exceptions the SML language. In the experiment we implemented an 2. A MINICOMPILER FOR MINI ML The first part of the model shown before, is a translator to CPS. This translator takes a program written a lambda language (encoded to a tree-like data structure), and then makes a recursive traversal over the source-language program producg a CPS program. Our lambda language defition is described the next SML datatype and is similar to Appel defition [1]. 2.1 The Lambda language datatype lexp= VAR of var INT of t STRING of strg FN of var * lexp of var list * lexp list * lexp APP of lexp * lexp PLUS SUB MULT LESS EQ MAKEREF RAISE of lexp HANDLE of lexp * lexp COND of lexp * lexp * lexp (* switch *)

2 2.2 The CPS language The CPS language used our translator has three big differences with respect to those traditional compilers, which use also CPS as an termediate representation [1,2]: Every function has a name. There is an operator for defg mutually recursive functions (stead of fixed pot function). There are n-tuple primitive operators. Besides that, we use the ML datatype declaration order to prohibit ill-formed expressions. One important property of CPS is that every termediate value of a computation is given a name. This makes easier the translation later, to any kd of mache code. For example the SML expression 289 (17 * 17) is translated to (*,[INT 17,INT 17],["w2"], [ (-,[INT 289,VAR "w2"], ["w1"],[app (VAR "k",[var "w1"])])]) CPS notation, where w1 and w2 are termediate names produced by the translator. We will expla more detail later this example. Another important aspect of CPS operations is that every argument is atomic; that means that only variables or constants are allowed to be arguments. The defition of a CPS expression as an ML datatype is shown next code: datatype primop= gethdlr sethdlr + - * < equal makeref datatype value = VAR of var INT of t STRING of strg datatype cexp= APP of value * value list of (var * var list * cexp) list * cexp of primop * value list * var list * cexp list Two examples will clarify our lambda and CPS notation. APP((["fact"], [FN("n", COND(APP(LESS,RECORD [VAR "n",int 1]), INT 1, APP(MULT,RECORD[VAR "n", APP (VAR "fact", APP (SUB,RECORD [VAR "n",int 1]))])))], VAR "fact"),int 6) ([("r29",["x30"],app (VAR "k",[var "x30"]))], ([("fact",["n","w31"], ([("F32",["z33"], (equal,[var "z33",int 0],[], [APP (VAR "w31",[int 1]), ([("r35",["x36"], (*,[VAR "n",var "x36"],["w34"], [APP (VAR "w31",[var "w34"])]))], (-,[VAR "n",int 1],["w37"], [APP (VAR "fact",[var "w37",var "r35"])]))]))], (<,[VAR "n",int 1],[], [APP (VAR "F32",[INT 0]),APP (VAR "F32",[INT 1])])))], APP (VAR "fact",[int 6,VAR "r29"]))) This example corresponds to the classical factorial function. The lambda code is built by usg one function (fact), which bds an anonymous function for the body of the factorial function. The factorial of 6 is evaluated. The CPS expression contas three functions. One is for applyg the identity function (r29); another one for the function factorial; and another one for the condition expression. The ma difference both programs is the way it accumulates the result. In the lambda code, the argument n-1 and a return address are pushed to a stack and then the values and addresses are popped order to get the factorial. But with CPS we do not have return from callg function. The CPS code passes also the argument n-1, but stead of passg the return address, CPS passes a function (name) which contas the rest of the computation (see code italic form). In this case, variable w37 corresponds to the argument n-1 passed to the factorial function, and variable r35 is the function which corresponds to the rest of the computation. Function r35 is an iterative function which computes the factorial by callg itself n number of times. In this case, the call to function w31 is really to function r35, the value bound to r31 (however the last call w31 has value r29, the itial argument passed the first call to function fact, and the last function called the program). (["f"], [FN ("n", HANDLE (APP (MULT,RECORD [VAR "n",var "n"]), FN("e",COND (APP (EQ,RECORD [VAR "e",var "ovfl"]),var "n", RAISE (VAR "e")))))],app (VAR "f",int 1700))

3 ([("f",["n","w55"], (gethdlr,[],["h56"], [ ([("k58",["x67"],app (VAR "w55",[var "x67"])), ("n65",["e57"], (sethdlr,[var "h56"],[], [ ([("F59",["e","k60"], ([("F61",["z62"], (equal,[var "z62",int 0],[], [APP (VAR "k60",[var "n"]), (gethdlr,[],["h63"], [APP (VAR "h63",[var "e"])])]))], (equal,[var "e",var "ovfl"],[], [APP (VAR "F61",[INT 0]), APP (VAR "F61",[INT 1])])))], APP (VAR "F59",[VAR "e57",var "k58"]))]))], (sethdlr,[var "n65"],[], [ (*,[VAR "n",var "n"],["w66"], [ (sethdlr,[var "h56"],[], [APP (VAR "k58",[var "w66"])])])]))]))], ([("r68",["x69"],app (VAR "k",[var "x69"]))], APP (VAR "f",[int 1700,VAR "r68"]))) We will expla the lambda expression handle with more details. This expression has two parts. The first part is the expression that is gog to be evaluated (multiplication expression). The second part is evaluated only if an exception is raised from the first part. The lambda code implements the second part usg an anonymous function with one condition side it. Whenever an exception is raised the first part of the expression, the bound variable (e) of the function takes the exception name, and then the condition expression compares the bound variable (the exception) agast a defed exception (ovfl). If the condition is true the handler catches the exception and contues with first contuation (VAR n). If the condition is false it contues with second contuation (raise e). The CPS semantic implements exception handlg by usg two primitives: gethdlr and sethdlr. The first primitive getdlr (variable h56), saves the current handler memory (at the of the expression it will be restored). Next, primitive sethdlr with variable n65 sets a new current handler (function n65). If the n by n raises an exception (like overflow), a jump to the current handler (function n65) is performed. The first struction to be executed function n65 is the restoration of the old current handler (sethdlr with variable h56). The rest of the code function n65 is the checkg of the raised exception agast exception overflow. At the of the function a jump to function k58 is made (this s the execution of the handler). On the other hand, if the multiplication does not raise an exception, the next primitive sethdlr with variable h56 restores the old current handler. Both cases (exception thrown or not), jumpg to function k58, which turn jumps to the exit of the program: function r The translator to CPS The translation from a lambda expression to a correspondg CPS expression is made by a recursive traversal of the lambda expression. We shown last examples, that each lambda expression is represented a hierarchical structure (a syntax tree) where each node represents an operation, and the children of a node represent the argument of the operation. Algorithm to translate lambda expressions to CPS expression Our new approach is a modification to the mutually-recursive function f of Appel [1]. We modified the translation by addg a new contuation for abnormal computations. The new function convert takes three arguments: a lambda expression, a contuation function c for succeed computations, and a contuation function e for failed computations. This translation algorithm was presented [4] and a more detailed explanation can be found [3]. Next, we present some of the new transformed functions for handle, raise, fn, fix, and app lambda expressions. The compe code can be found [3]. convert(handle (A,FN(z,B)),c, e) = val H = newvar ("H") fun e' w = APP(VAR H,[w]) ([(H,[z],convert(B,c, e))], convert (A,c,e')) convert(raise E, c, e) = convert(e,e,e) convert(fn (v,e), c, e) =

4 val F = newvar ("F"); val k = newvar ("k"); val ak = newvar ("ak"); fun e' z = APP(VAR ak,[z]) ([(F,[v,k,ak],convert (E,(fn z=>app (VAR k,[z])), e'))],c(var F)) convert((hx,bx,e),c, e) = val w = newvar ("w") val ak = newvar ("ak") fun e'' w = APP(VAR ak,[w]) fun g(h1::h,fn(v,b)::b)= (h1,[v,w,ak], convert (B, fn z=> g(nil,nil) = nil APP(VAR w,[z]), e''))::g(h,b) (g(hx,bx),convert (E,c, e)) convert(app (F,E), c, e) = val r= newvar ("r"); val x= newvar ("x"); val e'= newvar ("e'"); val z= newvar ("z"); ([(r,[x],c(var x)), (e',[z],e(var z))], convert(f,(fn f2=>convert(e,(fn e2=>app(f2, [e2,var r,var e'])), e)), e)) 3. AN EXECUTABLE FRAMEWORK The semantic of CPS is described by Appel [1], where the author describes the meang of CPS expressions by usg denotational or contuation semantics. This semantics is defed as a functor SML. The functor takes a CPS structure, a datatype for the values allowed the semantics, and some data defitions as arguments. Then, a function evaluates a CPS expression, usg an empty environment and a store at the begng of the evaluation. We implemented this contuation semantic by defg some new functions, an itial environment, and a store. Also, we lked some other programs like the translator of lambda expressions, and altogether we created a framework or model of CPS translation and terpretation (see figure 2). LAMBDA CODE STORE AND ENVIRONMENT Translator To CPS Evaluator Of CPS Translator to Flat CPS and Abstract mache code (optional) RESULT RESULT Figure 2. Model of CPS translation and terpretation The framework focuses on the experience of learng the CPS concepts by usg an environment of CPS programmg. It can serve as an aid gag a coherent understandg of the CPS programmg. The most important element of this framework is that programs lambda and CPS code can be directly compiled and executed and, the programmer can see how this source code (lambda) is transformed to correspondent CPS code together with important components of the framework, like an environment and a store. From this framework the user should be able to write their own programs, test them with different data, make experiments, etc. Research based upon the experiment approach can be conducted order to study the different structures to use a program, and so to determe what the best approach is. 3.1 Evaluator of CPS The evaluator of CPS is a program which takes a CPS program, an put, and performs an evaluation or execution of the CPS program, givg as a result a denotable value (which is later converted to a strg). The put is formed by two components: An environment. This is a function that maps CPS variables to denotable values (result values). The itial environment of the evaluator is created by three functions: val env0 = fn v=>raise Undefed (v) val env1 = bd(env0,"k", FUNC ic) val env2 = bd (env1, "ovfl", overflow_exn) The first value bound to the environment is the empty environment (raise Undefed); the second value is the itial contuation (identity contuation); and the third value is a predefed exception (overflow). A store. A function that maps locations (addresses) to denotable values. The itial store of the evaluator are three functions: val store0 = (100, fn l=>raise Exc_Overflow l,fn _=>0) val store1 = upd(store0,handler_ref,func default_handler) val store2 = upd(store1, overflow_loc, STRING "- overflow-")

5 Store0 establish that the first unused location is address 100. Addresses before 100 are used for keepg values like system exceptions. This store is the empty location (a raise to an exception); the second location has the itial default handler; and the third location has the predefed overflow exception handler. In next tables, we show the implementation and some comments of the evaluator of CPS. val overflow_loc = 7; val overflow_exn: dvalue = ARRAY [overflow_loc] The current handler is kept a special location store. We decided to store the address (reference) of the overflow exception the element 7 of a dvalue ARRAY. fun V env (INT i) = INT i V env (STRING s) = STRING s V env (VAR v) = env v Fun V converts CPS values to denotable values. For variables the function has to lock up the environment. fun bd (env:env, v:a.var, d) = fn w => if v=w then d else env w Function bd produces a new environment (a function of type a.var -> dvalue) by bdg a new variable with a denotable value. exception Undefed of var and Exc_Overflow of loc We defe two exceptions: Undefed that is used when a value is not the environment (undefed variable), and Exc_Overflow when a value is not the store. exception bad_equality and Error Two exceptions are defed: bad_equality, which is, raised when two non-compatible denotable values are compared and Error, which is raised when the result of the program is not a denotable value. fun evalprim (a.gethdlr, [], [c]) = (fn s => c [fetch s handler_ref] s) evalprim (sethdlr, [h], [c]) = (fn s => c [] (upd(s,handler_ref,h))) evalprim (+,[INT i, INT j],[c]) = overflow(fn ()=> (i + j),c) evalprim (<,[INT i, INT j],[t,f]) = if i<j then t[] else f[] evalprim (equal,[array [i],array [j]], [t,f]) = if i=j then t[] else f[] evalprim (makeref,[v],[c])= (fn (l,f,r)=>c [ARRAY [l]] (upd ((nextloc l,f,r),l,v))) evalprim (equal, [_,_], [t,f]) = raise bad_equality Function evalprim evaluates a primitive operator () applied to arguments. The first two primitive operators: gethdlr and sethdlr are used for exception handlg. A gethdlr operator fetches the current exception handler (handler_ref) from the store. A sethdlr operator sets (updates) a new current handler the store. Primitive makeref is important when an exception is declared. The operator serts the denotable value v the first available location the store. type env = a.var -> dvalue The type of the environment is a function from a variable (strg) to a denotable value. fun E (a.app(f,vl)) env = val FUNC g = V env f g (map (V env) vl) Function E is the function, which takes the whole CPS expression, an environment, and a store, and then evaluates the expression givg as a result a value of type answer (a strg). E (a.(p,vl,wl,el)) env = evalprim(p, map (V env) vl, map (fn e => fn al => E e (bdn(env,wl,al))) el ) In order to evaluate a primitive operator, we first convert the arguments usg the current environment (map (V env) vl). Then the contuation (a function) of the evalprim function is built by usg the contuation of this function (E), and a new environment with the addition of element wl. E (a.(fl,e)) env = fun h r1 (f,vl,b) = FUNC(fn al => E b (bdn(g r1,vl,al))) and g r = bdn(r, map #1 fl, map (h r) fl) E e (g env) Function E with a mutually recursive function (fl,e) evaluates expression e the augmented environment g. The augmented environment is built by bdg the list of recursive function names (map #1 fl), with the list of bodies (map (h r) fl) of each of these recursive functions (FUNC(fn al => E b (bdn(g r1,vl,al)))), and usg theirs respective local variables (bdn(g r1,vl,al)). fun ic [INT i] _ = Int.toStrg i ic [STRING s] _ = s ic [FUNC _] _ = "fn" ic [ARRAY [l]] _= "ref "^(Int.toStrg l) ic = raise Error

6 Function ic is used to produce answer (an strg) as a result of the evaluation. The function just transforms a denotable value to a strg. fun default_handler [ARRAY [l]] s = val STRING e =fetch s l "EXCEPTION "^e default_handler [_,ARRAY [l]] s = val STRING e =fetch s l "EXCEPTION "^e This function allows the program to display the output EXCEPTION name_exception whenever a user defed exception is raised. Remember that the name of the exception (strg) is saved memory, matag the location l a denotable value of type ARRAY. So, usg l as the location and the fetch function we can access the name of the raised exception. val env0 = fn v=>raise Undefed (v) val env1 = bd(env0,"k", FUNC ic) val env2 = bd (env1, "ovfl", overflow_exn); val store0 = (100, fn l=>raise Exc_Overflow l,fn _=>0) val store1 = upd(store0,handler_ref,func default_handler) val store2 = upd(store1, overflow_loc, STRING "-overflow-") We itialize the environment with three new bdgs (fn v=>raise Undefed (v), FUNC ic, and overflow_exn), and the store with three new store locations (fn l=>raise Exc_Overflow, FUNC default_handler, STRING "-overflow-"), where the last one is the handler for the overflow exception. 4. CONCLUSIONS Although some compilers like SML/NJ provide a way to see the CPS termediate representation, the format of that representation is too complex to be understood by a regular user or programmer. Our implementation is very simple to read and understand and can be used not only as a tool to learn the concept of CPS but also as a program to make experiments with lambda and CPS programmg. 5. REFERENCES [1] Andrew W. Appel. Compilg with Contuations. Cambridge University Press, Cambridge, England, [2] Andrew Appel and David B. MacQueen. A standard ML compiler. In Gilles Kahn, editor, Functional Programmg Languages and Computer Architecture, pages Sprger-Verlag, Berl, Lecture Notes Computer Science 274; Proceedgs of Conference held at Portland, Oregon. [3] Ramon Zatara. Design and Implementation of Exception Handlg with Zero Overhead Functional Languages. PhD Dissertation, Florida Institute of Technology, [4] Ramon Zatara and Ryan Stansifer. Exception Handlg for CPS Compilers. Proceedgs of the 41 st ACM Southeast Regional Conference (ACMSE 03), Savannah, Georgia. [5] Rob Milner, Mads Tofte, and Robert William Harper, Jr. The Defition of Standard ML. MIT Press, Cambridge, Massachussetts, [6] Shao, Z. Compilg Standard ML for Efficient Execution on Modern Maches. PhD Dissertation, Prceton university, fun eval (vl,e) dl = E e env2 store2 Fally, function eval will take a CPS expression e, with two lists of variables and denotable values (vl and dl), and then will call function E passg out formal parameters e, env2, and store2.

Design and Implementation of Exception Handling with Zero Overhead in Functional Languages. Ramon Zatarain Cabada

Design and Implementation of Exception Handling with Zero Overhead in Functional Languages. Ramon Zatarain Cabada Design and Implementation of Exception Handling with Zero Overhead in Functional Languages By Ramon Zatarain Cabada A dissertation submitted to the College of Engineering at Florida Institute of Technology

More information

About coding style Spring February 9, 2004

About coding style Spring February 9, 2004 About codg style 15-212 Sprg 2004 February 9, 2004 Contents 1 Correctness 2 2 Specification 2 3 Style 2 3.1 if-then- Expressions... 3 3.1.1 Boolean if-then- Expressions... 3 3.1.2 if-then- stead of Pattern

More information

Functions Over Lists. Programming Languages and Compilers (CS 421) Structural Recursion. Functions Over Lists. Structural Recursion : List Example

Functions Over Lists. Programming Languages and Compilers (CS 421) Structural Recursion. Functions Over Lists. Structural Recursion : List Example Functions Over Lists Programmg Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC http://courses.engr.illois.edu/cs421 Based part on slides by Mattox Beckman, as updated by Vikram Adve and Gul

More information

Supplementary Notes on Concurrent ML

Supplementary Notes on Concurrent ML Supplementary Notes on Concurrent ML 15-312: Foundations of Programmg Languages Frank Pfenng Lecture 25 November 21, 2002 In the last lecture we discussed the π-calculus, a mimal language with synchronous

More information

7.3.3 A Language With Nested Procedure Declarations

7.3.3 A Language With Nested Procedure Declarations 7.3. ACCESS TO NONLOCAL DATA ON THE STACK 443 7.3.3 A Language With Nested Procedure Declarations The C family of languages, and many other familiar languages do not support nested procedures, so we troduce

More information

A Crash Course on Standard ML

A Crash Course on Standard ML A Crash Course on Standard ML Hongwei Xi Version of November 23, 2004 1 Start Type sml-cm at a Unix wdow to get an teractive terpreter for Standard ML (SML). You can later quit the terpreter by typg ctrl-d.

More information

Recap: Functions as first-class values

Recap: Functions as first-class values Recap: Functions as first-class values Arguments, return values, bindings What are the benefits? Parameterized, similar functions (e.g. Testers) Creating, (Returning) Functions Iterator, Accumul, Reuse

More information

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming Closures Mooly Sagiv Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming t ::= x x. t t t Call-by-value big-step Operational Semantics terms variable v ::= values abstraction x.

More information

Handout 2 August 25, 2008

Handout 2 August 25, 2008 CS 502: Compiling and Programming Systems Handout 2 August 25, 2008 Project The project you will implement will be a subset of Standard ML called Mini-ML. While Mini- ML shares strong syntactic and semantic

More information

Control in Sequential Languages

Control in Sequential Languages CS 242 2012 Control in Sequential Languages Reading: Chapter 8, Sections 8.1 8.3 (only) Section 7.3 of The Haskell 98 Report, Exception Handling in the I/O Monad, http://www.haskell.org/onlinelibrary/io-13.html

More information

Programming Languages

Programming Languages CSE 130 : Fall 2008 Programmg Languages Lecture 4: Variables, Environments, Scope News PA 1 due Frida 5pm PA 2 out esterda (due net Fi) Fri) Ranjit Jhala UC San Diego Variables and Bdgs Q: How to use variables

More information

Functional Programming. Pure Functional Programming

Functional Programming. Pure Functional Programming Functional Programming Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends only on the values of its sub-expressions (if any).

More information

CSci 4223 Principles of Programming Languages

CSci 4223 Principles of Programming Languages Review CSci 4223 Prciples of Programmg Languages Lecture 8 Features learned: functions, tuples, lists, let expressions, options, records, datatypes, case expressions, type synonyms, pattern matchg, exceptions

More information

Parsing Scheme (+ (* 2 3) 1) * 1

Parsing Scheme (+ (* 2 3) 1) * 1 Parsing Scheme + (+ (* 2 3) 1) * 1 2 3 Compiling Scheme frame + frame halt * 1 3 2 3 2 refer 1 apply * refer apply + Compiling Scheme make-return START make-test make-close make-assign make- pair? yes

More information

THAT ABOUT WRAPS IT UP Using FIX to Handle Errors Without Exceptions, and Other Programming Tricks

THAT ABOUT WRAPS IT UP Using FIX to Handle Errors Without Exceptions, and Other Programming Tricks THAT ABOUT WRAPS IT UP Usg FIX to Handle Errors Without Exceptions, and Other Programmg Tricks BRUCE J. MCADAM Technical Report ECS LFCS 97 375 Department of Computer Science University of Edburgh November

More information

A Third Look At ML. Chapter Nine Modern Programming Languages, 2nd ed. 1

A Third Look At ML. Chapter Nine Modern Programming Languages, 2nd ed. 1 A Third Look At ML Chapter Nine Modern Programming Languages, 2nd ed. 1 Outline More pattern matching Function values and anonymous functions Higher-order functions and currying Predefined higher-order

More information

CSE 341: Programming Languages

CSE 341: Programming Languages CSE 341: Programming Languages Autumn 2005 Lecture 10 Mutual Recursion, Equivalence, and Syntactic Sugar CSE 341 Autumn 2005, Lecture 10 1 Mutual Recursion You ve already seen how multiple functions can

More information

CPS Conversion. Di Zhao.

CPS Conversion. Di Zhao. CPS Conversion Di Zhao zhaodi01@mail.ustc.edu.cn This is the first assignment of the course - Advanced Topics in Software Technologies in the 2014-2015 academic year. During this course, we will explore

More information

Variables and Bindings

Variables and Bindings Net: Variables Variables and Bindings Q: How to use variables in ML? Q: How to assign to a variable? # let = 2+2;; val : int = 4 let = e;; Bind the value of epression e to the variable Variables and Bindings

More information

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find CS1622 Lecture 15 Semantic Analysis CS 1622 Lecture 15 1 Semantic Analysis How to build symbol tables How to use them to find multiply-declared and undeclared variables. How to perform type checking CS

More information

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming Closures Mooly Sagiv Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming Summary 1. Predictive Parsing 2. Large Step Operational Semantics (Natural) 3. Small Step Operational Semantics

More information

G Programming Languages Spring 2010 Lecture 4. Robert Grimm, New York University

G 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 information

Konzepte von Programmiersprachen

Konzepte von Programmiersprachen Konzepte von Programmiersprachen Chapter 5: Continuation-Passing Interpreters Stefan Wehr Universität Freiburg 8. Juni 2009 Konzepte von Programmiersprachen 1 / 43 Motivation Continuations: abstraction

More information

Introduction to SML Getting Started

Introduction to SML Getting Started Introduction to SML Getting Started Michael R. Hansen mrh@imm.dtu.dk Informatics and Mathematical Modelling Technical University of Denmark c Michael R. Hansen, Fall 2004 p.1/15 Background Standard Meta

More information

CIS24 Project #3. Student Name: Chun Chung Cheung Course Section: SA Date: 4/28/2003 Professor: Kopec. Subject: Functional Programming Language (ML)

CIS24 Project #3. Student Name: Chun Chung Cheung Course Section: SA Date: 4/28/2003 Professor: Kopec. Subject: Functional Programming Language (ML) CIS24 Project #3 Student Name: Chun Chung Cheung Course Section: SA Date: 4/28/2003 Professor: Kopec Subject: Functional Programming Language (ML) 1 Introduction ML Programming Language Functional programming

More information

G Programming Languages - Fall 2012

G 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 information

News. CSE 130: Programming Languages. Environments & Closures. Functions are first-class values. Recap: Functions as first-class values

News. CSE 130: Programming Languages. Environments & Closures. Functions are first-class values. Recap: Functions as first-class values CSE 130: Programming Languages Environments & Closures News PA 3 due THIS Friday (5/1) Midterm NEXT Friday (5/8) Ranjit Jhala UC San Diego Recap: Functions as first-class values Arguments, return values,

More information

Computer Science 312 Fall Prelim 2 SOLUTIONS April 18, 2006

Computer Science 312 Fall Prelim 2 SOLUTIONS April 18, 2006 Computer Science 312 Fall 2006 Prelim 2 SOLUTIONS April 18, 2006 1 2 3 4 5 6 7 8 Total Grade /xx /xx /xx /xx /xx /xx /xx /xx /100 Grader 1 1. (xx pots) A. The bary representation of a natural number is

More information

Forward Recursion. Programming Languages and Compilers (CS 421) Mapping Recursion. Forward Recursion: Examples. Folding Recursion.

Forward Recursion. Programming Languages and Compilers (CS 421) Mapping Recursion. Forward Recursion: Examples. Folding Recursion. Forward Recursion Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC http://www.cs.uiuc.edu/class/cs421/ Based in part on slides by Mattox Beckman, as updated by Vikram Adve and Gul

More information

Deferred operations. Continuations Structure and Interpretation of Computer Programs. Tail recursion in action.

Deferred operations. Continuations Structure and Interpretation of Computer Programs. Tail recursion in action. Deferred operations Continuations 6.037 - Structure and Interpretation of Computer Programs Mike Phillips (define the-cons (cons 1 #f)) (set-cdr! the-cons the-cons) (define (run-in-circles l) (+

More information

Comp 411 Principles of Programming Languages Lecture 7 Meta-interpreters. Corky Cartwright January 26, 2018

Comp 411 Principles of Programming Languages Lecture 7 Meta-interpreters. Corky Cartwright January 26, 2018 Comp 411 Principles of Programming Languages Lecture 7 Meta-interpreters Corky Cartwright January 26, 2018 Denotational Semantics The primary alternative to syntactic semantics is denotational semantics.

More information

TIC. %goo~~oo eomputer-science. ELECTE f. No-te on Coridhitiom Cominliati"I~n Standard ML1

TIC. %goo~~oo eomputer-science. ELECTE f. No-te on Coridhitiom CominliatiI~n Standard ML1 eomputer-science No-te on Coridhitiom Cominliati"I~n Standard ML1 mom Nicholas Haines Edoardo Biagioni Robert Hiarper Brian G. Mimnes June 1993 CMU-CS-93. 11 TIC ELECTE f 00..7733 %goo~~oo Note on Conditioual

More information

CS 312 Problem Set 1: An Introduction to SML

CS 312 Problem Set 1: An Introduction to SML CS 312 Problem Set 1: An Introduction to SML Assigned: September 1, 2003 Revised: September 4, 2003 Due: 11:59PM, September 10th, 2003 1 Introduction The goal of this problem set is to expose you to as

More information

Lecture 5: Declarative Programming. The Declarative Kernel Language Machine. September 12th, 2011

Lecture 5: Declarative Programming. The Declarative Kernel Language Machine. September 12th, 2011 Lecture 5: Declarative Programming. The Declarative Kernel Language Machine September 12th, 2011 1 Lecture Outline Declarative Programming contd Dataflow Variables contd Expressions and Statements Functions

More information

1 Introduction Closure conversion is a critical program transformation for higher-order languages that elimates lexically nested, rst-class functions

1 Introduction Closure conversion is a critical program transformation for higher-order languages that elimates lexically nested, rst-class functions Typed Closure Conversion for Recursively-Dened Functions (Extended Abstract) Greg Morrisett 1 Cornell University Robert Harper 2 Carnegie Mellon University Abstract Much recent work on the compilation

More information

Functional programming Primer I

Functional programming Primer I Functional programming Primer I COS 320 Compiling Techniques Princeton University Spring 2016 Lennart Beringer 1 Characteristics of functional programming Primary notions: functions and expressions (not

More information

CS4215 Programming Language Implementation. Martin Henz

CS4215 Programming Language Implementation. Martin Henz CS4215 Programming Language Implementation Martin Henz Thursday 15 March, 2012 2 Chapter 11 impl: A Simple Imperative Language 11.1 Introduction So far, we considered only languages, in which an identifier

More information

Compiling Exceptions Correctly

Compiling Exceptions Correctly Compiling Exceptions Correctly Graham Hutton and Joel Wright School of Computer Science and IT University of Nottingham, United Kingdom Abstract. Exceptions are an important feature of modern programming

More information

Symbol Tables Symbol Table: In computer science, a symbol table is a data structure used by a language translator such as a compiler or interpreter, where each identifier in a program's source code is

More information

CSCI-GA Scripting Languages

CSCI-GA Scripting Languages CSCI-GA.3033.003 Scripting Languages 12/02/2013 OCaml 1 Acknowledgement The material on these slides is based on notes provided by Dexter Kozen. 2 About OCaml A functional programming language All computation

More information

Lecture 9: Control Flow

Lecture 9: Control Flow Programming Languages Lecture 9: Control Flow Benjamin J. Keller Department of Computer Science, Virginia Tech Programming Languages Control Flow 2 Command Overview Assignment Control Structures Natural

More information

CSE341: Programming Languages Lecture 6 Nested Patterns Exceptions Tail Recursion. Zach Tatlock Winter 2018

CSE341: Programming Languages Lecture 6 Nested Patterns Exceptions Tail Recursion. Zach Tatlock Winter 2018 CSE341: Programming Languages Lecture 6 Nested Patterns Exceptions Tail Recursion Zach Tatlock Winter 2018 Nested patterns We can nest patterns as deep as we want Just like we can nest expressions as deep

More information

An Explicit-Continuation Metacircular Evaluator

An Explicit-Continuation Metacircular Evaluator Computer Science (1)21b (Spring Term, 2018) Structure and Interpretation of Computer Programs An Explicit-Continuation Metacircular Evaluator The vanilla metacircular evaluator gives a lot of information

More information

Motivation. Compiler. Our ultimate goal: Hack code. Jack code (example) Translate high-level programs into executable code. return; } } return

Motivation. Compiler. Our ultimate goal: Hack code. Jack code (example) Translate high-level programs into executable code. return; } } return Motivation Jack code (example) class class Main Main { { static static int int x; x; function function void void main() main() { { Inputs Inputs and and multiplies multiplies two two numbers numbers var

More information

A quick introduction to SML

A quick introduction to SML A quick introduction to SML CMSC 15300 April 9, 2004 1 Introduction Standard ML (SML) is a functional language (or higherorder language) and we will use it in this course to illustrate some of the important

More information

Principles of Programming Languages

Principles of Programming Languages Principles of Programming Languages Lecture 08 Control Semantics & Continuations Semantics of Control Flow Sequencers: commands that cause control transfers:! goto! return! exit! break! continue! resultis

More information

SML A F unctional Functional Language Language Lecture 19

SML A F unctional Functional Language Language Lecture 19 SML A Functional Language Lecture 19 Introduction to SML SML is a functional programming language and acronym for Standard d Meta Language. SML has basic data objects as expressions, functions and list

More information

Functional Programming. Big Picture. Design of Programming Languages

Functional Programming. Big Picture. Design of Programming Languages Functional Programming Big Picture What we ve learned so far: Imperative Programming Languages Variables, binding, scoping, reference environment, etc What s next: Functional Programming Languages Semantics

More information

At build time, not application time. Types serve as statically checkable invariants.

At build time, not application time. Types serve as statically checkable invariants. Static Typing Thus far we have only considered statically typed languages. CMPSCI 630: Programming Languages Static and Dynamic Typing Spring 2008 (with thanks to Robert Harper) Type system is based on

More information

CS 312, Fall Exam 1

CS 312, Fall Exam 1 Name: ID number: CS 312, Fall 2003 Exam 1 October 16, 2003 Problem 1 2 3 4 Total Grader Grade 18 24 28 30 There are 4 problems on this exam. Please check now that you have a complete exam booklet with

More information

Begin at the beginning

Begin at the beginning Begin at the beginning Expressions (Syntax) Exec-time Dynamic Values (Semantics) Compile-time Static Types 1. Programmer enters expression 2. ML checks if expression is well-typed Using a precise set of

More information

An example DFA: reaching definitions

An example DFA: reaching definitions Dataflow analysis: what is it? Dataflow analysis A common framework for expressg algorithms that compute formation ab a program Why is such a framework useful? Dataflow analysis: what is it? A common framework

More information

Contextual Analysis (2) Limitations of CFGs (3)

Contextual Analysis (2) Limitations of CFGs (3) G53CMP: Lecture 5 Contextual Analysis: Scope I Henrik Nilsson University of Nottgham, UK This Lecture Limitations of context-free languages: Why checkg contextual constrats is different from checkg syntactical

More information

COP4020 Programming Language Concepts Spring 2017 Sample Final Exam Questions SOLUTIONS

COP4020 Programming Language Concepts Spring 2017 Sample Final Exam Questions SOLUTIONS COP4020 Programmg Language Concepts Sprg 2017 Sample Fal Exam Questions SOLUTIONS Disclaimer: This is a collection of sample exam questions, not a sample exam. 1. Add the unary postfix auto-crement operator

More information

Comp 311: Sample Midterm Examination

Comp 311: Sample Midterm Examination Comp 311: Sample Midterm Examination October 29, 2007 Name: Id #: Instructions 1. The examination is closed book. If you forget the name for a Scheme operation, make up a name for it and write a brief

More information

Homework 3 COSE212, Fall 2018

Homework 3 COSE212, Fall 2018 Homework 3 COSE212, Fall 2018 Hakjoo Oh Due: 10/28, 24:00 Problem 1 (100pts) Let us design and implement a programming language called ML. ML is a small yet Turing-complete functional language that supports

More information

CSE 341, Autumn 2005, Assignment 3 ML - MiniML Interpreter

CSE 341, Autumn 2005, Assignment 3 ML - MiniML Interpreter Due: Thurs October 27, 10:00pm CSE 341, Autumn 2005, Assignment 3 ML - MiniML Interpreter Note: This is a much longer assignment than anything we ve seen up until now. You are given two weeks to complete

More information

Programming Languages and Compilers (CS 421)

Programming Languages and Compilers (CS 421) Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC http://courses.engr.illinois.edu/cs421 Based in part on slides by Mattox Beckman, as updated by Vikram Adve and Gul Agha 9/11/17

More information

CSE341, Spring 2013, Final Examination June 13, 2013

CSE341, Spring 2013, Final Examination June 13, 2013 CSE341, Spring 2013, Final Examination June 13, 2013 Please do not turn the page until 8:30. Rules: The exam is closed-book, closed-note, except for both sides of one 8.5x11in piece of paper. Please stop

More information

Version 4, 12 October 2004 Project handed out on 12 October. Complete Java implementation due on 2 November.

Version 4, 12 October 2004 Project handed out on 12 October. Complete Java implementation due on 2 November. CS 351 Programmg Paradigms, Fall 2004 1 Project 2: gnuplot Version 4, 12 October 2004 Project handed out on 12 October. Compe Java implementation due on 2 November. 2.1 The task Implement a utility for

More information

type environment updated subtype sound

type environment updated subtype sound #1 Type Checkg #2 One-Slide Summary A type environment gives types for free variables. You typecheck a let-body with an environment that has been updated to conta the new let-variable. If an object of

More information

Tail Calls. CMSC 330: Organization of Programming Languages. Tail Recursion. Tail Recursion (cont d) Names and Binding. Tail Recursion (cont d)

Tail Calls. CMSC 330: Organization of Programming Languages. Tail Recursion. Tail Recursion (cont d) Names and Binding. Tail Recursion (cont d) CMSC 330: Organization of Programming Languages Tail Calls A tail call is a function call that is the last thing a function does before it returns let add x y = x + y let f z = add z z (* tail call *)

More information

Lecture 8: Recursion and Iteration. Exceptions. Declarative Programming.

Lecture 8: Recursion and Iteration. Exceptions. Declarative Programming. Lecture 8: Recursion and Iteration. Exceptions. Declarative Programming. September 26th, 2010 Lecture 8: Recursion and Iteration. Exceptions. Declarative Programming. (1/48) Lecture Outline Memory Management,

More information

Lecture 09: Data Abstraction ++ Parsing is the process of translating a sequence of characters (a string) into an abstract syntax tree.

Lecture 09: Data Abstraction ++ Parsing is the process of translating a sequence of characters (a string) into an abstract syntax tree. Lecture 09: Data Abstraction ++ Parsing Parsing is the process of translating a sequence of characters (a string) into an abstract syntax tree. program text Parser AST Processor Compilers (and some interpreters)

More information

1 Announcements. 2 Scan Implementation Recap. Recitation 4 Scan, Reduction, MapCollectReduce

1 Announcements. 2 Scan Implementation Recap. Recitation 4 Scan, Reduction, MapCollectReduce Recitation 4 Scan, Reduction, MapCollectReduce Parallel and Sequential Data Structures and Algorithms, 15-210 (Sprg 2013) February 6, 2013 1 Announcements How did HW 2 go? HW 3 is out get an early start!

More information

Computer Science CSC324 Wednesday February 13, Homework Assignment #3 Due: Thursday February 28, 2013, by 10 p.m.

Computer Science CSC324 Wednesday February 13, Homework Assignment #3 Due: Thursday February 28, 2013, by 10 p.m. Computer Science CSC324 Wednesday February 13, 2013 St. George Campus University of Toronto Homework Assignment #3 Due: Thursday February 28, 2013, by 10 p.m. Silent Policy A silent policy takes effect

More information

The Environment Model. Nate Foster Spring 2018

The Environment Model. Nate Foster Spring 2018 The Environment Model Nate Foster Spring 2018 Review Previously in 3110: Interpreters: ASTs, evaluation, parsing Formal syntax: BNF Formal semantics: dynamic: small-step substitution model static semantics

More information

The Environment Model

The Environment Model The Environment Model Prof. Clarkson Fall 2017 Today s music: Selections from Doctor Who soundtracks by Murray Gold Review Previously in 3110: Interpreters: ASTs, evaluation, parsing Formal syntax: BNF

More information

COP-5555 PROGRAMMING LANGUAGEPRINCIPLES NOTES ON RPAL

COP-5555 PROGRAMMING LANGUAGEPRINCIPLES NOTES ON RPAL COP-5555 PROGRAMMING LANGUAGEPRINCIPLES NOTES ON 1. Introduction is a subset of PAL, the Pedagogic Algorithmic Language. There are three versions of PAL:, LPAL, and JPAL. The only one of terest here is.

More information

Scheme in Scheme: The Metacircular Evaluator Eval and Apply

Scheme in Scheme: The Metacircular Evaluator Eval and Apply Scheme in Scheme: The Metacircular Evaluator Eval and Apply CS21b: Structure and Interpretation of Computer Programs Brandeis University Spring Term, 2015 The metacircular evaluator is A rendition of Scheme,

More information

DML - A Meta-language and System for the Generation of Practical and Efficient Compilers from Denotational Specifications

DML - A Meta-language and System for the Generation of Practical and Efficient Compilers from Denotational Specifications DML - A Meta-language and System for the Generation of Practical and Efficient Compilers from Denotational Specifications Mikael Pettersson and Peter Fritzson Department of Computer and Information Science,

More information

Programming Languages and Compilers (CS 421)

Programming Languages and Compilers (CS 421) Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC http://courses.engr.illinois.edu/cs421 Based in part on slides by Mattox Beckman, as updated by Vikram Adve and Gul Agha 9/18/17

More information

Fall Semester, The Metacircular Evaluator. Today we shift perspective from that of a user of computer langugaes to that of a designer of

Fall Semester, The Metacircular Evaluator. Today we shift perspective from that of a user of computer langugaes to that of a designer of 1 MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science 6.001 Structure and Interpretation of Computer Programs Fall Semester, 1996 Lecture Notes { October 31,

More information

Static semantics. Lecture 3-6: Semantics. Attribute grammars (2) Attribute grammars. Attribute grammars example. Dynamic semantics

Static semantics. Lecture 3-6: Semantics. Attribute grammars (2) Attribute grammars. Attribute grammars example. Dynamic semantics Lecture 3-6: Semantics Static semantics Attribute grammars Dynamic semantics Denotational semantics: semantic equations Axiomatic semantics: inference rules and correctness proofs Static semantics Semantics

More information

INF 212 ANALYSIS OF PROG. LANGS FUNCTION COMPOSITION. Instructors: Crista Lopes Copyright Instructors.

INF 212 ANALYSIS OF PROG. LANGS FUNCTION COMPOSITION. Instructors: Crista Lopes Copyright Instructors. INF 212 ANALYSIS OF PROG. LANGS FUNCTION COMPOSITION Instructors: Crista Lopes Copyright Instructors. Topics Recursion Higher-order functions Continuation-Passing Style Monads (take 1) Identity Monad Maybe

More information

CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures. Dan Grossman Autumn 2018

CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures. Dan Grossman Autumn 2018 CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Dan Grossman Autumn 2018 Typical workflow concrete syntax (string) "(fn x => x + x) 4" Parsing Possible errors / warnings

More information

Topic 7: Activation Records

Topic 7: Activation Records Topic 7: Activation Records Compiler Design Prof. Hanjun Kim CoreLab (Compiler Research Lab) POSTECH 1 Storage Organization Stack Free Memory Heap Static Code 2 ELF file format example Executable Object

More information

Principles of Programming Languages

Principles of Programming Languages Principles of Programming Languages www.cs.bgu.ac.il/~ppl172 Lesson 6 - Defining a Programming Language Bottom Up Collaboration and Management - Elements of Programming Dana Fisman 1 What we accomplished

More information

CS558 Programming Languages

CS558 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 information

Announcements. The current topic: Scheme. Review: BST functions. Review: Representing trees in Scheme. Reminder: Lab 2 is due on Monday at 10:30 am.

Announcements. The current topic: Scheme. Review: BST functions. Review: Representing trees in Scheme. Reminder: Lab 2 is due on Monday at 10:30 am. The current topic: Scheme! Introduction! Object-oriented programming: Python Functional programming: Scheme! Introduction! Numeric operators, REPL, quotes, functions, conditionals! Function examples, helper

More information

UNIT 3

UNIT 3 UNIT 3 Presentation Outline Sequence control with expressions Conditional Statements, Loops Exception Handling Subprogram definition and activation Simple and Recursive Subprogram Subprogram Environment

More information

Project Compiler. CS031 TA Help Session November 28, 2011

Project Compiler. CS031 TA Help Session November 28, 2011 Project Compiler CS031 TA Help Session November 28, 2011 Motivation Generally, it s easier to program in higher-level languages than in assembly. Our goal is to automate the conversion from a higher-level

More information

CSCC24 Functional Programming Scheme Part 2

CSCC24 Functional Programming Scheme Part 2 CSCC24 Functional Programming Scheme Part 2 Carolyn MacLeod 1 winter 2012 1 Based on slides from Anya Tafliovich, and with many thanks to Gerald Penn and Prabhakar Ragde. 1 The Spirit of Lisp-like Languages

More information

SCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015

SCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015 SCHEME 7 COMPUTER SCIENCE 61A October 29, 2015 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

More information

n What is its running time? 9/18/17 2 n poor_rev [1,2,3] = n (poor_rev [1] = n ((poor_rev [1] =

n What is its running time? 9/18/17 2 n poor_rev [1,2,3] = n (poor_rev [1] = n ((poor_rev  [1] = Recall Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC http://courses.engr.illinois.edu/cs421 Based in part on slides by Mattox Beckman, as updated by Vikram Adve and Gul Agha

More information

Notes on Higher Order Programming in Scheme. by Alexander Stepanov

Notes on Higher Order Programming in Scheme. by Alexander Stepanov by Alexander Stepanov August 1986 INTRODUCTION Why Scheme? Because it allows us to deal with: 1. Data Abstraction - it allows us to implement ADT (abstact data types) in a very special way. The issue of

More information

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011 CS152: Programming Languages Lecture 11 STLC Extensions and Related Topics Dan Grossman Spring 2011 Review e ::= λx. e x e e c v ::= λx. e c τ ::= int τ τ Γ ::= Γ, x : τ (λx. e) v e[v/x] e 1 e 1 e 1 e

More information

Lambda Calculus and Lambda notation in Lisp II. Based on Prof. Gotshalks notes on Lambda Calculus and Chapter 9 in Wilensky.

Lambda Calculus and Lambda notation in Lisp II. Based on Prof. Gotshalks notes on Lambda Calculus and Chapter 9 in Wilensky. λ Calculus Basis Lambda Calculus and Lambda notation in Lisp II Based on Prof. Gotshalks notes on Lambda Calculus and Chapter 9 in Wilensky Mathematical theory for anonymous functions» functions that have

More information

CVO103: Programming Languages. Lecture 5 Design and Implementation of PLs (1) Expressions

CVO103: Programming Languages. Lecture 5 Design and Implementation of PLs (1) Expressions CVO103: Programming Languages Lecture 5 Design and Implementation of PLs (1) Expressions Hakjoo Oh 2018 Spring Hakjoo Oh CVO103 2018 Spring, Lecture 5 April 3, 2018 1 / 23 Plan Part 1 (Preliminaries):

More information

The Phases of a Compiler. Course Overview. In Chapter 4. Syntax Analysis. Syntax Analysis. Multi Pass Compiler. PART I: overview material

The Phases of a Compiler. Course Overview. In Chapter 4. Syntax Analysis. Syntax Analysis. Multi Pass Compiler. PART I: overview material Course Overview The Phases of a Compiler PART I: overview material Introduction 2 Language processors (tombstone diagrams, bootstrappg) 3 Architecture of a compiler PART II: side a compiler 4 Sntax analsis

More information

CS 320: Concepts of Programming Languages

CS 320: Concepts of Programming Languages CS 320: Concepts of Programming Languages Wayne Snyder Computer Science Department Boston University Lecture 24: Compilation: Implementing Function Calls o Function Definitions in Mini-C o The Run-Time

More information

Programming Languages and Compilers (CS 421)

Programming Languages and Compilers (CS 421) Programming Languages and Compilers (CS 421) #3: Closures, evaluation of function applications, order of evaluation #4: Evaluation and Application rules using symbolic rewriting Madhusudan Parthasarathy

More information

Demonstrating Lambda Calculus Reduction

Demonstrating Lambda Calculus Reduction Electronic Notes in Theoretical Computer Science 45 (2001) URL: http://www.elsevier.nl/locate/entcs/volume45.html 9 pages Demonstrating Lambda Calculus Reduction Peter Sestoft 1 Department of Mathematics

More information

6.184 Lecture 4. Interpretation. Tweaked by Ben Vandiver Compiled by Mike Phillips Original material by Eric Grimson

6.184 Lecture 4. Interpretation. Tweaked by Ben Vandiver Compiled by Mike Phillips Original material by Eric Grimson 6.184 Lecture 4 Interpretation Tweaked by Ben Vandiver Compiled by Mike Phillips Original material by Eric Grimson 1 Interpretation Parts of an interpreter Arithmetic calculator

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Operational Semantics CMSC 330 Summer 2018 1 Formal Semantics of a Prog. Lang. Mathematical description of the meaning of programs written in that language

More information

CSE341 Spring 2017, Final Examination June 8, 2017

CSE341 Spring 2017, Final Examination June 8, 2017 CSE341 Spring 2017, Final Examination June 8, 2017 Please do not turn the page until 8:30. Rules: The exam is closed-book, closed-note, etc. except for both sides of one 8.5x11in piece of paper. Please

More information

Introduction to ML. Based on materials by Vitaly Shmatikov. General-purpose, non-c-like, non-oo language. Related languages: Haskell, Ocaml, F#,

Introduction to ML. Based on materials by Vitaly Shmatikov. General-purpose, non-c-like, non-oo language. Related languages: Haskell, Ocaml, F#, Introduction to ML Based on materials by Vitaly Shmatikov slide 1 ML General-purpose, non-c-like, non-oo language Related languages: Haskell, Ocaml, F#, Combination of Lisp and Algol-like features (1958)

More information

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define CS 6A Scheme Summer 207 Discussion 0: July 25, 207 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

More information

Continuations and Continuation-Passing Style

Continuations and Continuation-Passing Style Continuations and Continuation-Passing Style Lecture 4 CS 390 1/16/08 Goal Weʼre interested in understanding how to represent the state of a co-routine Insight into what a thread really means How fundamental

More information

A Functional Representation of Data Structures with a Hole

A Functional Representation of Data Structures with a Hole A Functional Representation of Data Structures with a Hole Yasuhiko Mamide Research Institute for Mathematical Sciences Kyoto University Kyoto 606-01, JAPAN nan@kurims.kyoto-u.ac.jp Abstract Data structures

More information