The BRENDA interpreter A interpreter for a subset of Dylan written in Dylan.

Slides:



Advertisements
Similar presentations
1 Programming Languages (CS 550) Mini Language Interpreter Jeremy R. Johnson.
Advertisements

1 Scheme and Functional Programming Aaron Bloomfield CS 415 Fall 2005.
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.
Scheme in Scheme?!? …the metacircular evaluator….
1 The metacircular evaluator Names Extend the calculator to store intermediate results as named values (define x (+ 4 5)) store result as x (+ x.
Defining New Special Forms (unless test body) (if (not test) body #f) (when (not test) body)
Metacircular Evaluation SICP Chapter 4 Mark Boady.
Evaluators for Functional Programming Chapter 4 1 Chapter 4 - Evaluators for Functional Programming.
1 Functional programming Languages And a brief introduction to Lisp and Scheme.
1 The Metacircular Evaluator Chapter 4 Section 4.1 We will not cover every little detail in the lectures, so you MUST read Section 4.1 in full.
1 Lecture 18 Continue Evaluator. 2 z9 true#t + twice Representing procedures (eval '(define twice (lambda (x) (+ x x))) GE) symbol primitive scheme procedure.
6.001 SICP SICP – October environment Trevor Darrell 32-D512 Office Hour: W web page:
Environments and Evaluation
Lexical vs. Dynamic Scope …where do I point to?. Intro… Remember in Scheme whenever we call a procedure we pop a frame and point it to where the procedure.
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,
The environment model evaluator and compiler 1 The env model evaluator Motivation In one word: Efficiency Saves repeated renaming and substitution: Using.
1 Saves repeated renaming and substitution: explicit substitution is replaced by variable bindings using new data structures (frame, environment). Can.
1 Programming Languages (CS 550) Lecture 5 Summary Object Oriented Programming and Implementation* Jeremy R. Johnson *Lecture based on notes from SICP.
Scheme in Scheme. Why implement Scheme in Scheme  Implementing a language is aa good way to learn more about programming languages  Interpreters are.
1 The metacircular evaluator (Cont.) Defining new procedures (define (lambda? e) (tag-check e 'lambda)) (define (eval exp env) (cond ((number? exp)
Scheme in Scheme 1. Why implement Scheme in Scheme  Implementing a language is a good way to learn more about programming languages  Interpreters are.
Advanced Programming Collage of Information Technology University of Palestine, Gaza Prepared by: Mahmoud Rafeek Alfarra Lecture 2: Major Concepts of Programming.
Functional Programming Universitatea Politehnica Bucuresti Adina Magda Florea
CS220 Programming Principles 프로그래밍의 이해 2002 가을학기 Class 15: Meta-Circular Evaluator 한 태숙.
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
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 With examples in F#. Pure Functional Programming Functional programming involves evaluating expressions rather than executing commands.
Streams and Lazy Evaluation A signal processing view of computation CD player DA con- verter ampspeakerdigital signal audio signal amplified audio signal.
The environment-based operational semantics Chapter
Algorithms and Programming Functions Lecture 28. Summary of Previous Lecture while statement for statement break statement Nested loops.
8-1 Compilers Compiler A program that translates a high-level language program into machine code High-level languages provide a richer set of instructions.
1 Env. Model Implementation & Analyzer Practice Session #10 Env. Model Implementation & Analyzer Practice Session #10.
1/ SICP Variations on a Scheme Scheme Evaluator – A Grand Tour Making the environment model concrete Defining eval defines the language –Provides.
Interpreters and Higher-Order Functions CSE 413 Autumn 2008 Credit: CSE341 notes by Dan Grossman.
1 Programming Languages (CS 550) Lecture 2 Summary Mini Language Interpreter Jeremy R. Johnson.
Scheme in Scheme 2. What’s next  Adding set!  Dynamic vs. lexical variable scope  Extending mcscheme v1 with libraries  Can mcscheme execute mcscheme?
CS61A Lecture Colleen Lewis. Clicker poll Where do you think you’re learning the most? I assume you’ll learn the most in lab & disc (so.
Artificial Intelligence and Lisp Lecture 6 LiU Course TDDC65 Autumn Semester,
(Thunking about Thunks)
Scheme in Scheme 1.
Operational Semantics of Scheme
Functional Programming
Lecture 4: Metacircles Eval Apply David Evans
6.001 SICP Variations on a Scheme
6.001 SICP Compilation Context: special purpose vs. universal machines
The interpreter.
Env. Model Implementation
Original material by Eric Grimson
Nondeterministic Evaluation
Mini Language Interpreter Programming Languages (CS 550)
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.
Dynamic Scoping Lazy Evaluation
The Metacircular Evaluator
3.4 Local Binding Recall Scheme's let: > (let ((x 5)‏ (y 6))
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
6.001 SICP Variations on a Scheme
(more) Python.
6.001 SICP Interpretation Parts of an interpreter
topics interpreters meta-linguistic abstraction eval and apply
Rehearsal: Lazy Evaluation Infinite Streams in our lazy evaluator
Lecture 25: The Metacircular Evaluator Eval Apply
Presentation transcript:

The BRENDA interpreter A interpreter for a subset of Dylan written in Dylan

What’s the point? Better understanding of how the language works Languages are not magic, just another program! You can change the language (we'll do so in PS6) see the environment model in action similar to the expression evaluator that we did in PS3, but more complex expressions (most of Dylan) You’ll see how garbage collection works

Interpreter “Walks over” a given high-level program and performs actions specified. Simpler, easier to understand and implement Compiler Translates high-level program to another program in the machine's native language (machine code). More efficient

Read-eval-print loop (define read-eval-print-loop (method () (bind ((raw (read)) (result (brenda-eval raw *brenda-global-environment*))) (print "Brenda? " raw) (print "Brenda==> " result) (read-eval-print-loop))))

Brenda-eval (define-generic-function brenda-eval ((obj ) (env ))) (add-method brenda-eval (method ((obj ) (env )) obj)) (add-method brenda-eval (method ((obj ) (env )) (lookup obj env)))

Brenda-eval (cont.) (add-method brenda-eval (method ((obj ) (env )) (brenda-apply (brenda-eval (head obj) env) (tail obj) env))) (define eval-sequence (method ((seq ) (env )) (cond ((null? seq) #f) ((null? (tail seq)) (brenda-eval (head seq) env)) (else: (brenda-eval (head seq) env) (eval-sequence (tail seq) env)))))

Brenda-apply (define-generic-function brenda-apply ((obj ) (args ) (env ))) (add-method brenda-apply (method ((obj ) (args ) (env )) (brenda-error "Apply : First element not a function.” obj)))

Brenda-apply for primitive functions (add-method brenda-apply (method ((obj ) (args ) (env )) (bind (((evaluated-args ) (map (method (x) (brenda-eval x env)) args))) (args-params-match? (params obj) evaluated-args) (apply (calls obj) evaluated-args)))

Brenda-apply for Brenda special forms (add-method brenda-apply (method ((obj ) (args ) (env )) ((calls obj) args env)))

Brenda-apply for user defined methods (add-method brenda-apply (method ((obj ) (args ) (e )) (bind (((evaluated-args ) (map (method (x) (brenda-eval x e)) args))) (args-params-match? (params obj) evaluated-args) (bind ((new-env (expand-environment (params obj) evaluated-args (env obj)))) (eval-sequence (body obj) new-env)))))

Bindings (define-class ( ) (variable ) (value )) (define make-brenda-binding (method ((var ) (val )) (make variable: var value: val)))

Environments (define-class ( )) (define-class ( ) (bindings ) (previous )) (define make-brenda-local-frame (method ((prev )) (make bindings: '() previous: prev)))

Expand an environment p = params a = arguments e = environment (define expand-environment (method ((p ) (a ) (e )) (bind (((e1 ) (make-brenda-local-frame e))) (set! (bindings e1) (map make-brenda-binding (map variable p) a)) e1)))