Catriel Beeri Pls/Winter 2004/5 interpreters 1 Language processors for EL  An interpreter transEval from  An interpreter natEval from An important theme:

Slides:



Advertisements
Similar presentations
Substitution & Evaluation Order cos 441 David Walker.
Advertisements

1 Programming Languages (CS 550) Mini Language Interpreter Jeremy R. Johnson.
Semantics Static semantics Dynamic semantics attribute grammars
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists Dan Grossman Winter 2013.
Exercise 1 Generics and Assignments. Language with Generics and Lots of Type Annotations Simple language with this syntax types:T ::= Int | Bool | T =>
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
Winter 2004/5Pls – expresssion-lang – Catriel Beeri22 Informal Analysis Goal: prove the semantics is deterministic Stages: Values --- we know they have.
Copyright © 2006 Addison-Wesley. All rights reserved. 3.5 Dynamic Semantics Meanings of expressions, statements, and program units Static semantics – type.
Catriel Beeri Pls/Winter 2004/5 last 55 Two comments on let polymorphism I. What is the (time, space) complexity of type reconstruction? In practice –
Algebra Problems… Solutions Algebra Problems… Solutions © 2007 Herbert I. Gross Set 4 By Herb I. Gross and Richard A. Medeiros next.
CS412/413 Introduction to Compilers Radu Rugina Lecture 16: Efficient Translation to Low IR 25 Feb 02.
CPSC Compiler Tutorial 9 Review of Compiler.
Catriel Beeri Pls/Winter 2004/5 functional-language 1 Substitution Semantics of FL – a simple functional language FL is EL + (non-recursive) function creation.
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
Catriel Beeri Pls/Winter 2004/5 type reconstruction 1 Type Reconstruction & Parametric Polymorphism  Introduction  Unification and type reconstruction.
Algorithm Design Techniques: Induction Chapter 5 (Except Section 5.6)
Winter 2004/5Pls – inductive – Catriel Beeri1 Inductive Definitions (our meta-language for specifications)  Examples  Syntax  Semantics  Proof Trees.
Prof. Bodik CS 164 Lecture 61 Building a Parser II CS164 3:30-5:00 TT 10 Evans.
1 Regular Grammars Generate Regular Languages. 2 Theorem Regular grammars generate exactly the class of regular languages: If is a regular grammar then.
Catriel Beeri Pls/Winter 2004/5 environment 68  Some details of implementation As part of / extension of type-checking: Each declaration d(x) associated.
Catriel Beeri Pls/Winter 2004/5 inductive-revisited 1 Inductive definitions revisited  Generated and Freely generated sets oPattern match, unification.
Catriel Beeri Pls/Winter 2004/05 types 65  A type-checking algorithm The task: (since we start with empty H, why is the goal not just E?) The rule set.
Parsing — Part II (Ambiguity, Top-down parsing, Left-recursion Removal)
Catriel Beeri Pls/Winter 2004/5 environment1 1 The Environment Model  Introduction and overview  A look at the execution model  Dynamic scoping  Static.
Winter 2004/5Pls – analysis – Catriel Beeri1 A precise analysis  Determinism, soundness, completeness for  Determinism for  Additional properties of.
Lesson 6. Refinement of the Operator Model This page describes formally how we refine Figure 2.5 into a more detailed model so that we can connect it.
Computer vision: models, learning and inference Chapter 10 Graphical Models.
Regular Expressions and Automata Chapter 2. Regular Expressions Standard notation for characterizing text sequences Used in all kinds of text processing.
Winter 2003/4Pls – syntax – Catriel Beeri1 SYNTAX Syntax: form, structure The syntax of a pl: The set of its well-formed programs The rules that define.
Catriel Beeri Pls/Winter 2004/5 environment 19 II. Frames and frame structures Frame – set of bindings generated together in a binding generation event.
RECURSIVE PATTERNS WRITE A START VALUE… THEN WRITE THE PATTERN USING THE WORDS NOW AND NEXT: NEXT = NOW _________.
Fundamentals of Python: From First Programs Through Data Structures
Symbol Table (  ) Contents Map identifiers to the symbol with relevant information about the identifier All information is derived from syntax tree -
DEDUCTIVE DATABASE.
Chapter 4 Context-Free Languages Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1.
Empirical Explorations with The Logical Theory Machine: A Case Study in Heuristics by Allen Newell, J. C. Shaw, & H. A. Simon by Allen Newell, J. C. Shaw,
Introduction to Parsing Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University.
CSE 219 Computer Science III Program Design Principles.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 3, 09/11/2003 Prof. Roy Levow.
Patterns and Sequences
Functional Programming With examples in F#. Pure Functional Programming Functional programming involves evaluating expressions rather than executing commands.
1 Relational Algebra and Calculas Chapter 4, Part A.
Regular Expressions Chapter 6 1. Regular Languages Regular Language Regular Expression Finite State Machine L Accepts 2.
PPL Applicative and Normal Form Verification, Type Checking and Inference.
3.2 Semantics. 2 Semantics Attribute Grammars The Meanings of Programs: Semantics Sebesta Chapter 3.
Ch. 13 Ch. 131 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (notes?) Dr. Carter Tiernan.
CS212: Object Oriented Analysis and Design
1 / 48 Formal a Language Theory and Describing Semantics Principles of Programming Languages 4.
CS 103 Discrete Structures Lecture 13 Induction and Recursion (1)
Regular Expressions Chapter 6. Regular Languages Regular Language Regular Expression Finite State Machine L Accepts.
1/33 Basic Scheme February 8, 2007 Compound expressions Rules of evaluation Creating procedures by capturing common patterns.
Type Systems CSE 340 – Principles of Programming Languages Fall 2015 Adam Doupé Arizona State University
CS412/413 Introduction to Compilers Radu Rugina Lecture 13 : Static Semantics 18 Feb 02.
1 Programming Languages (CS 550) Lecture 2 Summary Mini Language Interpreter Jeremy R. Johnson.
Exercises on Chomsky Normal Form and CYK parsing
© Kenneth C. Louden, Chapter 7 - Control I: Expressions and Statements Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
Arithmetic Recursive and Explicit formulas I can write explicit and recursive formulas given a sequence. Day 2.
COMP 412, FALL Type Systems C OMP 412 Rice University Houston, Texas Fall 2000 Copyright 2000, Robert Cartwright, all rights reserved. Students.
Introduction to Parsing
Theory of Computational Complexity Probability and Computing Chapter Hikaru Inada Iwama and Ito lab M1.
Names and Attributes Names are a key programming language feature
Syntax Specification and Analysis
September 4, 1997 Programming Languages (CS 550) Lecture 6 Summary Operational Semantics of Scheme using Substitution Jeremy R. Johnson TexPoint fonts.
Propositional Calculus: Boolean Algebra and Simplification
R.Rajkumar Asst.Professor CSE
Problem Solving Skill Area 305.1
Programming Techniques
Chapter 6 Network Flow Models.
COMPILER CONSTRUCTION
Presentation transcript:

Catriel Beeri Pls/Winter 2004/5 interpreters 1 Language processors for EL  An interpreter transEval from  An interpreter natEval from An important theme: deriving interpreters directly from the rules

Catriel Beeri Pls/Winter 2004/5 interpreters 2  Deriving an interpreter from We derive: next (a stepper) for each E, next(E) = E’, where E -- the goal, E’ -- the solution A full interpreter: transEval -- drives next until final (extended) value is obtained

Catriel Beeri Pls/Winter 2004/5 interpreters 3 How does next work: Check on goal E the conditions of previous chapter, determine the applicable group of rules An axiom group: –Check more conditions –Apply unique applicable axiom A proper rule group: –Determine E st step down on selection path –Call (recursively) next(E1) –Given its solution E’1, construct the solution E’ Note: E=E0, E1, … En -- the goals of the calls – the selection path E0  E’0, … En  E’n -- the labels of the proof tree (virtual construction)

Catriel Beeri Pls/Winter 2004/5 interpreters 4

Catriel Beeri Pls/Winter 2004/5 interpreters 5 Examples: /0 2 4 (2 * 3) + 4 (2 3) + 4

Catriel Beeri Pls/Winter 2004/5 interpreters 6 Example tuple i = 1 Apply-op (3,5) * app-rand: applic A non-value applic next((3+5,4-5)) next(3+5) builtIn(+, (3,5)) 8 8 (8,4-5) A value

