Chapter 1 Review: BNF Grammar for lists:

Slides:



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

Closures & Environments CS153: Compilers Greg Morrisett.
Scheme in Scheme. Why implement Scheme in Scheme  Implementing a language is a good way to learn more about programming languages  Interpreters are.
Functional Programming. Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends.
Chapter 3 Functional Programming. Outline Introduction to functional programming Scheme: an untyped functional programming language.
Metacircular Evaluation SICP Chapter 4 Mark Boady.
1 Lecture 18 Continue Evaluator. 2 z9 true#t + twice Representing procedures (eval '(define twice (lambda (x) (+ x x))) GE) symbol primitive scheme procedure.
SICP Symbolic data Symbol: a primitive type Generalization Symbolic differentiation.
מבוא מורחב - שיעור 10 1 Symbols Manipulating lists and trees of symbols: symbolic differentiation Lecture 10.
Functional programming: LISP Originally developed for symbolic computing Main motivation: include recursion (see McCarthy biographical excerpt on web site).
6.001 SICP SICP – Evaluation I Recitation 11/19/2004 Eval review Evaluation examples define lambda apply New language elements.
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.
Scheme More MCE examples. Q1 new special form which defines global variables (static ) search the global environment – Variable exists: does nothing,
SchemeCOP Introduction to Scheme. SchemeCOP Scheme Meta-language for coding interpreters –“ clean ” semantics Scheme = LISP + ALGOL –simple.
The environment model evaluator and compiler 1 The env model evaluator Motivation In one word: Efficiency Saves repeated renaming and substitution: Using.
EOPL3: Section 3.3 PROC and App B: SLLGEN
Plt /8/ Inductive Sets of Data Programming Language Essentials 2nd edition Chapter 1.2 Recursively Specified Programs.
A Scheme Refresher (Functional Subset) Prabhaker Mateti.
6.001 SICP 1/ : Structure and Interpretation of Computer Programs Symbols Example of using symbols Differentiation.
1 The metacircular evaluator (Cont.) Defining new procedures (define (lambda? e) (tag-check e 'lambda)) (define (eval exp env) (cond ((number? exp)
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:
Functional Programming Universitatea Politehnica Bucuresti Adina Magda Florea
CS220 Programming Principles 프로그래밍의 이해 2002 가을학기 Class 15: Meta-Circular Evaluator 한 태숙.
SICP Interpretation Parts of an interpreter Arithmetic calculator Names Conditionals and if Storing procedures in the environment Environment as.
Plt /19/ Environment-Passing Interpreters Programming Language Essentials 2nd edition Chapter 3.1 A Simple Interpreter.
18-October-2002cse Symbols © 2002 University of Washington1 Symbols CSE 413, Autumn 2002 Programming Languages
מבוא מורחב 1 Lecture #9. מבוא מורחב 2 Symbol: a primitive type constructors: (quote alpha) ==> quote is a special form. One argument: a name. selectors.
CS220 Programming Principles 프로그래밍의 이해 2002 가을학기 Class 6 한 태숙.
Scheme Profs Tim Sheard and Andrew Black CS 311 Computational Structures.
Compiler (javac) vs. Interpreter (drscheme): Chapter 3: Environment-Passing Interpreters Front End Interpreter program textsyntax tree answer > ((lambda.
CS61A Lecture Colleen Lewis. Clicker poll Do you feel comfortable posting questions to piazza? A)Yes with my classmates and instructors.
Cs784 (Prasad)L6AST1 Abstract Syntax. cs784 (Prasad)L6AST2 Language of -expressions ::= | (lambda ( ) ) | ( ) E.g., concrete syntax Scheme S-expressions.
Abstract Syntax cs7100 (Prasad) L7AST.
Chapter 1: Inductive Sets of Data
Additional Scheme examples
History of Computing – Lisp
Introduction to Scheme
Interpreters Study Semantics of Programming Languages through interpreters (Executable Specifications) cs7100(Prasad) L8Interp.
Chapter 15 – Functional Programming Languages
September 4, 1997 Programming Languages (CS 550) Lecture 6 Summary Operational Semantics of Scheme using Substitution Jeremy R. Johnson TexPoint fonts.
Corky Cartwright January 18, 2017
Env. Model Implementation
Original material by Eric Grimson
Case Study: Undefined Variables
The Metacircular Evaluator
Abstract Syntax Prabhaker Mateti 1.
Dynamic Scoping Lazy Evaluation
The Metacircular Evaluator
Scoping and Binding of Variables
Procedures App B: SLLGEN 1.
3.4 Local Binding Recall Scheme's let: > (let ((x 5)‏ (y 6))
Rules of evaluation The value of a number is itself.
The Metacircular Evaluator (Continued)
Lecture 26: The Metacircular Evaluator Eval Apply
6.001 SICP Further Variations on a Scheme
Streams, Delayed Evaluation and a Normal Order Interpreter
Lecture #9 מבוא מורחב.
Abstract Syntax cs7100 (Prasad) L7AST.
2.2.2 Abstract Syntax Recall BNF definition of l-calculus expressions:
topics mutable data structures
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
CSE S. Tanimoto Lambda Calculus
topics interpreters meta-linguistic abstraction eval and apply
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:

Chapter 1 Review: BNF Grammar for lists: <list> ::= ({<datum>}*) <dotted-datum> ::= ({<datum>}+ . <datum>) <vector> ::= #({<datum>}*) <datum> ::= <number> | <symbol> | <boolean> | <string> ::= <list> | <dotted-datum> | <vector> Let's derive (a “mixed” # (bag (of . data))) from this grammar....

Chapter 1 Review: Free and Bound Variables A variable x occurs free in a l-calculus expression E iff: 1. E is a variable reference and E = x; or 2. E is of the form (l (y) E') where y ≠ x and x occurs free in E'; or 3. E is of the form (E1 E2) and x occurs free in E1 or E2 Let's prove that b occurs free in (l (a) (a b))

Chapter 1 Review: Free and Bound Variables A variable x occurs bound in a l-calculus expression E iff: 1. E is of the form (l (y) E') where x occurs bound in E' or x = y and y occurs free in E'; or 2. E is of the form (E1 E2) and x occurs bound in E1 or E2 Let's prove that a occurs bound in (l (a) (a b))

Coding It Up: Follow the Definition (define occurs-free? (lambda (var exp) (cond 1. E is a variable reference and E = x; or ((symbol? exp) (eqv? var exp)) 2. E is of the form (l (y) E') where y ≠ x and x occurs free in E'; or ((eqv? (car exp) 'lambda) (and (not (eqv? (caadr exp) var)) (occurs-free? var (caddr exp)))) 3. E is of the form (E1 E2) and x occurs free in E1 or E2 ((else (or (occurs-free? var (car exp)) (occurs-free? var (cadr exp)))))))

(define occurs-bound? (lambda (var exp) (cond 0. symbol by itself isn't bound ((symbol? exp) #f) 1. E is of the form (l (y) E') where x occurs bound in E' ((eqv? (car exp) 'lambda) (or (occurs-bound? var (caddr exp)) or x = y and y occurs free in E'; or (and (eqv? (caadr exp) var) (occurs-free? var (caddr exp))))) 2. E is of the form (E1 E2) and x occurs bound in E1 or E2 (else (or (occurs-bound? var (car exp)) (occurs-bound? var (cadr exp)))))))

Use helper functions! (define (lambda-exp? exp) (eqv? (car exp?) 'lambda)) (define (lambda-arg exp) (caadr exp)) (define (lambda-body exp) (caddr exp)) (define (app-fun exp) (car exp)) (define (app-arg exp) (cadr exp))

(define occurs-free? (lambda (var exp) (cond 1. E is a variable reference and E = x; or ((symbol? exp) (eqv? var exp)) 2. E is of the form (l (y) E') where y ≠ x and x occurs free in E'; or ((lambda-exp? exp) (and (not (eqv? (lambda-arg exp) var) (occurs-free? var (lambda-body exp)))) 3. E is of the form (E1 E2) and x occurs free in E1 or E2 ((else (or (occurs-free? var (app-fun exp)) (occurs-free? var (app-arg exp)))))))