First Class Traversal Idioms with Nested Attribute Grammars

Size: px
Start display at page:

Download "First Class Traversal Idioms with Nested Attribute Grammars"

Transcription

1 First Class Traversal Idioms with Nested Attribute Grammars Arie Middelkoop Dept. of Information and Computing Sciences, Utrecht University P.O. Box , 3508 TB Utrecht, The Netherlands Web pages: 15 April 2010 & Software Technology Colloquium

2 Introduction 2

3 Main Question Software component for name analysis? 3

4 Main Question Software component for name analysis? Why? Pattern that occurs often in compilers Software engineering practice (e.g. elimination of code duplication) 3

5 Main Question Software component for name analysis? Why? Pattern that occurs often in compilers Software engineering practice (e.g. elimination of code duplication) Actual question: mechanism for any traversal idiom? More intriguing idiom: damas-milner inference 3

6 4

7 Warning! Work in progress! Controversial/not a silver bullet. I hope this talk leads to: 5 References to related material Improvements to the concepts Improvements to understanding and explanation Ideas for a nicer implementation

8 Related Work This talk is related to attribute grammars: Higher-order Attribute Grammars Remote Attributes / Reference Attributes... and probably many other formalisms/technologies 6

9 Background 7

10 Name Analysis Concrete syntax: let x = 1 f = λx.x in f x Abstract syntax: Let [Decl "x" (Val 1), Decl "f" (Lam "x" (Var "x"))] (App (Var "f") (Var "x"))) Questions: 8 All identifiers defined? No duplicate definitions? What is the type of an identifier?

11 Name Analysis applied - gather environment let app x = f x val f = nil λx x 9

12 Name Analysis applied - gather environment let app x = (x, τ 1 ) f x val f = nil λx x 9

13 Name Analysis applied - gather environment let app x = (x, τ 1 ) f x val f = nil λx x 9

14 Name Analysis applied - gather environment let app x = (x, τ 1 ) f x val f = nil λx (x, τ 2 ) x 9

15 Name Analysis applied - gather environment let app x = (x, τ 1 ) f x val f = (f, τ 3 ) nil λx (x, τ 2 ) x 9

16 Name Analysis applied - gather environment let app x = (x, τ 1 ) (f, τ 3 ) f x val f = (f, τ 3 ) nil λx (x, τ 2 ) x 9

17 Name Analysis applied - gather environment let (x, τ 1 ) (f, τ 3 ) app x = (x, τ 1 ) (f, τ 3 ) f x val f = (f, τ 3 ) nil λx (x, τ 2 ) x 9

18 Name Analysis applied - gather environment let (x, τ 1) (f, τ 3 ) (x, τ 1 ) (f, τ 3 ) app x = (x, τ 1 ) (f, τ 3 ) f x val f = (f, τ 3 ) nil λx (x, τ 2 ) x 9

19 Name Analysis applied - distribute environment let (x, τ 1) (f, τ 3 ) app x = f x val f = nil λx (x, τ 2 ) x 10

20 Name Analysis applied - distribute environment let (x, τ 1) (f, τ 3 ) (x, τ 1 ) (f, τ 3 ) app x = f x val f = nil λx (x, τ 2 ) x 10

21 Name Analysis applied - distribute environment let (x, τ 1) (f, τ 3 ) (x, τ 1 ) (f, τ 3 ) app x = f x val f = nil (x, τ 1 ) (f, τ 3 ) λx (x, τ 2 ) (x, τ 2 ) (f, τ 3 ) x 10

22 Name Analysis applied - distribute environment let (x, τ 1) (f, τ 3 ) (x, τ 1 ) (f, τ 3 ) (x, τ 1 ) (f, τ 3 ) app x = (x, τ 1 ) (f, τ 3 ) f x val f = nil (x, τ 1 ) (f, τ 3 ) λx (x, τ 2 ) (x, τ 2 ) (f, τ 3 ) x 10

23 Name Analysis applied - distribute environment let (x, τ 1) (f, τ 3 ) (x, τ 1 ) (f, τ 3 ) (x, τ 1 ) (f, τ 3 ) app x = (x, τ 1 ) (f, τ 3 ) f x val f = nil (x, τ 1 ) (f, τ 3 ) λx (x, τ 2 ) (x, τ 2 ) (f, τ 3 ) x 10

24 Name Analysis applied - distribute environment let (x, τ 1) (f, τ 3 ) (x, τ 1 ) (f, τ 3 ) (x, τ 1 ) (f, τ 3 ) app x = f = (x, τ 1 ) (f, τ 3 ) f x val f = nil (x, τ 1 ) (f, τ 3 ) λx (x, τ 2 ) (x, τ 2 ) (f, τ 3 ) x 10

25 Implementation - parser pexpr :: Parser Token T Expr pexpr = sem Expr Let $ pkey "let" pdecls pkey "in" pexpr sem Expr Lam $ pkey "\\" pident pkey "." pexpr pexprapps pexprapps = pchainl sem Expr App pexprbase pexprbase = sem Expr Var $ pident sem Expr Val $ pvalue pparens pexpr pdecls = pfoldr (sem Decls Cons, sem Decls Nil) pdecl pdecl = sem Decl Decl $ pident pkey "=" pexpr 11

26 Implementation - tructors (1) sem Expr Var nm = sem :: Expr... sem Expr Val val = sem :: Expr... sem Expr App l r = sem :: Expr... sem Expr Lam nm b = sem :: Expr... sem Expr Let ds b = sem :: Expr... sem Decls Cons d ds = sem :: Decls... sem Decls Nil = sem :: Decls... sem Decl Decl nm e = sem :: Decl... 12

27 Implementation - tructors (1) sem Expr Var nm = sem :: Expr... sem Expr Val val = sem :: Expr... sem Expr App l r = sem :: Expr... sem Expr Lam nm b = sem :: Expr... sem Expr Let ds b = sem :: Expr... sem Decls Cons d ds = sem :: Decls... sem Decls Nil = sem :: Decls... sem Decl Decl nm e = sem :: Decl... sem Expr Lam :: String T Expr T Expr sem Expr Let :: T Decls T Expr T Expr 12

