3.4 Local Binding Recall Scheme's let: > (let ((x 5)‏ (y 6))

Slides:



Advertisements
Similar presentations
Plt /7/ Data Abstraction Programming Language Essentials 2nd edition Chapter 2.2 An Abstraction for Inductive Data Types.
Advertisements

Cs784(Prasad)L10Rec1 Implementing Recursion. cs784(Prasad)L10Rec2 let insufficient for recursion ( (let((fact(lambda (n) (if (zero? n) 1 (* n (fact (-
Closures & Environments CS153: Compilers Greg Morrisett.
Semantics of PLs via Interpreters: Getting Started CS784: Programming Languages Prabhaker Mateti.
Scheme in Scheme. Why implement Scheme in Scheme  Implementing a language is a good way to learn more about programming languages  Interpreters are.
Assignments and Procs w/Params EOPL3 Chapter 4. Expressible vs. Denotable values Expressible Values –the language can express and compute these –represented.
Objectives Understand grammar of OOP Understand equivalent Java code Discuss different implementations of classes and objects.
Recap 1.Programmer enters expression 2.ML checks if expression is “well-typed” Using a precise set of rules, ML tries to find a unique type for the expression.
1 Programming Languages (CS 550) Lecture Summary Functional Programming and Operational Semantics for Scheme Jeremy R. Johnson.
Functional Programming. Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends.
Cs7100(Prasad)L8Interp1 Interpreters Study Semantics of Programming Languages through interpreters (Executable Specifications)
3.6 Interpreter: Recursion Recall Scheme's letrec (recursive let ): > (letrec ((fact (lambda (x) (if (zero? x) 1 (* x (fact (- x 1))))) (fact 6)) 720 Question:
Metacircular Evaluation SICP Chapter 4 Mark Boady.
Cs784(TK)1 Semantics of Procedures and Scopes. Kinds of Scope Static or Lexical scope –determined by structure of program –Scheme, C++, Java, and many.
1 Scheme Scheme is a functional language. Scheme is based on lambda calculus. lambda abstraction = function definition In Scheme, a function is defined.
SICP Variations on a Scheme Scheme Evaluator – A Grand Tour Techniques for language design: Interpretation: eval/apply Semantics vs. syntax Syntactic.
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
EOPL3: Section 3.3 PROC and App B: SLLGEN
Cs784(tk)1 Implementing Recursion. Recap: Goals Experimenting with PL design alternatives Scoping, parameter passing, arrays,... Runnable prototype of.
PrasadL145OOL1 Managing Environments An Exercise in the Design, Analysis, Specification, and Implementation of the Core of an OOP Language. Object-Oriented.
5.4.1: Implementation Method Invocation (define eval-expression (lambda (exp env) (cases expression exp... (method-app-exp (obj-exp method-name rands)
Cs7100(Prasad)L8Proc1 Procedures. cs7100(Prasad)L8Proc2 Primitive procedures  etc User-defined procedures –Naming a sequence of operations.
Plt /12/ Data Abstraction Programming Language Essentials 2nd edition Chapter 2.3 Representation Strategies for Data Types.
3.5 Procedures Recall procedures (functions) in Scheme: (let ((f (lambda(y z) (+ y (- z 5))) (f 2 28)) We would like something similar in our toy language:
Plt /17/ Environment-Passing Interpreters Programming Language Essentials 2nd edition Chapter 3.8 Parameter-Passing Variations.
Plt /19/ Environment-Passing Interpreters Programming Language Essentials 2nd edition Chapter 3.1 A Simple Interpreter.
Comp 311 Principles of Programming Languages Lecture 4 The Scope of Variables Corky Cartwright September 3, 2008.
Compiler (javac) vs. Interpreter (drscheme): Chapter 3: Environment-Passing Interpreters Front End Interpreter program textsyntax tree answer > ((lambda.
Inductively Defined Data Concrete and Abstract syntax Karl Lieberherr.
3.3 Conditional Evaluation --> if 1 then 2 else 3 2 Want to support if/then/else We'll represent false as 0, true as 1: Syntax (BNF): ::= if then else.
Objects and Classes Gul Agha CS 421 Spring /11/2001CS 322 Fall Characteristics of OOP Object-based  encapsulate state  provide interface.
Cs784 (Prasad)L6AST1 Abstract Syntax. cs784 (Prasad)L6AST2 Language of -expressions ::= | (lambda ( ) ) | ( ) E.g., concrete syntax Scheme S-expressions.
Operational Semantics of Scheme
Lecture 4: Metacircles Eval Apply David Evans
Abstract Syntax cs7100 (Prasad) L7AST.
The interpreter.
Interpreters Study Semantics of Programming Languages through interpreters (Executable Specifications) cs7100(Prasad) L8Interp.
Corky Cartwright January 18, 2017
Implementing Recursion
Env. Model Implementation
Original material by Eric Grimson
5.4.1: Implementation Method Invocation
زبان بدن Body Language.
Semantics of PLs via Interpreters: Getting Started
The Metacircular Evaluator
Lecture 23 Pages : Separating Syntactic Analysis from Execution. We omit many details so you have to read the section in the book. The halting.
Abstract Syntax Prabhaker Mateti 1.
CSE 341 Section 7 Winter 2018 Adapted from slides by Eric Mullen, Nicholas Shahan, Dan Grossman, and Tam Dang.
Dynamic Scoping Lazy Evaluation
The Metacircular Evaluator
Scoping and Binding of Variables
Procedures App B: SLLGEN 1.
3.7 Variable Assignment Recall instance variables in Python:
The Metacircular Evaluator (Continued)
Lecture 26: The Metacircular Evaluator Eval Apply
Extending our interpreted language with Scheme’s set!
Chapter 1 Review: BNF Grammar for lists:
Abstract Syntax cs7100 (Prasad) L7AST.
2.2.2 Abstract Syntax Recall BNF definition of l-calculus expressions:
3.6 Interpreter: Recursion
6.001 SICP Variations on a Scheme
2.2.2 Abstract Syntax Recall BNF definition of l-calculus expressions:
Chapter 3: Environment-Passing Interpreters
6.001 SICP Interpretation Parts of an interpreter
Assignments and Procs w/Params
topics interpreters meta-linguistic abstraction eval and apply
Recursive Procedures and Scopes
Rehearsal: Lazy Evaluation Infinite Streams in our lazy evaluator
Inductively Defined Data Concrete and Abstract syntax
Lecture 25: The Metacircular Evaluator Eval Apply
Presentation transcript:

3.4 Local Binding Recall Scheme's let: > (let ((x 5)‏ (y 6)) 11 Make let look different in our defined language: --> let x = 5 y = 6 in +(x, y)‏

3.4 Local Binding: Step 1 Syntax: <expression> ::= let {<identifier> = <expression>}* in <expression> Add some code to grammar: (define grammar-3-4 '((program (expression) a-program)‏ (expression (number) lit-exp)‏ (expression (identifier) var-exp) . . . (expression ("let" (arbno identifier "=" expression) "in" expression) let-exp)

3.4 Local Binding: Step 2 Add some code to datatype definition: (define-datatype expression expression? ... (let-exp (ids (list-of symbol?))‏ (rands (list-of expression?)) (body expression?)))‏

3.4 Local Binding: Step 3 Add some code to eval-expression: (define eval-expression (lambda (exp env)‏ (cases expression exp ... (let-exp (ids rands body)‏ (let ((args (eval-rands rands env)))‏ (eval-expression body (extend-env ids args env))))‏