Catriel Beeri Pls/Winter 2004/5 interpreters 7 In what sense is next “derived from the rules? How much is routine derivation/ human analysis ? 1. find applicable rules for E: Primary construct C of E selects rules --- how? compare C to primary construct is each rule’s head left part – rule head goal pattern (why pattern?) applic

Catriel Beeri Pls/Winter 2004/5 interpreters 8 2. check conditions, narrow set of applicable rules: need to associate direct sub-expressions with variables in the goal patterns --- why & how? Convenience: make the conditions explicit in the rules Variable assignment identifies which sub-expressions are to be checked 2 nd condition fails  rule is disqualified applic

Catriel Beeri Pls/Winter 2004/5 interpreters 9 3. proper rule --- generate new goal: The binding of direct sub-expressions to variables instantiates the rule’s transition premise goal The call next((3+5,4-2)) is generated applic

Catriel Beeri Pls/Winter 2004/5 interpreters recursive call returns --- generate solution: The binding is extended by the recursive solution, instantiate the rules’s head solution pattern The call next((3+5,4-2)) is generated It returns (8,4-2), which is bound to Now the solution is returned applic

Catriel Beeri Pls/Winter 2004/5 interpreters 11 Summary: Pattern match of E with goal patterns of rules –excludes some rules –For a remaining rule, binds variables in its goal pattern to E’s direct sub-expressions Binding  check conditions  more rules excluded If remaining rule is an axiom, solution is generated If a proper rule, –Binding used to generate a recursive call –Its solution extends the variable assignment –Binding for head solution pattern is now full, solution is generated

Catriel Beeri Pls/Winter 2004/5 interpreters 12 Comments: Actually, after checking, several rules remain –Either all proper, or all axioms –when proper, all generates same new goal (we are lucky!) When a recursive call returns ER, the data flow described above is short-circuited – how? Our description of derivation from the rules is complete but there is still one bothersome detail

Catriel Beeri Pls/Winter 2004/5 interpreters 13 Look at the first clause

Catriel Beeri Pls/Winter 2004/5 interpreters 14 The condition is not written in the rule! Here, human analysis was used What would be the algorithm if only the conditions in the rules were used? discussion An advantage of deriving from the rules: the rules are a declarative specification of the algorithm Can we change the rules so human analysis is not required for the derivation?

Catriel Beeri Pls/Winter 2004/5 interpreters 15 An algorithmic version of the rules (apply-op-a) (applic-rator-a) (applic-rand-a) (tup-eval) ……. If + errors rules are left to you (make the conditions explicit)

Catriel Beeri Pls/Winter 2004/5 interpreters 16  Deriving natEval from accepts goal E, returns its (extended) value – the solution Same principles, some differences: Rules have several evaluation premises  several recursive calls per rule When binding for the head goal allows several new goals, the order of calls is arbitrary (but select order to check conditions as early as possible!) When several rules are potentially applicable, a new goal common to all is generated first

Catriel Beeri Pls/Winter 2004/5 interpreters 17

Catriel Beeri Pls/Winter 2004/5 interpreters 18 Which of transEval, natEval is simpler to write, more efficient? How can we improve, by eliminating some of the analysis/recursive calls?