School of Computing and Mathematics, University of Huddersfield CAS810: WEEK 7 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE WITH ENVIRONMENTS : INTERPRETATION.

Slides:



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

Type Checking, Inference, & Elaboration CS153: Compilers Greg Morrisett.
Exercise 1 Generics and Assignments. Language with Generics and Lots of Type Annotations Simple language with this syntax types:T ::= Int | Bool | T =>
Assignments and Procs w/Params EOPL3 Chapter 4. Expressible vs. Denotable values Expressible Values –the language can express and compute these –represented.
1 How to transform an analyzer into a verifier. 2 OUTLINE OF THE LECTURE a verification technique which combines abstract interpretation and Park’s fixpoint.
Tim Sheard Oregon Graduate Institute Lecture 8: Operational Semantics of MetaML CSE 510 Section FSC Winter 2005 Winter 2005.
8. Introduction to Denotational Semantics. © O. Nierstrasz PS — Denotational Semantics 8.2 Roadmap Overview:  Syntax and Semantics  Semantics of Expressions.
School of Computing and Mathematics, University of Huddersfield CAS810: WEEK 5 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE : INTERPRETATION IN HASKELL.
0 PROGRAMMING IN HASKELL Chapter 10 - Declaring Types and Classes.
Functional Programming. Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends.
String is a synonym for the type [Char].
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 14 Functional Programming It is better to.
Fall Semantics Juan Carlos Guzmán CS 3123 Programming Languages Concepts Southern Polytechnic State University.
School of Computing and Engineering, University of Huddersfield LANGUAGE TRANSLATORS: WEEK 10 LECTURE: symbol tables TUTORIAL: Pen and paper exercises.
School of Computing and Engineering, University of Huddersfield CHA2545: WEEK 14 LECTURE: ABSTRACT SYNTAX SIMPLE EXAMPLE OF SEMANTICS DEFINITION TUTORIAL/PRACTICAL:
Comp 205: Comparative Programming Languages Semantics of Imperative Programming Languages denotational semantics operational semantics logical semantics.
Lecture 02 – Structural Operational Semantics (SOS) Eran Yahav 1.
School of Computing and Engineering, University of Huddersfield CHA2545: WEEK 14 - SYNTAX LECTURE: ABSTRACT SYNTAX SIMPLE EXAMPLE OF SEMANTICS DEFINITION.
School of Computing and Mathematics, University of Huddersfield CAS2545: WEEK 11 LECTURE: n The meaning of Algebraic Specifications TUTORIAL/PRACTICAL:
8. Introduction to Denotational Semantics. © O. Nierstrasz PS — Denotational Semantics 8.2 Roadmap  Syntax and Semantics  Semantics of Expressions 
School of Computing and Mathematics, University of Huddersfield CAS810: WEEK 3 LECTURE: LAMBDA CALCULUS PRACTICAL/TUTORIAL: (i) Do exercises given out.
C SC 520 Principles of Programming Languages Principles of Programming Languages Lecture 08 Control Semantics & Continuations.
Programming Language Semantics Mooly SagivEran Yahav Schrirber 317Open space html://
Denotational Semantics Syntax-directed approach, generalization of attribute grammars: –Define context-free abstract syntax –Specify syntactic categories.
Control Flow Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
1 Control Flow Analysis Mooly Sagiv Tel Aviv University Textbook Chapter 3
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 10 Function Implementation In theory, there.
Programming Language Semantics Mooly SagivEran Yahav Schrirber 317Open space html://
The Semantic Web – WEEK 3: XML Schema Tutorial/Practical: Exercises using the Suns Today’s lecture will include material relevant to Advanced DBs and Language.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Chapter 6: Type Systems Fall 2009.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 6 Type Systems I was eventually persuaded.
Semantics with Applications Mooly Sagiv Schrirber html:// Textbooks:Winskel The.
Cs784(Prasad)L123Assg1 Assignments. cs784(Prasad)L123Assg2 l-value vs. r-value Pascal/Ada: x := x + 1 C/Java: x = x + 1 l-value = location, address, reference,
School of Computing and Mathematics, University of Huddersfield Computing Science: WEEK 17 Announcement: next few weeks… 9 nd Feb: Comparative Programming.
Language Translators - Lee McCluskey LANGUAGE TRANSLATORS: WEEK 21 LECTURE: Using JavaCup to create simple interpreters
0 REVIEW OF HASKELL A lightening tour in 45 minutes.
11/1/20151 GC16/3011 Functional Programming Lecture 5 Miranda patterns, functions, recursion and lists.
Advanced Functional Programming Tim Sheard 1 Lecture 6 Functional Programming Tim Sheard & Mark Jones Monads & Interpreters.
Semantics. Semantics is a precise definition of the meaning of a syntactically and type-wise correct program. Ideas of meaning: –Operational Semantics.
Programming Languages and Design Lecture 3 Semantic Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
School of Computing and Mathematics, University of Huddersfield CHA2545: WEEK 4 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE TUTORIAL: Do exercises.
Advanced Formal Methods Lecture 3: Simply Typed Lambda calculus Mads Dam KTH/CSC Course 2D1453, Some material from B. Pierce: TAPL + some from.
School of Computing and Engineering, University of Huddersfield CHA2545: WEEK 14 – SEMANTICS EXAMPLE LECTURE: SIMPLE EXAMPLE OF SEMANTICS DEFINITION TUTORIAL/PRACTICAL:
0 PROGRAMMING IN HASKELL Chapter 4 - Defining Functions.
Programming Language Descriptions. What drives PL Development? Computers are “in charge” of extremely important issues Execute a program literally. Exercise.
1 Programming Languages (CS 550) Lecture 2 Summary Mini Language Interpreter Jeremy R. Johnson.
Programming Languages Meeting 4 September 16/17, 2014.
Formal Semantics of Programming Languages 虞慧群 Topic 2: Operational Semantics.
Environments, Stores, and Interpreters. Overview As we study languages we will build small languages that illustrate language features We will use two.
CS5205Semantics1 CS5205: Foundation in Programming Languages Semantics Static Semantics Dynamic Semantics Operational Semantics Big-step Small-Step Denotational.
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Control Structure  What is control Structure?  Types of Controls  Use the control structure in VBScript.  Example Summery.
Functional Programming
String is a synonym for the type [Char].
Conditional Expressions
CS 4450: Principles of Programming Languages
6.001 SICP Compilation Context: special purpose vs. universal machines
A lightening tour in 45 minutes
Graph-Based Operational Semantics
CS4450: Principles of Programming Languages
Functional Programming Lecture 2 - Functions
Semantics HOFL short semantics Roberto Zunino
Programming Languages
The Metacircular Evaluator
Principles of Programming Languages
PROGRAMMING IN HASKELL
Environments, Stores, and Interpreters
Assignments and Procs w/Params
Functional Programming Lecture 2 - Functions
Representations & Reasoning Systems (RRS) (2.2)
Presentation transcript:

School of Computing and Mathematics, University of Huddersfield CAS810: WEEK 7 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE WITH ENVIRONMENTS : INTERPRETATION IN HASKELL PRACTICAL AND DURING THE WEEK: Do practical exercises to be given out..

School of Computing and Mathematics, University of Huddersfield HASKELL IMPLEMENTATION OF LAST WEEKS LANGUAGE n NB implementations always add extra “detail” that doesn’t occur in the abstract definition. Some syntax is necessarily different n I’ve cut a few corners to keep it simple – not all the error situations are specified

School of Computing and Mathematics, University of Huddersfield ABSTRACT SYNTAX data Exp = SN Int | SB Bool | SV Identifier | SC Identifier | Plus Exp Exp | Minus Exp Exp | GT Exp Exp data Cmd = Assigns Identifier Exp | Sequence Cmd Cmd | While Exp Cmd | Block Dec Cmd data Dec = Const Identifier Exp | Var Identifier Exp

School of Computing and Mathematics, University of Huddersfield ABSTRACT SYNTAX - EXAMPLE (Block (Var 'r' (SV 'y')) (Block (Var 'q' (SN 0)) (While (GT (SV 'r') (SV 'x')) (Sequence (Assigns 'r' (Minus (SV 'r') (SV 'x') )) (Assigns 'q' (Plus (SV 'q') (SN 1 ) )) ) Example “Concrete Syntax”.. {Var r = y; {Var q = 0; while r > x do {r = r-x; q = q+1} }

School of Computing and Mathematics, University of Huddersfield SEMANTIC DOMAINS -- values and locations data V = VB Bool | VN Int | V_error data D = LC Loc | EB Bool | EN Int | D_error -- the MAPS environments and stores are -- represented as a sequence of pairs data U = UCons Identifier D U | UNull | U_error data S = SCons Loc V S | SNull | S_error

School of Computing and Mathematics, University of Huddersfield AUXILIARY FUNCTIONS contents :: Loc -> S -> V contents l s = applyS s l update :: Loc -> V -> S -> S update l v s = overwrite s l v new :: S -> Loc new s = (maxloc 0 s)+1 maxloc :: Int -> S -> Int maxloc i SNull = i maxloc i (SCons l v s) | l > i = maxloc l s | otherwise = maxloc i s

School of Computing and Mathematics, University of Huddersfield meaning functions- Emeans -- exp is a var emeans (SV x) u S_error = V_error emeans (SV x) u s = contents l s where l = get_loc (applyU u x) NB extra selector function because applyU returns a Denotable value! get_loc :: D -> Loc get_loc (LC l) = l

School of Computing and Mathematics, University of Huddersfield meaning functions- Dmeans dmeans :: Dec -> U -> S -> (U,S) dmeans (Const id exp) u s = (UCons id e UNull, s) where e = get_exp (emeans exp u s) (NB get_exp :: V -> D) dmeans (Var id exp) u s = (UCons id (LC l) UNull, update l e s) where e = (emeans exp u s) l = new s

School of Computing and Mathematics, University of Huddersfield meaning functions- Cmeans - assignment cmeans (Assigns id exp) u s = update l v s where l = get_loc (applyU u id) v = emeans exp u s -- Sequence of two or more commands cmeans (Sequence c1 c2) u s = cmeans c2 u (cmeans c1 u s)

School of Computing and Mathematics, University of Huddersfield meaning functions- Cmeans -- meaning of a block command cmeans (Block dec c) u s = cmeans c u2 s1 where u1 = fst (dmeans dec u s) s1 = snd (dmeans dec u s) u2 = env_overwrite u u1

School of Computing and Mathematics, University of Huddersfield meaning functions- Cmeans cmeans (While exp c) u s | val (emeans exp u s) == False = s | otherwise = cmeans (While exp c) u (cmeans c u s)