© Egon Börger: Backtracking ASM 1 Backtracking Machine (for Tree Computations) If mode = ramify then Let k = |alternatives (Params)| Let o 1,..., o k =new.

Slides:



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

Semantics Static semantics Dynamic semantics attribute grammars
Attribute Grammars Prabhaker Mateti ACK: Assembled from many sources.
ICE1341 Programming Languages Spring 2005 Lecture #6 Lecture #6 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Cs7120 (Prasad)L21-DCG1 Definite Clause Grammars
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
CS7100 (Prasad)L16-7AG1 Attribute Grammars Attribute Grammar is a Framework for specifying semantics and enables Modular specification.
ICE1341 Programming Languages Spring 2005 Lecture #5 Lecture #5 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Ch.2: Syntax and Semantics Fall 2005.
1 Introduction to Computability Theory Lecture5: Context Free Languages Prof. Amos Israeli.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Defining practical programming languages Carlos Varela RPI.
Exploiting Abstractions for Specification Reuse Java/C# Case Study Egon Börger in cooperation with R. Stärk, V. Gervasi, G. Fruja Dipartimento di Informatica,
Runtime Environments Source language issues Storage organization
Programming Language Semantics Mooly SagivEran Yahav Schrirber 317Open space html://
Chapter 3 Describing Syntax and Semantics Sections 1-3.
Parsing — Part II (Ambiguity, Top-down parsing, Left-recursion Removal)
Chapter 3 Describing Syntax and Semantics Sections 1-3.
Yu-Chen Kuo1 Chapter 2 A Simple One-Pass Compiler.
Refinement Method for Abstract State Machines Egon Börger Dipartimento di Informatica, Universita di Pisa
CSC 8310 Programming Languages Meeting 2 September 2/3, 2014.
CS784 (Prasad)L167AG1 Attribute Grammars Attribute Grammar is a Framework for specifying semantics and enables Modular specification.
1 Introduction to Parsing Lecture 5. 2 Outline Regular languages revisited Parser overview Context-free grammars (CFG’s) Derivations.
CPSC 388 – Compiler Design and Construction Parsers – Context Free Grammars.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 2.
Client/browser productivity language Ras Bodik, Thibaud Hottelier, James Ide, and Doug Kimelman(IBM)
COP4020 Programming Languages Semantics Prof. Xin Yuan.
Classification of grammars Definition: A grammar G is said to be 1)Right-linear if each production in P is of the form A  xB or A  x where A and B are.
CS 3240: Languages and Computation Context-Free Languages.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
TextBook Concepts of Programming Languages, Robert W. Sebesta, (10th edition), Addison-Wesley Publishing Company CSCI18 - Concepts of Programming languages.
Introduction To PROLOG World view of imperative languages. World view of relational languages. A PROLOG program. Running a PROLOG program. A PROLOG.
PPL Applicative and Normal Form Verification, Type Checking and Inference.
Chapter 3 Part II Describing Syntax and Semantics.
Semantics In Text: Chapter 3.
Language Translation A programming language processor is any system that manipulates programs expressed in a PL A source program in some source language.
Ch. 13 Ch. 131 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (notes?) Dr. Carter Tiernan.
LESSON 04.
A Monadic-Memoized Solution for Left-Recursion Problem of Combinatory Parser Rahmatullah Hafiz Fall, 2005.
Chapter 3 Context-Free Grammars and Parsing. The Parsing Process sequence of tokens syntax tree parser Duties of parser: Determine correct syntax Build.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
Grammars Hopcroft, Motawi, Ullman, Chap 5. Grammars Describes underlying rules (syntax) of programming languages Compilers (parsers) are based on such.
Grammars CS 130: Theory of Computation HMU textbook, Chap 5.
LING/C SC/PSYC 438/538 Lecture 15 Sandiway Fong. Did you install SWI Prolog?
Overview of Previous Lesson(s) Over View 3 Model of a Compiler Front End.
1 Programming Languages (CS 550) Lecture 2 Summary Mini Language Interpreter Jeremy R. Johnson.
07/10/04 AIPP Lecture 5: List Processing1 List Processing Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 5 07/10/04.
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Logic Programming Lecture 2: Unification and proof search.
LECTURE 10 Semantic Analysis. REVIEW So far, we’ve covered the following: Compilation methods: compilation vs. interpretation. The overall compilation.
Run-Time Environments Presented By: Seema Gupta 09MCA102.
Lecture 9 Symbol Table and Attributed Grammars
CSE3302 Programming Languages (notes continued)
Chapter 3 – Describing Syntax
Run-Time Environments Chapter 7
Constructing Precedence Table
CS510 Compiler Lecture 4.
Fall Compiler Principles Context-free Grammars Refresher
Parsing — Part II (Top-down parsing, left-recursion removal)
What does it mean? Notes from Robert Sebesta Programming Languages
Graph-Based Operational Semantics
Mini Language Interpreter Programming Languages (CS 550)
Lecture 7: Introduction to Parsing (Syntax Analysis)
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Languages and Compilers (SProg og Oversættere)
Fall Compiler Principles Context-free Grammars Refresher
Chapter 3 Describing Syntax and Semantics.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
COMPILER CONSTRUCTION
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 2, 09/04/2003 Prof. Roy Levow.
Presentation transcript:

