6.037 Lecture 4. Interpretation. What is an interpreter? Why do we need an interpreter? Stages of an interpreter. Role of each part of the interpreter


 Gervase Sullivan
 1 years ago
 Views:
Transcription
1 6.037 Lecture 4 Interpretation Interpretation Parts of an interpreter Metacircular Evaluator (Schemeinscheme!) A slight variation: dynamic scoping Original material by Eric Grimson Tweaked by Zev Benjamin, Nelson Elhage, Keegan McAllister, Mike Phillips, Alex Vandiver, Ben Vandiver, Leon Shen 2 What is an interpreter? Why do we need an interpreter? Description of Computation Interpreter Results Abstractions let us bury details and focus on use of modules to solve large systems We need a process to unwind abstractions at execution time to deduce meaning We have already seen such a process the Environment Model Now want to describe that process as a procedure Update of internal state 3 4 Stages of an interpreter Lexical analyzer Parser Evaluator average: <proc> +: <proc>... Printer "(average 40 (+ 5 5))" ( average 40 ( symbol average input to each stage ) ) "25" symbol Role of each part of the interpreter Lexical analyzer break up input string into "words" called tokens Parser convert linear sequence of tokens to a tree like diagramming sentences in elementary school also convert selfevaluating tokens to their internal values e.g., #f is converted to the internal false value Evaluator follow language rules to convert parse tree to a value read and modify the environment as needed Printer convert value to humanreadable output string 6
2 Our interpreters Only write evaluator and environment Use Scheme's reader for lexical analysis and parsing Use Scheme's printer for output To do this, our language must resemble Scheme The Metacircular Evaluator And now a complete Scheme interpreter written in Scheme Why? An interpreter makes things explicit e.g., procedures and procedure application in the environment model Provides a precise definition for what the Scheme language means Describing a process in a computer language forces precision and completeness Sets the foundation for exploring variants of Scheme Today: lexical vs. dynamic scoping 7 8 The Core Evaluator proc args apply eval env expr eval/apply core Core evaluator eval: evaluate expression by dispatching on type apply: apply procedure to argument values by evaluating procedure body 1. (define (square x) (* x x)) (square 4) x = 4 (* x x) Metacircular evaluator (Scheme implemented in Scheme) primitives special forms ((begin? exp) (evalsequence (beginactions exp) ((cond? exp) (meval (cond>if exp) application (listofvalues (operands exp) ) 9 11 Things to observe cond determines the expression type No work to do on numbers Scheme's reader has already done the work It converts a sequence of characters like "24" to an internal binary representation of the number 24 selfevaluating! Procedure application must be at the end of the cond expression ((begin? exp) (evalsequence (beginactions exp) ((cond? exp) (eval (cond>if exp) (listofvalues (operands exp) ) 12 13
3 (define (listofvalues exps env) (map (lambda (exp) (meval exp exps)) mapply (define (mapply procedure arguments) (cond ((primitiveprocedure? procedure) (applyprimitiveprocedure procedure arguments)) ((compoundprocedure? procedure) (evalsequence (procedurebody procedure) (extendenvironment (procedureparameters procedure) arguments (procedureenvironment procedure)))) (else (error "Unknown procedure type  APPLY" procedure)))) Side comment procedure body The procedure body is a sequence of one or more expressions: (define (foo x) (dosomething (+ x 1)) (* x 5)) In mapply, we evalsequence the procedure body. (define (evalsequence exps env) (cond ((lastexp? exps) (meval (firstexp exps) (else (meval (firstexp exps) env) (evalsequence (restexps exps) )) ((begin? exp) (evalsequence (beginactions exp) ((cond? exp) (eval (cond>if exp) (listofvalues (operands exp) ) (define (evalassignment exp env) (setvariablevalue! (assignmentvariable exp) (meval (assignmentvalue exp) exp) (define (evaldefinition exp env) (definevariable! (definitionvariable exp) (meval (definitionvalue exp) env) ((begin? exp) (evalsequence (beginactions exp) ((cond? exp) (eval (cond>if exp) (listofvalues (operands exp) ) 18 19
4 (define (evalif exp env) (if (meval (ifpredicate exp) env) (meval (ifconsequent exp) env) (meval (ifalternative exp) ) ((begin? exp) (evalsequence (beginactions exp) ((cond? exp) (eval (cond>if exp) (listofvalues (operands exp) ) Implementation of lambda (eval '(lambda (x) (+ x x)) GE) (makeprocedure '(x) '((+ x x)) GE) (list 'compound '(x) '((+ x x)) GE) compound GE How the Environment Works Abstractly in our environment diagrams: Concretely our implementation (as in textbook) E2 x: 10 plus: (procedure...) E2 list of variables frame E1 enclosingenvironment list of values 3. environment manipulation + x This data structure is a procedure! x plus 10 procedure Extending the Environment (extendenvironment '(x y) '(4 5) E2) Concretely E3 list of variables frame list of values E2 Abstractly E1 E2 x: 10 plus: (procedure...) E3 x: 4 y: 5 E1 E3 E2 (((x y). (4 5)) ((x plus). (10 (proc..))) E1) "Scanning" the environment Look for a variable in the environment... Look for a variable in a frame... loop through the list of vars and list of vals in parallel detect if the variable is found in the frame If not found in frame (i.e. we reached end of list of vars), look in enclosing environment x y
5 Scanning the environment (details) (define (lookupvariablevalue var env) (define (envloop env) (define (scan vars vals) (cond ((null? vars) (envloop (enclosingenvironment ) ((eq? var (car vars)) (car vals)) (else (scan (cdr vars) (cdr vals))))) (if (eq? env theemptyenvironment) (error "Unbound variable  LOOKUP" var) (let ((frame (firstframe ) (scan (framevariables frame) (framevalues frame))))) (envloop The Initial (Global) Environment setupenvironment (define (setupenvironment) (let ((initialenv (extendenvironment 4. primitives and initial env. (primitiveprocedurenames) (primitiveprocedureobjects) theemptyenvironment))) (definevariable! 'true #T initialenv) (definevariable! 'false #F initialenv) initial define initial variables we always want bind explicit set of "primitive procedures" here: use underlying Scheme procedures in other interpreters: assembly code, hardware, Syntactic Abstraction Semantics What the language means Model of computation Syntax Particulars of writing expressions E.g. how to signal different expressions Separation of syntax and semantics: allows one to easily alter syntax 2. syntax procedures Basic Syntax (define (taggedlist? exp tag) (and (pair? exp) (eq? (car exp) tag))) Routines to detect expressions (define (if? exp) (taggedlist? exp 'if)) (define (lambda? exp) (taggedlist? exp 'lambda)) (define (application? exp) (pair? exp)) Routines to get information out of expressions (define (operator app) (car app)) (define (operands app) (cdr app)) eval/apply syntax procedures 28 Routines to manipulate expressions (define (nooperands? args) (null? args)) (define (firstoperand args) (car args)) (define (restoperands args) (cdr args)) 29 Example Changing Syntax Suppose you wanted a "verbose" application syntax, i.e., instead of use (<proc> <arg1> <arg2>...) (CALL <proc> ARGS <arg1> <arg2>...) Changes only in the syntax routines! Implementing "Syntactic Sugar" Idea: Easy way to add alternative/convenient syntax Allows us to implement a simpler "core" in the evaluator, and support the alternative syntax by translating it into core syntax "let" as sugared procedure application: (let ((<name1> <val1>) (<name2> <val2>)) <body>) (define (application? exp) (taggedlist? exp 'CALL)) (define (operator app) (cadr app)) (define (operands app) (cdddr app)) ((lambda (<name1> <name2>) <val1> <val2>) <body>) 30 31
6 Detect and Transform the Alternative Syntax ((variable? exp) (lookupvariablevalue exp ((quoted? exp) (textofquotation exp))... ((let? exp) (meval (let>combination exp) (listofvalues (operands exp) ) (else (error "Unknown expression" exp)))) Let Syntax Transformation FROM (let ((x 23) (y 15)) (dosomething x y)) TO ( (lambda (x y) (dosomething x y)) ) Let Syntax Transformation (define (let? exp) (taggedlist? exp 'let)) (define (letboundvariables letexp) (map car (cadr letexp))) (define (letvalues letexp) (map cadr (cadr letexp))) (define (letbody letexp) (cddr letexp)) Details of let syntax transformation (let ((x 23) (y 15)) (dosomething x y)) let (define (let>combination letexp) (let ((names (letboundvariables letexp)) (values (letvalues letexp)) (body (letbody letexp))) (cons (makelambda names body) values))) NOTE: only manipulates list structure, returning new list structure that acts as an expression 34 x 23 y 15 dosomething x y 35 Details of let syntax transformation Defining Procedures let x 23 y 15 lambda x y dosomething x 23 y 15 (define foo (lambda (x) <body>)) (define (foo x) <body>) Semantic implementation just another define: (define (evaldefinition exp env) (definevariable! (definitionvariable exp) (meval (definitionvalue exp) env) Syntactic transformation: (define (definitionvalue exp) (if (symbol? (cadr exp)) (caddr exp) (makelambda (cdadr exp) ;formal params (cddr exp)))) ;body dosomething x y 36 37
7 ReadEvalPrint Loop (define (driverloop) (promptforinput inputprompt) (let ((input (read))) (let ((output (meval input theglobal) (announceoutput outputprompt) (display output))) (driverloop)) 5. readevalprint loop Variations on a Scheme More (notso) stupid syntactic tricks Let with sequencing (let* ((x 4) (y (+ x 1)))... ) Infix notation ((4 * 3) + 7) instead of (+ (* 4 3) 7) Semantic variations Lexical vs dynamic scoping Lexical: defined by the program text Dynamic: defined by the runtime behavior Diving in Deeper: Lexical Scope Scoping is about how free variables are looked up (as opposed to bound parameters) (lambda (x) (* x x)) * is free x is bound How does our evaluator achieve lexical scoping? environment chaining procedures capture their enclosing lexical environment Diving in Deeper: Lexical Scope What makes our language lexically scoped? Because of the semantic rules we use for procedure application: Drop a new frame" Bind parameters to actual args in the new frame Link frame to the environment in which the procedure was defined (i.e., the environment surrounding the procedure in the program text) Evaluate body in this new environment" (define (foo x y) ) (define (bar l) (define (baz m) ) ) 40 (define (foo x y) ) (define (bar l) (define (baz m) ) ) 41 Lexical Scope & Environment Diagram (define (foo x y) (lambda (z) (+ x y z))) (define bar (foo 1 2)) (bar 3) GE foo: p: x y body: ( (z) (+ x y z)) bar: E1 x: 1 y: 2 p: z body: (+ x y z) Will always evaluate (+ x y z) in a new environment inside the surrounding lexical environment. E2 z: 3 (+ x y z) E2 => 6 42 Alternative Model: Dynamic Scoping Dynamic scope: Look up free variables in the caller's environment rather than the surrounding lexical environment Suppose we use our usual Example: environment model rules... (define (pooh x) (bear 20)) (define (bear y) (+ x y)) (pooh 9) pooh p: x b: (bear 20) x: 9 bear (bear 20) x not found p: y b: (+ x y) y: 20 (+ x y) 43
8 Dynamic Scope & Environment Diagram A "Dynamic" Scheme (define (pooh x) (bear 20)) (define (bear y) (+ x y)) (pooh 9) GE pooh: p: x body: (bear 20) E1 E2 x: 9 y: 20 Will evaluate (+ x y) in an environment that extends the caller's environment. (+ x y) E2 => 29 bear: p: y body: (+ x y 44 (cond ((selfevaluating? exp) exp)... '*noenvironment*)) ;CHANGE: no env... (dapply (meval (operator exp) env) (listofvalues (operands exp) env) ;CHANGE: add env (else (error "Unknown expression  MEVAL" exp)))) 45 A "Dynamic" Scheme dapply (define (dapply procedure arguments callingenv) (cond ((primitiveprocedure? procedure) (applyprimitiveprocedure procedure arguments)) ((compoundprocedure? procedure) (evalsequence (procedurebody procedure) (extendenvironment (procedureparameters procedure) arguments calling) ;CHANGE: use calling env (else (error "Unknown procedure" procedure)))) Evaluator Summary Scheme Evaluator Know it Inside & Out Techniques for language design: Interpretation: eval/apply Semantics vs. syntax Syntactic transformations Able to design new language variants! Lexical scoping vs. Dynamic scoping 46 47
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 informationBuilding up a language SICP Variations on a Scheme. Meval. The Core Evaluator. Eval. Apply. 2. syntax procedures. 1.
6.001 SICP Variations on a Scheme Scheme Evaluator A Grand Tour Techniques for language design: Interpretation: eval/appl Semantics vs. snta Sntactic transformations Building up a language... 3. 1. eval/appl
More informationScheme 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 informationWhy do we need an interpreter? SICP Interpretation part 1. Role of each part of the interpreter. 1. Arithmetic calculator.
.00 SICP Interpretation part Parts of an interpreter Arithmetic calculator Names Conditionals and if Store procedures in the environment Environment as explicit parameter Defining new procedures Why do
More informationFall 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 informationFunctional 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 subexpressions (if any).
More informationSyntactic Sugar: Using the Metacircular Evaluator to Implement the Language You Want
Computer Science 21b (Spring Term, 2017) Structure and Interpretation of Computer Programs Syntactic Sugar: Using the Metacircular Evaluator to Implement the Language You Want Here is one of the big ideas
More informationDiscussion 12 The MCE (solutions)
Discussion 12 The MCE (solutions) ;;;;METACIRCULAR EVALUATOR FROM CHAPTER 4 (SECTIONS 4.1.14.1.4) of ;;;; STRUCTURE AND INTERPRETATION OF COMPUTER PROGRAMS ;;;from section 4.1.4  must precede def of
More informationCS61A Discussion Notes: Week 11: The Metacircular Evaluator By Greg Krimer, with slight modifications by Phoebus Chen (using notes from Todd Segal)
CS61A Discussion Notes: Week 11: The Metacircular Evaluator By Greg Krimer, with slight modifications by Phoebus Chen (using notes from Todd Segal) What is the Metacircular Evaluator? It is the best part
More informationStreams, Delayed Evaluation and a Normal Order Interpreter. CS 550 Programming Languages Jeremy Johnson
Streams, Delayed Evaluation and a Normal Order Interpreter CS 550 Programming Languages Jeremy Johnson 1 Theme This lecture discusses the stream model of computation and an efficient method of implementation
More information6.037 Lecture 7B. Scheme Variants Normal Order Lazy Evaluation Streams
6.037 Lecture 7B Scheme Variants Normal Order Lazy Evaluation Streams Edited by Mike Phillips & Ben Vandiver Original Material by Eric Grimson & Duane Boning Further Variations on a Scheme Beyond Scheme
More informationBelow are example solutions for each of the questions. These are not the only possible answers, but they are the most common ones.
6.001, Fall Semester, 2002 Quiz II Sample solutions 1 MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science 6.001 Structure and Interpretation of Computer Programs
More informationComputer Science 21b (Spring Term, 2015) Structure and Interpretation of Computer Programs. Lexical addressing
Computer Science 21b (Spring Term, 2015) Structure and Interpretation of Computer Programs Lexical addressing The difference between a interpreter and a compiler is really two points on a spectrum of possible
More informationProject 2: Scheme Interpreter
Project 2: Scheme Interpreter CSC 4101, Fall 2017 Due: 12 November 2017 For this project, you will implement a simple Scheme interpreter in C++ or Java. Your interpreter should be able to handle the same
More informationCS61A Midterm 2 Review (v1.1)
Spring 2006 1 CS61A Midterm 2 Review (v1.1) Basic Info Your login: Your section number: Your TA s name: Midterm 2 is going to be held on Tuesday 79p, at 1 Pimentel. What will Scheme print? What will the
More informationregsim.scm ~/umb/cs450/ch5.base/ 1 11/11/13
1 File: regsim.scm Register machine simulator from section 5.2 of STRUCTURE AND INTERPRETATION OF COMPUTER PROGRAMS This file can be loaded into Scheme as a whole. Then you can define and simulate machines
More informationIntroduction to Scheme
How do you describe them Introduction to Scheme Gul Agha CS 421 Fall 2006 A language is described by specifying its syntax and semantics Syntax: The rules for writing programs. We will use Context Free
More informationA Brief Introduction to Scheme (II)
A Brief Introduction to Scheme (II) Philip W. L. Fong pwlfong@cs.uregina.ca Department of Computer Science University of Regina Regina, Saskatchewan, Canada Lists Scheme II p.1/29 Lists Aggregate data
More informationLexical vs. Dynamic Scope
Intro Lexical vs. Dynamic Scope where do I point to? Remember in Scheme whenever we call a procedure we pop a frame and point it to where the procedure points to (its defining environment). This is called
More informationAn ExplicitContinuation Metacircular Evaluator
Computer Science (1)21b (Spring Term, 2018) Structure and Interpretation of Computer Programs An ExplicitContinuation Metacircular Evaluator The vanilla metacircular evaluator gives a lot of information
More informationEvaluating Scheme Expressions
Evaluating Scheme Expressions How Scheme evaluates the expressions? (procedure arg 1... arg n ) Find the value of procedure Find the value of arg 1 Find the value of arg n Apply the value of procedure
More informationFrom Syntactic Sugar to the Syntactic Meth Lab:
From Syntactic Sugar to the Syntactic Meth Lab: Using Macros to Cook the Language You Want a V E N E TRUT H Brandeis S PA R T U N T O I T S I N N E R M OS T COMPUTER SCIENCE 21B: Structure and Interpretation
More informationLecture 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 informationBuilding a system for symbolic differentiation
Computer Science 21b Structure and Interpretation of Computer Programs Building a system for symbolic differentiation Selectors, constructors and predicates: (constant? e) Is e a constant? (variable? e)
More informationDeferred 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 thecons (cons 1 #f)) (setcdr! thecons thecons) (define (runincircles l) (+
More informationTurtles All The Way Down
Turtles All The Way Down Bertrand Russell had just finished giving a public lecture on the nature of the universe. An old woman said Prof. Russell, it is well known that the earth rests on the back of
More informationFunctional Programming. Pure Functional Languages
Functional Programming Pure functional PLs Sexpressions cons, car, cdr Defining functions readevalprint loop of Lisp interpreter Examples of recursive functions Shallow, deep Equality testing 1 Pure
More informationCS 314 Principles of Programming Languages
CS 314 Principles of Programming Languages Lecture 16: Functional Programming Zheng (Eddy Zhang Rutgers University April 2, 2018 Review: Computation Paradigms Functional: Composition of operations on data.
More informationBuilding a system for symbolic differentiation
Computer Science 21b Structure and Interpretation of Computer Programs Building a system for symbolic differentiation Selectors, constructors and predicates: (constant? e) Is e a constant? (variable? e)
More informationCS 314 Principles of Programming Languages. Lecture 16
CS 314 Principles of Programming Languages Lecture 16 Zheng Zhang Department of Computer Science Rutgers University Friday 28 th October, 2016 Zheng Zhang 1 CS@Rutgers University Class Information Reminder:
More informationCS 360 Programming Languages Interpreters
CS 360 Programming Languages Interpreters Implementing PLs Most of the course is learning fundamental concepts for using and understanding PLs. Syntax vs. semantics vs. idioms. Powerful constructs like
More informationReview Analyzing Evaluator. CS61A Lecture 25. What gets returned by mceval? (not analyzing eval) REVIEW What is a procedure?
2 1 Review Analyzing Evaluator CS61A Lecture 20110802 Colleen Lewis What s look like What the output of analyze was Fact: The body of a lambda gets analyzed! We can give names to analyzed lambdas What
More informationFunctional Programming. Pure Functional Languages
Functional Programming Pure functional PLs Sexpressions cons, car, cdr Defining functions readevalprint loop of Lisp interpreter Examples of recursive functions Shallow, deep Equality testing 1 Pure
More information6.001: Structure and Interpretation of Computer Programs
6.001: Structure and Interpretation of Computer Programs Symbols Quotation Relevant details of the reader Example of using symbols Alists Differentiation Data Types in Lisp/Scheme Conventional Numbers
More informationComp 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 informationCS61A Summer 2010 George Wang, Jonathan Kotker, Seshadri Mahalingam, Eric Tzeng, Steven Tang
CS61A Notes Week 6B: Streams Streaming Along A stream is an element and a promise to evaluate the rest of the stream. You ve already seen multiple examples of this and its syntax in lecture and in the
More informationThis exam is worth 70 points, or about 23% of your total course grade. The exam contains 15 questions.
CS 61A Final Exam May 16, 2008 Your name login: cs61a This exam is worth 70 points, or about 23% of your total course grade. The exam contains 15 questions. This booklet contains 18 numbered pages including
More informationAdministrivia. Simple data types
Administrivia Lists, higher order procedures, and symbols 6.037  Structure and Interpretation of Computer Programs Mike Phillips (mpp) Massachusetts Institute of Technology Project 0 was due today Reminder:
More informationAn Explicit Continuation Evaluator for Scheme
Massachusetts Institute of Technology Course Notes 2 6.844, Spring 05: Computability Theory of and with Scheme February 17 Prof. Albert R. Meyer revised March 3, 2005, 1265 minutes An Explicit Continuation
More informationUsing Symbols in Expressions (1) evaluate subexpressions... Number. ( ) machine code to add
Using Symbols in Expressions (1) (define z y) z Symbol y z ==> y prints as (+ x 3) evaluate subexpressions... PrimProc Number Number ( ) machine code to add 23 3 Number 26 apply... ==> 26 prints as 1
More information4.2 Variations on a Scheme  Lazy Evaluation
[Go to first, previous, next page; contents; index] 4.2 Variations on a Scheme  Lazy Evaluation Now that we have an evaluator expressed as a Lisp program, we can experiment with alternative choices in
More informationAnnouncements. 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! Objectoriented programming: Python Functional programming: Scheme! Introduction! Numeric operators, REPL, quotes, functions, conditionals! Function examples, helper
More informationNormal Order (Lazy) Evaluation SICP. Applicative Order vs. Normal (Lazy) Order. Applicative vs. Normal? How can we implement lazy evaluation?
Normal Order (Lazy) Evaluation Alternative models for computation: Normal (Lazy) Order Evaluation Memoization Streams Applicative Order: evaluate all arguments, then apply operator Normal Order: pass unevaluated
More informationDocumentation for LISP in BASIC
Documentation for LISP in BASIC The software and the documentation are both Copyright 2008 Arthur NunesHarwitt LISP in BASIC is a LISP interpreter for a Schemelike dialect of LISP, which happens to have
More informationCSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341)
CSE 413 Languages & Implementation Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341) 1 Goals Representing programs as data Racket structs as a better way to represent
More informationCSc 520 Principles of Programming Languages
CSc 520 Principles of Programming Languages 9: Scheme Metacircular Interpretation Christian Collberg collberg@cs.arizona.edu Department of Computer Science University of Arizona Copyright c 2005 Christian
More informationCOP4020 Programming Assignment 1  Spring 2011
COP4020 Programming Assignment 1  Spring 2011 In this programming assignment we design and implement a small imperative programming language MicroPL. To execute MircoPL code we translate the code to
More information6.001 Notes: Section 15.1
6.001 Notes: Section 15.1 Slide 15.1.1 Our goal over the next few lectures is to build an interpreter, which in a very basic sense is the ultimate in programming, since doing so will allow us to define
More information(scheme1) has lambda but NOT define
CS61A Lecture 12 2011011 Colleen Lewis (calc) review (scheme1) has lambda but NOT define Remember calcapply? STk> (calcapply '+ '(1 2 )) 6 STk> (calcapply '* '(2 4 )) 24 STk> (calcapply '/ '(10
More informationPrinciples 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 informationParsing 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 makereturn START maketest makeclose makeassign make pair? yes
More informationSCHEME AND CALCULATOR 5b
SCHEME AND CALCULATOR 5b COMPUTER SCIENCE 6A July 25, 203 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 informationTAIL RECURSION, SCOPE, AND PROJECT 4 11
TAIL RECURSION, SCOPE, AND PROJECT 4 11 COMPUTER SCIENCE 61A Noveber 12, 2012 1 Tail Recursion Today we will look at Tail Recursion and Tail Call Optimizations in Scheme, and how they relate to iteration
More informationFall Semester, Lecture Notes { November 12, Variations on a Scheme Nondeterministic evaluation
1 MASSACHUSETTS INSTITUTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science 6.001 Structure and Interpretation of Computer Programs Fall Semester, 1996 Lecture Notes { November 12,
More informationAn Introduction to Scheme
An Introduction to Scheme Stéphane Ducasse stephane.ducasse@inria.fr http://stephane.ducasse.free.fr/ Stéphane Ducasse 1 Scheme Minimal Statically scoped Functional Imperative Stack manipulation Specification
More informationPrinciples of Programming Languages 2017W, Functional Programming
Principles of Programming Languages 2017W, Functional Programming Assignment 3: Lisp Machine (16 points) Lisp is a language based on the lambda calculus with strict execution semantics and dynamic typing.
More informationThe Eval/Apply Cycle Eval. Evaluation and universal machines. Examining the role of Eval. Eval from perspective of language designer
Evaluation and universal machines What is the role of evaluation in defining a language? How can we use evaluation to design a language? The Eval/Apply Cycle Eval Exp & env Apply Proc & args Eval and Apply
More informationFP Foundations, Scheme
FP Foundations, Scheme In Text: Chapter 15 1 Functional Programming  Prelude We have been discussing imperative languages C/C++, Java, Fortran, Pascal etc. are imperative languages Imperative languages
More informationChapter 1. Fundamentals of Higher Order Programming
Chapter 1 Fundamentals of Higher Order Programming 1 The Elements of Programming Any powerful language features: so does Scheme primitive data procedures combinations abstraction We will see that Scheme
More informationCS 342 Lecture 8 Data Abstraction By: Hridesh Rajan
CS 342 Lecture 8 Data Abstraction By: Hridesh Rajan 1 Com S 342 so far So far we have studied: Language design goals, Basic functional programming, Flat recursion over lists, Notion of Scheme procedures
More informationA Small Interpreted Language
A Small Interpreted Language What would you need to build a small computing language based on mathematical principles? The language should be simple, Turing equivalent (i.e.: it can compute anything that
More informationCOP4020 Programming Languages. Functional Programming Prof. Robert van Engelen
COP4020 Programming Languages Functional Programming Prof. Robert van Engelen Overview What is functional programming? Historical origins of functional programming Functional programming today Concepts
More informationUserdefined Functions. Conditional Expressions in Scheme
Userdefined Functions The list (lambda (args (body s to a function with (args as its argument list and (body as the function body. No quotes are needed for (args or (body. (lambda (x (+ x 1 s to the increment
More informationCS 275 Name Final Exam Solutions December 16, 2016
CS 275 Name Final Exam Solutions December 16, 2016 You may assume that atom? is a primitive procedure; you don t need to define it. Other helper functions that aren t a standard part of Scheme you need
More information6.001, Spring Semester, 1998, Final Exam Solutions Your Name: 2 Part c: The procedure evaluntil: (define (evaluntil exp env) (let ((return (evalseq
1 MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science 6.001 Structure and Interpretation of Computer Programs Spring Semester, 1998, Final Exam Solutions Your
More informationClass Structure. Prerequisites
Class Structure Procedural abstraction and recursion 6.037  Structure and Interpretation of Computer Programs Mike Phillips, Benjamin Barenblat, Leon Shen, Ben Vandiver, Alex Vandiver, Arthur Migdal Massachusetts
More informationOrganization of Programming Languages CS3200/5200N. Lecture 11
Organization of Programming Languages CS3200/5200N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Functional vs. Imperative The design of the imperative languages
More informationCS61A Notes Week 13: Interpreters
CS61A Notes Week 13: Interpreters ReadEval Loop Unlike Python, the result of evaluating an expression is not automatically printed. Instead, Logo complains if the value of any toplevel expression is
More informationC311 Lab #3 Representation Independence: Representation Independent Interpreters
C311 Lab #3 Representation Independence: Representation Independent Interpreters Will Byrd webyrd@indiana.edu February 5, 2005 (based on Professor Friedman s lecture on January 29, 2004) 1 Introduction
More informationBasic Scheme February 8, Compound expressions Rules of evaluation Creating procedures by capturing common patterns
Basic Scheme February 8, 2007 Compound expressions Rules of evaluation Creating procedures by capturing common patterns Previous lecture Basics of Scheme Expressions and associated values (or syntax and
More informationNotes 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 informationComp 411 Principles of Programming Languages Lecture 7 Metainterpreters. Corky Cartwright January 26, 2018
Comp 411 Principles of Programming Languages Lecture 7 Metainterpreters Corky Cartwright January 26, 2018 Denotational Semantics The primary alternative to syntactic semantics is denotational semantics.
More informationProject 5  The MetaCircular Evaluator
MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science 6.001 Structure and Interpretation of Computer Programs Spring Semester, 2005 Project 5  The MetaCircular
More informationData Abstraction. An Abstraction for Inductive Data Types. Philip W. L. Fong.
Data Abstraction An Abstraction for Inductive Data Types Philip W. L. Fong pwlfong@cs.uregina.ca Department of Computer Science University of Regina Regina, Saskatchewan, Canada Introduction This lecture
More informationLECTURE 16. Functional Programming
LECTURE 16 Functional Programming WHAT IS FUNCTIONAL PROGRAMMING? Functional programming defines the outputs of a program as a mathematical function of the inputs. Functional programming is a declarative
More information;;; Determines if e is a primitive by looking it up in the primitive environment. ;;; Define indentation and output routines for the output for
Page 1/11 (require (lib "trace")) Allow tracing to be turned on and off (define tracing #f) Define a string to hold the error messages created during syntax checking (define error msg ""); Used for fancy
More informationVectors in Scheme. Data Structures in Scheme
Data Structures in Scheme Vectors in Scheme In Scheme, lists and Sexpressions are basic. Arrays can be simulated using lists, but access to elements deep in the list can be slow (since a list is a linked
More informationCSSE 304 Assignment #13 (interpreter milestone #1) Updated for Fall, 2018
CSSE 304 Assignment #13 (interpreter milestone #1) Updated for Fall, 2018 Deliverables: Your code (submit to PLC server). A13 participation survey (on Moodle, by the day after the A13 due date). This is
More informationLecture08: Scope and Lexical Address
Lecture08: Scope and Lexical Address Free and Bound Variables (EOPL 1.3.1) Given an expression E, does a particular variable reference x appear free or bound in that expression? Definition: A variable
More informationScheme. Functional Programming. Lambda Calculus. CSC 4101: Programming Languages 1. Textbook, Sections , 13.7
Scheme Textbook, Sections 13.1 13.3, 13.7 1 Functional Programming Based on mathematical functions Take argument, return value Only function call, no assignment Functions are firstclass values E.g., functions
More informationCSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures
CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures Dan Grossman Fall 2014 Hi! I m not Hal J I love this stuff and have taught
More informationProject 5  The MetaCircular Evaluator
MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science 6.001 Structure and Interpretation of Computer Programs Fall Semester, 2005 Project 5  The MetaCircular
More informationLecture 12: Conditional Expressions and Local Binding
Lecture 12: Conditional Expressions and Local Binding Introduction Corresponds to EOPL 3.33.4 Please review Version1 interpreter to make sure that you understand how it works Now we will extend the basic
More informationFunctional Programming
Functional Programming CS331 Chapter 14 Functional Programming Original functional language is LISP LISt Processing The list is the fundamental data structure Developed by John McCarthy in the 60 s Used
More informationScheme Quick Reference
Scheme Quick Reference COSC 18 Winter 2003 February 10, 2003 1 Introduction This document is a quick reference guide to common features of the Scheme language. It is by no means intended to be a complete
More information6.001, Spring Semester, 1998, Final Exam Your Name: 2 Question 1 (12 points): Each of the parts below should be treated as independent. For each part,
1 MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science 6.001 Structure and Interpretation of Computer Programs Spring Semester, 1998, Final Exam Your Name: Open
More information6.945 Adventures in Advanced Symbolic Programming
MIT OpenCourseWare http://ocw.mit.edu 6.945 Adventures in Advanced Symbolic Programming Spring 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. ps.txt
More information11/6/17. Functional programming. FP Foundations, Scheme (2) LISP Data Types. LISP Data Types. LISP Data Types. Scheme. LISP: John McCarthy 1958 MIT
Functional programming FP Foundations, Scheme (2 In Text: Chapter 15 LISP: John McCarthy 1958 MIT List Processing => Symbolic Manipulation First functional programming language Every version after the
More informationPrinciples of Programming Languages
Principles of Programming Languages Lesson 14 Type Checking Collaboration and Management Dana Fisman www.cs.bgu.ac.il/~ppl172 1 Type Checking We return to the issue of type safety we discussed informally,
More informationScheme: Strings Scheme: I/O
Scheme: Strings Scheme: I/O CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Wednesday, April 5, 2017 Glenn G. Chappell Department of Computer Science University of
More informationMASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science. Issued: Wed. 26 April 2017 Due: Wed.
ps.txt Fri Apr 07 14:24:11 2017 1 MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science 6.945 Spring 2017 Problem Set 9 Issued: Wed. 26 April 2017 Due: Wed. 12
More informationAn introduction to Scheme
An introduction to Scheme Introduction A powerful programming language is more than just a means for instructing a computer to perform tasks. The language also serves as a framework within which we organize
More informationScheme: Data. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, Glenn G.
Scheme: Data CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, 2017 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks ggchappell@alaska.edu
More informationSummer 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 informationScheme Quick Reference
Scheme Quick Reference COSC 18 Fall 2003 This document is a quick reference guide to common features of the Scheme language. It is not intended to be a complete language reference, but it gives terse summaries
More information6.001 Notes: Section 8.1
6.001 Notes: Section 8.1 Slide 8.1.1 In this lecture we are going to introduce a new data type, specifically to deal with symbols. This may sound a bit odd, but if you step back, you may realize that everything
More informationRecursive Functions of Symbolic Expressions and Their Computation by Machine Part I
Recursive Functions of Symbolic Expressions and Their Computation by Machine Part I by John McCarthy IkSoon Kim Winter School 2005 Feb 18, 2005 Overview Interesting paper with By John Mitchell Interesting
More informationCS 314 Principles of Programming Languages
CS 314 Principles of Programming Languages Lecture 17: Functional Programming Zheng (Eddy Zhang Rutgers University April 4, 2018 Class Information Homework 6 will be posted later today. All test cases
More informationFall 2018 Discussion 8: October 24, 2018 Solutions. 1 Introduction. 2 Primitives
CS 6A Scheme Fall 208 Discussion 8: October 24, 208 Solutions Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write
More informationThe 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: smallstep substitution model static semantics
More information