28 Implementation - interfaces itf Expr Decls Decl visit gather syn gathenv :: [(String, Ty)] visit distribute inh finenv :: [(String, Ty)] syn errors :: [String ] order gather < distribute 13

29 Implementation - interfaces itf Expr Decls Decl visit gather syn gathenv :: [(String, Ty)] visit distribute inh finenv :: [(String, Ty)] syn errors :: [String ] order gather < distribute newtype T Expr st =... data Inh Expr = Inh Expr {finenv Inh Expr :: [(String, Ty)]} data Syn Expr = Syn Expr {gathenv Syn Expr :: [(String, Ty)], errors Syn Expr :: [String ] } eval Expr :: (forall st.t Expr st) Inh Expr Syn Expr 13

30 Implementation - Constructors (2) sem Expr Var nm = sem :: Expr loc.mbval = lookup nm lhs.finenv lhs.errors = maybe ["missing: " + nm ] (t [ ]) loc.mbval lhs.gathenv = 14

31 Implementation - Constructors (2) sem Expr Var nm = sem :: Expr loc.mbval = lookup nm lhs.finenv lhs.errors = maybe ["missing: " + nm ] (t [ ]) loc.mbval lhs.gathenv = sem Expr Lam nm b = sem :: Expr child body :: Expr = b loc.(envwith, envwithout) = partition (( nm).fst) lhs.finenv loc.duperrs = if length loc.envwith > 1 then ["dup: " + nm ] lhs.errors = loc.duperrs + body.errors loc.binding = [(nm, loc.argtype)] body.finenv = loc.binding + loc.envwithout lhs.gathenv = filter (( nm).fst) body.gathenv 14

32 Implementation - Constructors (2) sem Expr App l r = sem :: Expr child left :: Expr = l child right :: Expr = r left.finenv = lhs.finenv right.finenv = lhs.finenv lhs.gathenv = left.gathenv + right.gathenv lhs.errors = left.errors + right.errors 15

33 Implementation - Constructors (2) sem Expr App l r = sem :: Expr child left :: Expr = l child right :: Expr = r left.finenv = lhs.finenv right.finenv = lhs.finenv lhs.gathenv = left.gathenv + right.gathenv lhs.errors = left.errors + right.errors Other cases: similar... 15

34 Name Analysis in UHC EH AST has 39 tructors that deal with names Core AST about 16 tructors Lost the count in the HS AST Many more ASTs in UHC... think of all other compilers Code duplication! 16

35 Components 17

36 Towards Attributed Trees as Components (1) visit gather syn gathenv let visit distribute inh finenv syn errs Expr decl Decls val 18

37 Towards Attributed Trees as Components (1) node visit gather syn gathenv let visit distribute inh finenv syn errs Expr decl Decls val 18

38 Towards Attributed Trees as Components (1) node sem :: RealTree loc.c =... child comp :: Comp = loc.c comp.finenv = [ ] visit gather syn gathenv let visit distribute inh finenv syn errs Expr decl Decls val 18

39 Show stoppers 1. Verbose AST Expressions, declarations: too fine grained Essence of name analysis: binding sites, use sites, scoping 2. Interfacing only with root insufficient Access to the values found for identifiers Access to the error messages at one particular node 3. Extend a component? Mismatch between offered and needed functionality Opening up the component, without affecting the original Overriding attributes, adding new attributes 4. Intuitiveness and predictability of code? Delegation of work: finished when results are needed? Functional code (side effect free/order independent) 19

40 More abstract AST 20

41 Coarser AST let app x = f x val f = nil λx 21 x

42 Coarser AST sc let split split app split x = def x split use f f use x val f = def f nil sc λx split 21 x def x use x

43 Coarser AST sc split def x use x 22

44 More Abstract Code 23 itf Name α visit gather syn gathenv use { +} {[ ]} :: [(String, α)] visit distribute inh finenv :: [(String, α)] syn errors use { +} {[ ]} :: [String ] sem Name Scope b = sem :: Name α child body :: Name α = b body.finenv = (lhs.finenv \\ (map fst body.gathenv)) + body.gathenv sem Name Split l r = sem :: Name α child left :: Name α = l child right :: Name α = r sem Name Def x v = sem :: Name α lhs.gathenv = [(x, v)] lhs.errors = if length (filter (( x).fst) lhs.finenv) > 1 then ["dup: " + x ] else [ ] sem Name Use x = sem :: Name α loc.mbval = lookup x lhs.finenv lhs.errors = if isnothing loc.mbval then ["missing: " + x ] else [ ] loc.val = maybe id loc.mbval -- how to access this??

45 Instantiation of the component itf Expr syn nmtree :: T Name st Ty sem Expr Lam x b = sem :: Expr child body :: Expr = b loc.τ =... lhs.nmtree = sem Name Scope $ sem Name Split (sem Name Def x loc.τ) $ body.nmtree sem Expr Var x = sem :: Expr lhs.nmtree = sem Name Use x sem Root Root b = sem :: Root child body :: Expr = b child name :: Name Ty = body.nmtree lhs.errors = name.errors 24

46 Interface to Subtrees 25

47 Towards Attributed Trees as Components (2) itf Name visit gather syn gathenv visit distribute inh finenv sc split itf NameDef visit supply syn nm syn value visit outcome inh errors def x use x itf NameUse visit supply syn nm visit outcome inh value inh errors 26

48 Instantiation and Exchange root app sc split var use 27

49 Instantiation and Exchange root app sc var value, errors nm use split 27

50 Nested AG Code itf NameUse α visit supply syn nm :: String visit outcome inh value :: α inh errors :: [String ] sem Name Use exttree = sem :: Name α child ext :: NameUse α = exttree loc.mbval = lookup ext.nm lhs.finenv ext.value = maybe id loc.mbval ext.errors = if isnothing loc.mbval then ["missing: " + ext.nm ] sem Expr Var nm = sem :: Expr lhs.nmtree = sem Name Use $ sem :: NameUse Type -- nested sem lhs.nm = nm loc.errors = lhs.errors loc.value = lhs.value... = loc.errors -- local attributes... = loc.value -- shared with nested sem 28