© Egon Börger: Backtracking ASM 1 Backtracking Machine (for Tree Computations) If mode = ramify then Let k = |alternatives (Params)| Let o 1,..., o k =new (NODE) candidates (currnode) := { o 1,..., o k } forall 1  i  k do parent (o i ) := currnode env (o i ) := i-th (alternatives (Params)) mode := select If mode = select then If candidates (currnode) =  then backtrack else try-next-candidate mode := execute curr node o1o1 okok candidates parent curr node o1o1 okok

© Egon Börger: Backtracking ASM 2 Backtracking Machine backtrack  if parent (currnode) = root then mode := Stop else currnode := parent (currnode) try-next-candidate  depth-first tree traversal currnode:= next (candidates(currnode)) delete next (candidates(currnode)) from candidates (currnode) The fctn next is a choice fct, possibly dynamic, which determines the order for trying out the alternatives. The fct alternatives, possibly dynamic and coming with parameters, determines the solution space. The execution machine may update mode again to ramify (in case of successful exec) or to select (for failed exec)

© Egon Börger: Backtracking ASM 3 Backtracking Machine: logic progg instantiation Prolog Börger/Rosenzweig Science of Computer Programming 24 (1995) –alternatives = procdef (act,pgm), yielding a sequence of clauses in pgm, to be tried out in this order to execute the current statement (“goal”) act procdef (act,constr,pgm) in CLAM with constraints for indexing mechanism Börger/Salamone OUP 1995 –next = first-of-sequence (depth-first left-to-right tree traversal) –execute mode resolves act against the head of the next candidate, if possible, replacing act by that clauses’ body & proceeding in mode ramify, otherwise it deletes that candidate & switches to mode select

© Egon Börger: Backtracking ASM 4 Backtracking Machine: functional progg instantiation Babel Börger et al. IFIP 13 World Computer Congress 1994, Vol.I –alternatives = fundef (currexp,pgm), yielding the list of defining rules provided in pgm for the outer fct of currexp –next = first-of-sequence –execute applies the defining rules in the given order to reduce currexp to normal form (using narrowing, a combination of unification and reduction)

© Egon Börger: Backtracking ASM 5 Backtracking Machine : context free grammar instantiation Generating leftmost derivations of cf grammars G –alternatives (currnode,G), yields sequence of symbols Y1...Yk of the conclusion of a G-rule with premisse X labeling currnode. Includes a choice bw different rules X  w –env yields the label of a node: variable X or terminal letter a –next = first-of-sequence ( depth-first left-to-right tree traversal ) –execute mode for nodes labeled by a variable triggers tree expansion for terminal nodes extracts the yield, concatenating terminal word to output, continues derivation at parent node in mode select Initially NODE = {root} root=currnode env(root)=G-axiom mode=ramify alternatives can be a dynamic fct (possibly monitored by the user) or static (with first argument in VAR) If mode = execute then If env (currnode)  VAR then mode:=ramify else output:=output * env(currnode) currnode:= parent(currnode) mode := select

© Egon Börger: Backtracking ASM 6 Backtracking Machine : instantiation for attribute grammars Synthesis of node attribute from children’s attributes via backtrack  if parent (currnode) = root then mode := Stop else currnode := parent (currnode) X.a := f(Y 1.a 1,..., Y k.a k ) where X = env(parent(currnode)), Y i =env(o i ) for children nodes Inheriting attribute from parent and siblings –included in update of env (e.g. upon node creation) generalized to update also node attributes Attribute conditions for grammar rules –included in execute-rules as additional guard to yielding output If mode = execute then... else If Cond(currnode.a, parent(currnode).b, siblings(currnode).c) then output:=output * env(currnode) currnode:= parent(currnode), mode := select Johnson/ Moss Linguistics &Philosophy 17 (1994)

© Egon Börger: Backtracking ASM 7 X m k-thChild X p j-thChild X Tree Adjoining Grammars Generalizing Parikh’s analysis of context free languages by pumping of cf trees from basis trees (with terminal yield) and recursion trees (with terminal yield except for the root variable) If n=k-thChild(m) & symb(n)=symb(root(T)) & T  RecTree & foot(T) = j-thChild(p) Then Let T’=new copy(T) in k-thChild(m):=root(T’) j-thChild(p’):=n m k-thChild X p j-thChild X

© Egon Börger: Backtracking ASM 8 References E.Börger and D. Rosenzweig: Mathematical Definition of Full Prolog –In: Science of Computer Programming 24 (1995) E.Börger and R.F.Salamone: CLAM Specification for Provably Correct Compilation of CLP ( R ) Programs –In: E.Börger (Ed.) Specification and Validation Methods. Oxford University Press, 1995, E.Börger, F.J.Lopez-Fraguas, M.Rodrigues-Artalejo: A Model for Mathematical Analysis of Functional Programs and their Implementations –In: B.Pehrson and I.Simon (Eds.): IFIP 13 World Computer Congress 1994, Vol.I: Technology/Foundations, D. Johnson and L. Moss: Grammar Formalisms Viewed als Evolving Algebras –Linguistics and Philosophy 17 (1994)