School of Computing and Mathematics, University of Huddersfield CAS810: WEEK 5 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE : INTERPRETATION IN HASKELL.

Slides:



Advertisements
Similar presentations
Types and Programming Languages Lecture 7 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Advertisements

1 Programming Languages (CS 550) Mini Language Interpreter Jeremy R. Johnson.
Expressions and Statements. 2 Contents Side effects: expressions and statements Expression notations Expression evaluation orders Conditional statements.
Winter Compiler Construction T7 – semantic analysis part II type-checking Mooly Sagiv and Roman Manevich School of Computer Science Tel-Aviv.
8. Introduction to Denotational Semantics. © O. Nierstrasz PS — Denotational Semantics 8.2 Roadmap Overview:  Syntax and Semantics  Semantics of Expressions.
1 Programming Languages (CS 550) Lecture Summary Functional Programming and Operational Semantics for Scheme Jeremy R. Johnson.
IT253: Computer Organization Lecture 6: Assembly Language and MIPS: Programming Tonga Institute of Higher Education.
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.
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.
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.
School of Computing and Mathematics, University of Huddersfield CAS810: WEEK 7 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE WITH ENVIRONMENTS : INTERPRETATION.
0 PROGRAMMING IN HASKELL Chapter 4 - Defining Functions.
Denotational Semantics Syntax-directed approach, generalization of attribute grammars: –Define context-free abstract syntax –Specify syntactic categories.
Abstract Syntax Trees Compiler Baojian Hua
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
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.
SICP Variations on a Scheme Scheme Evaluator – A Grand Tour Techniques for language design: Interpretation: eval/apply Semantics vs. syntax Syntactic.
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.
Chapter 2 A Simple Compiler
Language Translators - Lee McCluskey LANGUAGE TRANSLATORS: WEEK 21 LECTURE: Using JavaCup to create simple interpreters
Semantics. Semantics is a precise definition of the meaning of a syntactically and type-wise correct program. Ideas of meaning: –Operational Semantics.
Parse & Syntax Trees Syntax & Semantic Errors Mini-Lecture.
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.
Simple Language (SL) Start version 00. Atze Dijkstra, 2000IPT - SL2 Content SL, the language AG, attribute grammar system First version of SL compiler.
1 CS1001 Lecture Overview Java Programming Java Programming Arrays Arrays.
Copyright 2001, Matt Dwyer, John Hatcliff, and Radu Iosif. The syllabus and all lectures for this course are copyrighted materials and may not be used.
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.
CPSC 388 – Compiler Design and Construction Parsers – Syntax Directed Translation.
1 Programming Languages (CS 550) Lecture 2 Summary Mini Language Interpreter Jeremy R. Johnson.
Formal Semantics of Programming Languages 虞慧群 Topic 2: Operational Semantics.
CS5205Semantics1 CS5205: Foundation in Programming Languages Semantics Static Semantics Dynamic Semantics Operational Semantics Big-step Small-Step Denotational.
School of Computing and Mathematics, University of Huddersfield CAS810: WEEK 8 LECTURE: LAMBDA CALCULUS SEMANTICS TUTORIAL: exercises.
ADTS, GRAMMARS, PARSING, TREE TRAVERSALS Lecture 13 CS2110 – Spring
1 Vectors, binary search, and sorting. 2 We know about lists O(n) time to get the n-th item. Consecutive cons cell are not necessarily consecutive in.
CS 603: Programming Language Organization Lecture 6 Spring 2003 Department of Computer Science University of Alabama Joel Jones.
Functional Programming
String is a synonym for the type [Char].
Conditional Expressions
Principles of programming languages 12: Functional programming
CS 4450: Principles of Programming Languages
A lightening tour in 45 minutes
CS4450: Principles of Programming Languages
Original material by Eric Grimson
Mini Language Interpreter Programming Languages (CS 550)
Programming Languages
The Metacircular Evaluator
Programming Languages (CS 550) Mini Language Semantics
The Metacircular Evaluator
Lecture 4: Lexical Analysis & Chomsky Hierarchy
Syntax-Directed Translation
The Metacircular Evaluator (Continued)
PROGRAMMING IN HASKELL
PROGRAMMING IN HASKELL
6.001 SICP Variations on a Scheme
6.001 SICP Interpretation Parts of an interpreter
Assignments and Procs w/Params
topics interpreters meta-linguistic abstraction eval and apply
Representations & Reasoning Systems (RRS) (2.2)
Presentation transcript:

School of Computing and Mathematics, University of Huddersfield CAS810: WEEK 5 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE : INTERPRETATION IN HASKELL FORMATIVE ASSESSMENT: Last week’s exercises, Cmeans[[if B then S1 else S2]] PRACTICAL AND DURING THE WEEK: Do practical exercises to be given out..

School of Computing and Mathematics, University of Huddersfield GOFER/HASKELL IMPLEMENTATION OF LAST WEEKS LANGUAGE An implementation should deepen your understanding of the semantic definition BUT - implementations always add extra “detail” that doesn’t occur in the abstract definition - some syntax is necessarily different - I’ve cut a few corners to keep it simple - some “implicit” things have to be explicitly defined e.g. The overwrite and apply functions for maps

School of Computing and Mathematics, University of Huddersfield GOFER/HASKELL IMPLEMENTATION PROGRAM TEXT ‘SYNTAX TREE’ PREFIX FORM (Plus (SI 'x') (SN 42))x + 42 Cons 'y' (VN 0) (Cons 'x' (VN (-3)) Null) STORE cmeans NEW STORE

School of Computing and Mathematics, University of Huddersfield ABSTRACT SYNTAX - is in PREFIX form - is like normal syntax onto which a PARSER has been applied, producing an abstract syntax tree e.g. PARSER(x + 42) = (Plus (SI 'x') (SN 42)) This latter syntax is what the ‘implementation’ (of the denotational defn) is applied to...

School of Computing and Mathematics, University of Huddersfield ABSTRACT SYNTAX -- abstract syntax data Exp = SN Int | SB Bool | SI Identifier | Plus Exp Exp data Cmd = Assigns Identifier Exp | Sequence Cmd Cmd | While Exp Cmd

School of Computing and Mathematics, University of Huddersfield SEMANTIC DOMAINS -- semantic domains (1) expressible values data E = VB Bool | VN Int | E_error -- (2) stores data S = Cons Identifier E S | Null | S_error

School of Computing and Mathematics, University of Huddersfield STORE - FUNCTIONS apply :: S -> Identifier -> E apply Null j = E_error apply S_error j = E_error apply (Cons i e s) j | i == j = e | otherwise = apply s j

School of Computing and Mathematics, University of Huddersfield STORE - FUNCTIONS overwrite :: S -> Identifier -> E -> S overwrite s j E_error = S_error overwrite Null j e2 = (Cons j e2 Null) overwrite S_error j e2 = S_error overwrite (Cons i e1 s) j e2 | i == j = (Cons i e2 s) | otherwise = (Cons i e1 (overwrite s j e2))

School of Computing and Mathematics, University of Huddersfield meaning functions- Emeans emeans :: Exp -> S -> E emeans (SB True) s = (VB True) emeans (SN x) s = VN x emeans (SI x) S_error = E_error emeans (SI x) s = apply s x emeans (Plus e1 e2) S_error = E_error emeans (Plus e1 e2) s = add (emeans e1 s) (emeans e2 s)

School of Computing and Mathematics, University of Huddersfield meaning functions- Cmeans cmeans :: Cmd -> S -> S cmeans c S_error = S_error cmeans (Assigns id exp) s = overwrite s id (emeans exp s) cmeans (Sequence c1 c2) s = cmeans c2 (cmeans c1 s)

School of Computing and Mathematics, University of Huddersfield meaning functions- Cmeans cmeans :: Cmd -> S -> S cmeans (While exp c) s | val (emeans exp s) == 0 = s | otherwise = cmeans (While exp c) (cmeans c s) val :: E -> Int val (VN x) = x

School of Computing and Mathematics, University of Huddersfield TESTS astore = Cons 'y' (VN 0) (Cons 'x' (VN (-3)) Null) test1 = cmeans (Assigns 'x' (SN 42)) astore test2 = cmeans (Sequence (Assigns 'x' (SN 42)) (Assigns 'y' (SI 'x')) ) astore test3 = cmeans (While (SI 'x') (Sequence (Assigns 'x' (Plus (SI 'x') (SN 1)) ) (Assigns 'y' (Plus (SI 'y') (SN 1)) ) )) astore test4 = cmeans (Sequence (Assigns 'x' (SN 42)) (Assigns 'y' (SI 'z')) ) astore