51 Referentially transparent? Unable to guarantee that nested sem is executed exactly once We can guarantee referential transparency Requirement: code is orderable Then: an expression for an attribute can be replaced with its value, without affecting the program Referential transparency is important! 29

52 Component Extensions Extend via extra filter nodes 30

53 Example: let-bound polymorphism sc split body decls 31

54 Example: let-bound polymorphism let sc split body decls 31

55 Example: let-bound polymorphism let sc split body decls 31

56 Example: let-bound polymorphism - code 32 sem Expr Let ds b = sem :: Expr lhs.nmtree = loc.semtop $ sem Name Scope $ sem Name Split decls.nmtree $ loc.sembody body.nmtree loc.semtop t = sem :: Name Ty child body :: Name Ty = t loc.parentenv = lhs.finenv loc.sembody t = sem :: Name Ty child body :: Name Ty = t body.finenv = generalize lhs.finenv loc.parentenv

57 AG convenience Override one or two attributes with filter nodes Copy rules take care of the rest 33

58 Limitations 34

59 Order Analysis 35

60 Interfaces and Dependencies finenv :: Env Name: gather distribute gathenv :: Env nmtree.nameuse Main: name supply outcome type nmtree :: T Name st Ty τ :: Ty 36

61 Conclusions 37

62 Type Check Idiom name gen gen main gen type + sig gen kind extends gen type type+kind extends 38

63 Discussion performance views idioms generics proofs functional backend examples UUAG tradeoffs validation usability 39

64 Conclusion Traversal components: Produce an attributed tree Interface with nodes of this attributed tree Extend functionality with filter nodes 40

Operational Semantics Using the Partiality Monad

Operational Semantics Using the Partiality Monad page.1 Operational Semantics Using the Partiality Monad Nils Anders Danielsson (Göteborg) Shonan Meeting 026: Coinduction for computation structures and programming languages The research leading to these

More information

Compiling Techniques

Compiling Techniques Lecture 7: Abstract Syntax 13 October 2015 Table of contents Syntax Tree 1 Syntax Tree Semantic Actions Examples Abstract Grammar 2 Internal Representation AST Builder 3 Visitor Processing Semantic Actions

More information

Nunchaku: Flexible Model Finding for Higher-Order Logic

Nunchaku: Flexible Model Finding for Higher-Order Logic Nunchaku: Flexible Model Finding for Higher-Order Logic Simon Cruanes, Jasmin Blanchette, Andrew Reynolds Veridis, Inria Nancy https://cedeela.fr/~simon/ April 7th, 2016 1 / 21 Summary Introduction Nunchaku

More information

CSCI 490 problem set 6

CSCI 490 problem set 6 CSCI 490 problem set 6 Due Tuesday, March 1 Revision 1: compiled Tuesday 23 rd February, 2016 at 21:21 Rubric For full credit, your solutions should demonstrate a proficient understanding of the following

More information

Syntax Directed Transla1on

Syntax Directed Transla1on Syntax Directed Transla1on Syntax Directed Transla1on CMPT 379: Compilers Instructor: Anoop Sarkar anoopsarkar.github.io/compilers-class Syntax directed Translation Models for translation from parse trees

More information

Abstracting Definitional Interpreters. David Van Horn

Abstracting Definitional Interpreters. David Van Horn Abstracting Definitional Interpreters David Van Horn Abstracting Definitional Interpreters David Van Horn Northeastern University Definitional interpreters written in monadic style can express a wide variety

More information

Static Program Analysis

Static Program Analysis Static Program Analysis Xiangyu Zhang The slides are compiled from Alex Aiken s Michael D. Ernst s Sorin Lerner s A Scary Outline Type-based analysis Data-flow analysis Abstract interpretation Theorem

More information

6.001 Recitation 22: Streams

6.001 Recitation 22: Streams 6.001 Recitation 22: Streams RI: Gerald Dalley, dalleyg@mit.edu, 4 May 2007 http://people.csail.mit.edu/dalleyg/6.001/sp2007/ The three chief virtues of a programmer are: Laziness, Impatience and Hubris

More information

COP-5555 PROGRAMMING LANGUAGEPRINCIPLES NOTES ON THE MECHANICAL EVALUATION OF APPLICATIVE EXPRESSSIONS

COP-5555 PROGRAMMING LANGUAGEPRINCIPLES NOTES ON THE MECHANICAL EVALUATION OF APPLICATIVE EXPRESSSIONS COP-5555 PROGRAMMING LANGUAGEPRINCIPLES NOTES ON THE MECHANICAL EVALUATION OF APPLICATIVE EXPRESSSIONS The substitution mechanism for evaluating applicative expressions is convenient for humans, but inconvenient

More information

A Simple Implementation Technique for Priority Search Queues

A Simple Implementation Technique for Priority Search Queues A Simple Implementation Technique for Priority Search Queues RALF HINZE Institute of Information and Computing Sciences Utrecht University Email: ralf@cs.uu.nl Homepage: http://www.cs.uu.nl/~ralf/ April,

More information

Functional Big-step Semantics

Functional Big-step Semantics Functional Big-step Semantics FM talk, 11 Mar 2015 Magnus Myréen Books Big-step semantics are defined as inductively defined relation. Functions are better! me Context: CakeML verified compiler Old compiler:

More information

CMSC 330: Organization of Programming Languages. Pushdown Automata Parsing

CMSC 330: Organization of Programming Languages. Pushdown Automata Parsing CMSC 330: Organization of Programming Languages Pushdown Automata Parsing Chomsky Hierarchy Categorization of various languages and grammars Each is strictly more restrictive than the previous First described

More information

Compilers. Lexical analysis. Yannis Smaragdakis, U. Athens (original slides by Sam

Compilers. Lexical analysis. Yannis Smaragdakis, U. Athens (original slides by Sam Compilers Lecture 3 Lexical analysis Yannis Smaragdakis, U. Athens (original slides by Sam Guyer@Tufts) Big picture Source code Front End IR Back End Machine code Errors Front end responsibilities Check

More information

(Type) Constraints. Solving constraints Type inference

(Type) Constraints. Solving constraints Type inference A (quick) tour of ML F (Graphic) Types (Type) Constraints Solving constraints Type inference Type Soundness A Fully Graphical Presentation of ML F Didier Rémy & Boris Yakobowski Didier Le Botlan INRIA

More information

The Lifting Lemma. Ralf Hinze

The Lifting Lemma. Ralf Hinze The Lifting Lemma Ralf Hinze Computing Laboratory, University of Oxford Wolfson Building, Parks Road, Oxford, OX1 3QD, England ralf.hinze@comlab.ox.ac.uk http://www.comlab.ox.ac.uk/ralf.hinze/ June 2009

More information

EDA045F: Program Analysis LECTURE 10: TYPES 1. Christoph Reichenbach

EDA045F: Program Analysis LECTURE 10: TYPES 1. Christoph Reichenbach EDA045F: Program Analysis LECTURE 10: TYPES 1 Christoph Reichenbach In the last lecture... Performance Counters Challenges in Dynamic Performance Analysis Taint Analysis Binary Instrumentation 2 / 44 Types

More information

Type Systems. Lecture 2 Oct. 27th, 2004 Sebastian Maneth.

Type Systems. Lecture 2 Oct. 27th, 2004 Sebastian Maneth. Type Systems Lecture 2 Oct. 27th, 2004 Sebastian Maneth http://lampwww.epfl.ch/teaching/typesystems/2004 Today 1. What is the Lambda Calculus? 2. Its Syntax and Semantics 3. Church Booleans and Church

More information

Syntax Analysis Part III

Syntax Analysis Part III Syntax Analysis Part III Chapter 4: Top-Down Parsing Slides adapted from : Robert van Engelen, Florida State University Eliminating Ambiguity stmt if expr then stmt if expr then stmt else stmt other The

More information

A Principled approach to Ornamentation in ML

A Principled approach to Ornamentation in ML 0 0 A Principled approach to Ornamentation in ML THOMAS WILLIAMS, Inria DIDIER RÉMY, Inria Ornaments are a way to describe changes in datatype definitions reorganizing, adding, or dropping some pieces

More information

Local computation of β-reduction A concrete presentation of Game Semantics

Local computation of β-reduction A concrete presentation of Game Semantics 1 2 3 4 Local computation of β-reduction A concrete presentation of Game Semantics William Blum and C.H. Luke Ong Oxford University Computing Laboratory 5 6 Abstract We show that... Key words: Lambda calculus,

More information

On the Semantics of Parsing Actions

On the Semantics of Parsing Actions On the Semantics of Parsing Actions Hayo Thielecke School of Computer Science University of Birmingham Birmingham B15 2TT, United Kingdom Abstract Parsers, whether constructed by hand or automatically

More information

Lecture Notes on Data Abstraction

Lecture Notes on Data Abstraction Lecture Notes on Data Abstraction 15-814: Types and Programming Languages Frank Pfenning Lecture 14 October 23, 2018 1 Introduction Since we have moved from the pure λ-calculus to functional programming

More information

Boolean Expression Checkers

Boolean Expression Checkers Boolean Expression Checkers Tobias Nipkow May 27, 2015 Abstract This entry provides executable checkers for the following properties of boolean expressions: satisfiability, tautology and equivalence. Internally,

More information

Structure. Background. them to their higher order equivalents. functionals in Standard ML source code and converts

Structure. Background. them to their higher order equivalents. functionals in Standard ML source code and converts Introduction 3 Background functionals factor out common behaviour map applies a function to every element of a list fun map [ ] = [ ] map f ( x : : xs ) = f x : : map f xs filter keeps only those elements

More information

3.2 Reduction 29. Truth. The constructor just forms the unit element,. Since there is no destructor, there is no reduction rule.

3.2 Reduction 29. Truth. The constructor just forms the unit element,. Since there is no destructor, there is no reduction rule. 32 Reduction 29 32 Reduction In the preceding section, we have introduced the assignment of proof terms to natural deductions If proofs are programs then we need to explain how proofs are to be executed,

More information

Syntax Analysis Part I

Syntax Analysis Part I 1 Syntax Analysis Part I Chapter 4 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2007-2013 2 Position of a Parser in the Compiler Model Source Program Lexical Analyzer

More information

Syntax Analysis Part I

Syntax Analysis Part I 1 Syntax Analysis Part I Chapter 4 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2007-2013 2 Position of a Parser in the Compiler Model Source Program Lexical Analyzer

More information

Safety Analysis versus Type Inference

Safety Analysis versus Type Inference Information and Computation, 118(1):128 141, 1995. Safety Analysis versus Type Inference Jens Palsberg palsberg@daimi.aau.dk Michael I. Schwartzbach mis@daimi.aau.dk Computer Science Department, Aarhus

More information

Minimally Strict Polymorphic Functions

Minimally Strict Polymorphic Functions Minimally Strict Polymorphic Functions Jan Christiansen Christian-Albrechts-Universität Kiel Institut für Informatik 24098 Kiel, Germany jac@informatik.uni-kiel.de Daniel Seidel Rheinische Friedrich-Wilhelms-Universität

More information

Subtyping and Intersection Types Revisited

Subtyping and Intersection Types Revisited Subtyping and Intersection Types Revisited Frank Pfenning Carnegie Mellon University International Conference on Functional Programming (ICFP 07) Freiburg, Germany, October 1-3, 2007 Joint work with Rowan

More information

Type Inference. For the Simply-Typed Lambda Calculus. Peter Thiemann, Manuel Geffken. Albert-Ludwigs-Universität Freiburg. University of Freiburg

Type Inference. For the Simply-Typed Lambda Calculus. Peter Thiemann, Manuel Geffken. Albert-Ludwigs-Universität Freiburg. University of Freiburg Type Inference For the Simply-Typed Lambda Calculus Albert-Ludwigs-Universität Freiburg Peter Thiemann, Manuel Geffken University of Freiburg 24. Januar 2013 Outline 1 Introduction 2 Applied Lambda Calculus

More information

Notes on Inductive Sets and Induction

Notes on Inductive Sets and Induction Notes on Inductive Sets and Induction Finite Automata Theory and Formal Languages TMV027/DIT21 Ana Bove, March 15th 2018 Contents 1 Induction over the Natural Numbers 2 1.1 Mathematical (Simple) Induction........................

More information

Administrivia. Test I during class on 10 March. Bottom-Up Parsing. Lecture An Introductory Example

Administrivia. Test I during class on 10 March. Bottom-Up Parsing. Lecture An Introductory Example Administrivia Test I during class on 10 March. Bottom-Up Parsing Lecture 11-12 From slides by G. Necula & R. Bodik) 2/20/08 Prof. Hilfinger CS14 Lecture 11 1 2/20/08 Prof. Hilfinger CS14 Lecture 11 2 Bottom-Up

More information

Principles of Program Analysis: Control Flow Analysis

Principles of Program Analysis: Control Flow Analysis Principles of Program Analysis: Control Flow Analysis Transparencies based on Chapter 3 of the book: Flemming Nielson, Hanne Riis Nielson and Chris Hankin: Principles of Program Analysis. Springer Verlag

More information

CS 6112 (Fall 2011) Foundations of Concurrency

CS 6112 (Fall 2011) Foundations of Concurrency CS 6112 (Fall 2011) Foundations of Concurrency 29 November 2011 Scribe: Jean-Baptiste Jeannin 1 Readings The readings for today were: Eventually Consistent Transactions, by Sebastian Burckhardt, Manuel

More information

From Operational Semantics to Abstract Machines

From Operational Semantics to Abstract Machines From Operational Semantics to Abstract Machines John Hannan Department of Computer Science, University of Copenhagen, Universitetsparken 1, DK-2100 Copenhagen East, Denmark. hannan@diku.dk Dale Miller

More information

Business Process Management

Business Process Management Business Process Management Theory: The Pi-Calculus Frank Puhlmann Business Process Technology Group Hasso Plattner Institut Potsdam, Germany 1 What happens here? We discuss the application of a general

More information

CFLs and Regular Languages. CFLs and Regular Languages. CFLs and Regular Languages. Will show that all Regular Languages are CFLs. Union.

CFLs and Regular Languages. CFLs and Regular Languages. CFLs and Regular Languages. Will show that all Regular Languages are CFLs. Union. We can show that every RL is also a CFL Since a regular grammar is certainly context free. We can also show by only using Regular Expressions and Context Free Grammars That is what we will do in this half.

More information

Semantic Solutions to Program Analysis Problems

Semantic Solutions to Program Analysis Problems Semantic Solutions to Program Analysis Problems Sam Tobin-Hochstadt and David Van Horn PLDI FIT 2011 A talk in three parts. 1. A provocative claim. (The thought) 2. A idea about modular program analysis.

More information

Outline. A recursive function follows the structure of inductively-defined data.

Outline. A recursive function follows the structure of inductively-defined data. Outline A recursive function follows the structure of inductively-defined data. With lists as our example, we shall study 1. inductive definitions (to specify data) 2. recursive functions (to process data)

More information

Why walk when you can take the tube?

Why walk when you can take the tube? Under consideration for publication in J. Functional Programming 1 F U N C T I O N A L P E A R L Why walk when you can take the tube? LUCAS DIXON University of Edinburgh PETER HANCOCK and CONOR MCBRIDE

More information

Type inference in context

Type inference in context Type inference in context Adam Gundry University of Strathclyde Microsoft Research PhD Scholar Conor McBride University of Strathclyde James McKinna Radboud University Nijmegen MSFP 25 September 2010 Two

More information

Predicate Logic. Xinyu Feng 11/20/2013. University of Science and Technology of China (USTC)

Predicate Logic. Xinyu Feng 11/20/2013. University of Science and Technology of China (USTC) University of Science and Technology of China (USTC) 11/20/2013 Overview Predicate logic over integer expressions: a language of logical assertions, for example x. x + 0 = x Why discuss predicate logic?

More information

Cost of Substitution. (interp {with {x 1} {with {y 2} {+ 100 {+ 99 { {+ y x}}}}}} )

Cost of Substitution. (interp {with {x 1} {with {y 2} {+ 100 {+ 99 { {+ y x}}}}}} ) Cost of Substitution (interp {with {x 1} {with {y 2} {+ 100 {+ 99 {+ 98... {+ y x}}}}}} 1 Cost of Substitution (interp {with {x 1} {with {y 2} {+ 100 {+ 99 {+ 98... {+ y x}}}}}} (interp {with {y 2} {+

More information

h>p://lara.epfl.ch Compiler Construc/on 2011 CYK Algorithm and Chomsky Normal Form

h>p://lara.epfl.ch Compiler Construc/on 2011 CYK Algorithm and Chomsky Normal Form h>p://lara.epfl.ch Compiler Construc/on 2011 CYK Algorithm and Chomsky Normal Form S à N ( N S) N ( N ) S S Parsing an Input N S) à S N ) N ( à ( N ) à ) 7 6 5 4 3 2 1 ambiguity N ( N ( N ) N ( N ) N (

More information

Normalization by Evaluation

Normalization by Evaluation Normalization by Evaluation Andreas Abel Department of Computer Science and Engineering Chalmers and Gothenburg University PhD Seminar in Mathematical Engineering EAFIT University, Medellin, Colombia 9

More information

Type Systems. Today. 1. What is the Lambda Calculus. 1. What is the Lambda Calculus. Lecture 2 Oct. 27th, 2004 Sebastian Maneth

Type Systems. Today. 1. What is the Lambda Calculus. 1. What is the Lambda Calculus. Lecture 2 Oct. 27th, 2004 Sebastian Maneth Today 1. What is the Lambda Calculus? Type Systems 2. Its Syntax and Semantics 3. Church Booleans and Church Numerals 4. Lazy vs. Eager Evaluation (call-by-name vs. call-by-value) Lecture 2 Oct. 27th,

More information

Boxes Go Bananas: Encoding Higher-Order Abstract Syntax with Parametric Polymorphism (Extended Version)

Boxes Go Bananas: Encoding Higher-Order Abstract Syntax with Parametric Polymorphism (Extended Version) Boxes Go Bananas: Encoding Higher-Order Abstract Syntax with Parametric Polymorphism (Extended Version) Geoffrey Washburn Stephanie Weirich Department of Computer and Information Science University of

More information

A Modular Rewriting Semantics for CML

A Modular Rewriting Semantics for CML A Modular Rewriting Semantics for CML Fabricio Chalub Barbosa do Rosário frosario@ic.uff.br 19 de março de 2004 0-0 Outline A closer look at MSOS Mapping MSOS to MRS Executing and model checking CML programs

More information

Lexical Analysis Part II: Constructing a Scanner from Regular Expressions

Lexical Analysis Part II: Constructing a Scanner from Regular Expressions Lexical Analysis Part II: Constructing a Scanner from Regular Expressions CS434 Spring 2005 Department of Computer Science University of Alabama Joel Jones Copyright 2003, Keith D. Cooper, Ken Kennedy

More information

The syntactic guard condition of Coq

The syntactic guard condition of Coq The syntactic guard condition of Coq Bruno Barras February 2, 2010 Overview 1 Theory Basic criterion Extensions 2 Algorithm Efficiency 3 Discussion 4 Attic A short history of the syntactic guard criterion

More information

CYK Algorithm for Parsing General Context-Free Grammars

CYK Algorithm for Parsing General Context-Free Grammars CYK Algorithm for Parsing General Context-Free Grammars Why Parse General Grammars Can be difficult or impossible to make grammar unambiguous thus LL(k) and LR(k) methods cannot work, for such ambiguous

More information

Principles of Program Analysis: A Sampler of Approaches

Principles of Program Analysis: A Sampler of Approaches Principles of Program Analysis: A Sampler of Approaches Transparencies based on Chapter 1 of the book: Flemming Nielson, Hanne Riis Nielson and Chris Hankin: Principles of Program Analysis Springer Verlag

More information

Syntactic Analysis. Top-Down Parsing

Syntactic Analysis. Top-Down Parsing Syntactic Analysis Top-Down Parsing Copyright 2015, Pedro C. Diniz, all rights reserved. Students enrolled in Compilers class at University of Southern California (USC) have explicit permission to make

More information

Lexical Analysis: DFA Minimization & Wrap Up

Lexical Analysis: DFA Minimization & Wrap Up Lexical Analysis: DFA Minimization & Wrap Up Automating Scanner Construction PREVIOUSLY RE NFA (Thompson s construction) Build an NFA for each term Combine them with -moves NFA DFA (subset construction)

More information

Logical Preliminaries

Logical Preliminaries Logical Preliminaries Johannes C. Flieger Scheme UK March 2003 Abstract Survey of intuitionistic and classical propositional logic; introduction to the computational interpretation of intuitionistic logic

More information

Alpha-Beta Pruning: Algorithm and Analysis

Alpha-Beta Pruning: Algorithm and Analysis Alpha-Beta Pruning: Algorithm and Analysis Tsan-sheng Hsu tshsu@iis.sinica.edu.tw http://www.iis.sinica.edu.tw/~tshsu 1 Introduction Alpha-beta pruning is the standard searching procedure used for solving

More information

Let us distinguish two kinds of annoying trivialities that occur in CoS derivations (the situation in the sequent calculus is even worse):

Let us distinguish two kinds of annoying trivialities that occur in CoS derivations (the situation in the sequent calculus is even worse): FORMALISM B Alessio Guglielmi (TU Dresden) 20.12.2004 AG13 In this note (originally posted on 9.2.2004 to the Frogs mailing list) I would like to suggest an improvement on the current notions of deep inference,

More information

Predicate Logic. Xinyu Feng 09/26/2011. University of Science and Technology of China (USTC)

Predicate Logic. Xinyu Feng 09/26/2011. University of Science and Technology of China (USTC) University of Science and Technology of China (USTC) 09/26/2011 Overview Predicate logic over integer expressions: a language of logical assertions, for example x. x + 0 = x Why discuss predicate logic?

More information

Course Announcements. Bacon is due next Monday. Next lab is about drawing UIs. Today s lecture will help thinking about your DB interface.

Course Announcements. Bacon is due next Monday. Next lab is about drawing UIs. Today s lecture will help thinking about your DB interface. Course Announcements Bacon is due next Monday. Today s lecture will help thinking about your DB interface. Next lab is about drawing UIs. John Jannotti (cs32) ORMs Mar 9, 2017 1 / 24 ORMs John Jannotti

More information

THEORY OF COMPILATION

THEORY OF COMPILATION Lecture 04 Syntax analysis: top-down and bottom-up parsing THEORY OF COMPILATION EranYahav 1 You are here Compiler txt Source Lexical Analysis Syntax Analysis Parsing Semantic Analysis Inter. Rep. (IR)

More information

Solutions to Exercises. Solution to Exercise 2.4. Solution to Exercise 2.5. D. Sabel and M. Schmidt-Schauß 1

Solutions to Exercises. Solution to Exercise 2.4. Solution to Exercise 2.5. D. Sabel and M. Schmidt-Schauß 1 D. Sabel and M. Schmidt-Schauß 1 A Solutions to Exercises Solution to Exercise 2.4 We calculate the sets of free and bound variables: FV ((λy.(y x)) (λx.(x y)) (λz.(z x y))) = FV ((λy.(y x)) (λx.(x y)))

More information

Notes from Yesterday s Discussion. Big Picture. CIS 500 Software Foundations Fall November 1. Some lessons.

Notes from Yesterday s  Discussion. Big Picture. CIS 500 Software Foundations Fall November 1. Some lessons. CIS 500 Software Foundations Fall 2006 Notes from Yesterday s Email Discussion November 1 Some lessons This is generally a crunch-time in the semester Slow down a little and give people a chance to catch

More information

Elaborating evaluation-order polymorphism

Elaborating evaluation-order polymorphism Elaborating evaluation-order polymorphism Joshua Dunfield University of British Columbia ICFP 2015 1 (prologue) ICFP in Canada for the first time since 2008 2 (prologue) ICFP in Canada for the first time

More information

Introduction to lambda calculus Part 6

Introduction to lambda calculus Part 6 Introduction to lambda calculus Part 6 Antti-Juhani Kaijanaho 2017-02-16 1 Untyped lambda calculus 2 Typed lambda calculi 2.1 Dynamically typed lambda calculus with integers 2.2 A model of Lisp 2.3 Simply

More information

Alpha-Beta Pruning: Algorithm and Analysis

Alpha-Beta Pruning: Algorithm and Analysis Alpha-Beta Pruning: Algorithm and Analysis Tsan-sheng Hsu tshsu@iis.sinica.edu.tw http://www.iis.sinica.edu.tw/~tshsu 1 Introduction Alpha-beta pruning is the standard searching procedure used for 2-person

More information

Alpha-Beta Pruning: Algorithm and Analysis

Alpha-Beta Pruning: Algorithm and Analysis Alpha-Beta Pruning: Algorithm and Analysis Tsan-sheng Hsu tshsu@iis.sinica.edu.tw http://www.iis.sinica.edu.tw/~tshsu 1 Introduction Alpha-beta pruning is the standard searching procedure used for 2-person

More information

COMP 3161/9161 Week 2

COMP 3161/9161 Week 2 Concepts of Programming Languages Judgements, Inference Rules & Proofs Lecturer: Gabriele Keller Tutor: Liam O Connor University of New South Wales School of Computer Sciences & Engineering Sydney, Australia

More information

Why Functions as Values

Why Functions as Values Why Functions as Values Abstraction is easier with functions as values get-ids filter, map, etc. Separate deffun form becomes unnecessary {deffun {f x} {+ 1 x}} {f 10} {with {f {fun {x} {+ 1 x}}} {f 10}}

More information

Predicate Logic. x. x + 0 = x. Predicate logic over integer expressions: a language of logical assertions, for example. Why discuss predicate logic?

Predicate Logic. x. x + 0 = x. Predicate logic over integer expressions: a language of logical assertions, for example. Why discuss predicate logic? Predicate Logic Predicate logic over integer expressions: a language of logical assertions, for example x. x + 0 = x Why discuss predicate logic? It is an example of a simple language It has simple denotational

More information

The Locally Nameless Representation

The Locally Nameless Representation Noname manuscript No. (will be inserted by the editor) The Locally Nameless Representation Arthur Charguéraud Received: date / Accepted: date Abstract This paper provides an introduction to the locally

More information

Midterm Exam Types and Programming Languages Frank Pfenning. October 18, 2018

Midterm Exam Types and Programming Languages Frank Pfenning. October 18, 2018 Midterm Exam 15-814 Types and Programming Languages Frank Pfenning October 18, 2018 Name: Andrew ID: Instructions This exam is closed-book, closed-notes. You have 80 minutes to complete the exam. There

More information

Verified Characteristic Formulae for CakeML. Armaël Guéneau, Magnus O. Myreen, Ramana Kumar, Michael Norrish April 18, 2017

Verified Characteristic Formulae for CakeML. Armaël Guéneau, Magnus O. Myreen, Ramana Kumar, Michael Norrish April 18, 2017 Verified Characteristic Formulae for CakeML Armaël Guéneau, Magnus O. Myreen, Ramana Kumar, Michael Norrish April 18, 2017 CakeML Has: references, modules, datatypes, exceptions, a FFI,... Doesn t have:

More information

Principal types Robustness to program transformations Practice. Type constraints for simple types Type constraints for ML Type inference in ML F

Principal types Robustness to program transformations Practice. Type constraints for simple types Type constraints for ML Type inference in ML F 1 Design iml F : an implicity-typed extension of System F Types explained eml F : an explicitly-typed version of iml F 2 Results Principal types Robustness to program transformations Practice 3 Type inference

More information

Syntax Analysis Part I. Position of a Parser in the Compiler Model. The Parser. Chapter 4

Syntax Analysis Part I. Position of a Parser in the Compiler Model. The Parser. Chapter 4 1 Syntax Analysis Part I Chapter 4 COP5621 Compiler Construction Copyright Robert van ngelen, Flora State University, 2007 Position of a Parser in the Compiler Model 2 Source Program Lexical Analyzer Lexical

More information

Follow sets. LL(1) Parsing Table

Follow sets. LL(1) Parsing Table Follow sets. LL(1) Parsing Table Exercise Introducing Follow Sets Compute nullable, first for this grammar: stmtlist ::= ε stmt stmtlist stmt ::= assign block assign ::= ID = ID ; block ::= beginof ID

More information

Abstract Parsing for Two-staged Language. Soonho Kong May 1, 2009

Abstract Parsing for Two-staged Language. Soonho Kong May 1, 2009 Astract arsing for Two-staged Language May 1, 009 Contents Motivation Language - Syntax & Semantics LR arsing Concrete arsing Astraction Instantiation / 5 Motivation rogram generates another program. How

More information

Jeffrey D. Ullman Stanford University

Jeffrey D. Ullman Stanford University Jeffrey D. Ullman Stanford University 3 We are given a set of training examples, consisting of input-output pairs (x,y), where: 1. x is an item of the type we want to evaluate. 2. y is the value of some

More information

CMSC 631 Program Analysis and Understanding Fall Type Systems

CMSC 631 Program Analysis and Understanding Fall Type Systems Program Analysis and Understanding Fall 2017 Type Systems Type Systems A type system is a tractable syntactic method for proving the absence of certain program behaviors by classifying phrases according

More information

GOTO the past / programs choose their own adventure. CSE 505: Programming Languages

GOTO the past / programs choose their own adventure. CSE 505: Programming Languages GOTO the past / programs choose their own adventure. CSE 505: Programming Languages Lecture 13 Evaluation Contexts First-Class Continuations Continuation-Passing Style Zach Tatlock Fall 2013 Zach Tatlock

More information

A Principled Approach to Ornamentation in ML

A Principled Approach to Ornamentation in ML A Principled Approach to Ornamentation in ML Thomas Williams, Didier Rémy To cite this version: Thomas Williams, Didier Rémy. A Principled Approach to Ornamentation in ML. [Research Report] RR-9117, Inria.

More information

Declarative Computation Model. Conditional. Case statement. Procedure values (2) Procedure values. Sequential declarative computation model

Declarative Computation Model. Conditional. Case statement. Procedure values (2) Procedure values. Sequential declarative computation model Declarative Computation Model Kernel language semantics revisited (VRH.4.5) From kernel to practical language (VRH.6) Exceptions (VRH.7) Carlos Varela RPI October 0, 009 Adapted with permission from: Seif

More information

Interoperation for Lazy and Eager Evaluation

Interoperation for Lazy and Eager Evaluation Interoperation for Lazy and Eager Evaluation 1 Matthews & Findler New method of interoperation Type safety, observational equivalence & transparency Eager evaluation strategies Lazy vs. eager 2 Lambda

More information

Ramsey s Theorem in ProofPower (Draft)

Ramsey s Theorem in ProofPower (Draft) A1 L E M M Lemma 1 Ltd. c/o Interglossa 2nd Floor 31A Chain St. Reading Berks RG1 2HX Ramsey s Theorem in ProofPower (Draft) Abstract This paper is concerned with a ProofPower-HOL proof of the finite exponent

More information

Taming Selective Strictness

Taming Selective Strictness Taming Selective Strictness Daniel Seidel and Janis Voigtländer Technische Universität Dresden, 01062 Dresden, Germany {seideld,voigt}@tcs.inf.tu-dresden.de Abstract: Free theorems establish interesting

More information

Bottom-Up Syntax Analysis

Bottom-Up Syntax Analysis Bottom-Up Syntax Analysis Mooly Sagiv http://www.cs.tau.ac.il/~msagiv/courses/wcc13.html Textbook:Modern Compiler Design Chapter 2.2.5 (modified) 1 Pushdown automata Deterministic fficient Parsers Report

More information

DEBUGGING AND TESTING WITH SCALACHECK. Martina Seidl 2017/11/14

DEBUGGING AND TESTING WITH SCALACHECK. Martina Seidl 2017/11/14 DEBUGGING AND TESTING WITH SCALACHECK Martina Seidl 2017/11/14 Some Words on Scala Scala is object-oriented every value is an object classes and traits: types and behavior of objects inheritance Scala

More information

Computing if a token can follow

Computing if a token can follow Computing if a token can follow first(b 1... B p ) = {a B 1...B p... aw } follow(x) = {a S......Xa... } There exists a derivation from the start symbol that produces a sequence of terminals and nonterminals

More information

Bicubical Directed Type Theory

Bicubical Directed Type Theory Bicubical Directed Type Theory Matthew Weaver General Examination May 7th, 2018 Advised by Andrew Appel and Dan Licata Bicubical Directed Type Theory Bicubical directed type theory is a constructive model

More information

Reading: Chapter 9.3. Carnegie Mellon

Reading: Chapter 9.3. Carnegie Mellon I II Lecture 3 Foundation of Data Flow Analysis Semi-lattice (set of values, meet operator) Transfer functions III Correctness, precision and convergence IV Meaning of Data Flow Solution Reading: Chapter

More information

Clojure Concurrency Constructs, Part Two. CSCI 5828: Foundations of Software Engineering Lecture 13 10/07/2014

Clojure Concurrency Constructs, Part Two. CSCI 5828: Foundations of Software Engineering Lecture 13 10/07/2014 Clojure Concurrency Constructs, Part Two CSCI 5828: Foundations of Software Engineering Lecture 13 10/07/2014 1 Goals Cover the material presented in Chapter 4, of our concurrency textbook In particular,

More information

Distributed Systems Byzantine Agreement

Distributed Systems Byzantine Agreement Distributed Systems Byzantine Agreement He Sun School of Informatics University of Edinburgh Outline Finish EIG algorithm for Byzantine agreement. Number-of-processors lower bound for Byzantine agreement.

More information

Information Flow Inference for ML

Information Flow Inference for ML Information Flow Inference for ML Vincent Simonet INRIA Rocquencourt Projet Cristal MIMOSA September 27, 2001 Information flow account number bank applet order vendor account H order L bank H vendor L

More information

Computer Science 160 Translation of Programming Languages

Computer Science 160 Translation of Programming Languages Computer Science 160 Translation of Programming Languages Instructor: Christopher Kruegel Top-Down Parsing Top-down Parsing Algorithm Construct the root node of the parse tree, label it with the start

More information

Compiling Techniques

Compiling Techniques Lecture 6: 9 October 2015 Announcement New tutorial session: Friday 2pm check ct course webpage to find your allocated group Table of contents 1 2 Ambiguity s Bottom-Up Parser A bottom-up parser builds

More information

COMP 204. Object Oriented Programming (OOP) Mathieu Blanchette

COMP 204. Object Oriented Programming (OOP) Mathieu Blanchette COMP 204 Object Oriented Programming (OOP) Mathieu Blanchette 1 / 14 Object-Oriented Programming OOP is a way to write and structure programs to make them easier to design, understand, debug, and maintain.

More information

Chapter 1 A computational interpretation of forcing in Type Theory

Chapter 1 A computational interpretation of forcing in Type Theory Chapter 1 A computational interpretation of forcing in Type Theory Thierry Coquand and Guilhem Jaber Abstract In a previous work, we showed the uniform continuity of definable functionals in intuitionistic

More information

Existential Label Flow Inference via CFL Reachability

Existential Label Flow Inference via CFL Reachability Existential Label Flow Inference via CFL Reachability Polyvios Pratikakis Michael Hicks Jeffrey S. Foster July, 2005 Abstract Label flow analysis is a fundamental static analysis problem with a wide variety

More information

Syntax and semantics of a GPU kernel programming language

Syntax and semantics of a GPU kernel programming language Syntax and semantics of a GPU kernel programming language John Wickerson April 17, 2016 Abstract This document accompanies the article The Design and Implementation of a Verification Technique for GPU

More information

Recitation 2: Binding, Semantics, and Safety : Foundations of Programming Languages

Recitation 2: Binding, Semantics, and Safety : Foundations of Programming Languages Recitation 2: Binding, Semantics, and Safety 15-312: Foundations of Programming Languages Charles Yuan, Jeanne Luning Prak September 5, 2018 1 Abstract Binding Trees The abstract syntax trees we saw previously

More information