School of Computing and Engineering, University of Huddersfield CHA2545: WEEK 14 LECTURE: ABSTRACT SYNTAX SIMPLE EXAMPLE OF SEMANTICS DEFINITION TUTORIAL/PRACTICAL:

Slides:



Advertisements
Similar presentations
8. Introduction to Denotational Semantics. © O. Nierstrasz PS — Denotational Semantics 8.2 Roadmap Overview:  Syntax and Semantics  Semantics of Expressions.
Advertisements

School of Computing and Mathematics, University of Huddersfield CAS810: WEEK 5 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE : INTERPRETATION IN HASKELL.
CS 355 – Programming Languages
School of Computing and Engineering, University of Huddersfield LANGUAGE TRANSLATORS: WEEK 10 LECTURE: symbol tables TUTORIAL: Pen and paper exercises.
AI - Week 13 Knowledge Representation, Logic, Semantic Web Lee McCluskey, room 2/07
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:
School of Computing and Mathematics, University of Huddersfield CAS810: WEEK 3 LECTURE: LAMBDA CALCULUS PRACTICAL/TUTORIAL: (i) Do exercises given out.
Language Specfication and Implementation - PART II: Semantics of Procedural Programming Languages Lee McCluskey Department of Computing and Mathematical.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 2 Syntax A language that is simple to parse.
Denotational Semantics Syntax-directed approach, generalization of attribute grammars: –Define context-free abstract syntax –Specify syntactic categories.
CS 330 Programming Languages 09 / 13 / 2007 Instructor: Michael Eckmann.
CS 330 Programming Languages 09 / 18 / 2007 Instructor: Michael Eckmann.
School of Computing and Mathematics, University of Huddersfield CIA2326 Week 14 LECTURE: How to reason with Algebraic Specifications TUTORIAL/PRACTICAL:
School of Computing and Mathematics, University of Huddersfield CHA2545 Last Lecture LECTURE: LAMBDA CALCULUS SEMANTICS TUTORIAL: Revision.
PSUCS322 HM 1 Languages and Compiler Design II Formal Semantics Material provided by Prof. Jingke Li Stolen with pride and modified by Herb Mayer PSU Spring.
CSC 8310 Programming Languages Meeting 2 September 2/3, 2014.
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
CSE 425: Intro to Programming Languages and their Design A Few Key Ideas No particular language is a prerequisite for this course –However you should be.
Chapter 2 Syntax A language that is simple to parse for the compiler is also simple to parse for the human programmer. N. Wirth.
The College of Saint Rose CIS 433 – Programming Languages David Goldschmidt, Ph.D. from Concepts of Programming Languages, 9th edition by Robert W. Sebesta,
Syntax & Semantic Introduction Organization of Language Description Abstract Syntax Formal Syntax The Way of Writing Grammars Formal Semantic.
Chpater 3. Outline The definition of Syntax The Definition of Semantic Most Common Methods of Describing Syntax.
OPERATING SYSTEMS AND LANGUAGE TRANSLATORS CIS 2380 TERM 2 – LANGUAGE TRANSLATORS Lee McCluskey – 23/09/20151.
1 COSC 4406 Software Engineering COSC 4406 Software Engineering Haibin Zhu, Ph.D. Dept. of Computer Science and mathematics, Nipissing University, 100.
Program Analysis and Verification Spring 2015 Program Analysis and Verification Lecture 2: Operational Semantics I Roman Manevich Ben-Gurion University.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
0 REVIEW OF HASKELL A lightening tour in 45 minutes.
Principles of programming languages 5: An operational semantics of a small subset of C Department of Information Science and Engineering Isao Sasano.
School of Computing and Mathematics, University of Huddersfield CIA2326: Week 11 LECTURE: Formal Specification TUTORIAL/PRACTICAL: Finish off last weeks.
School of Computing and Engineering, University of Huddersfield CIA2326 Week 14 LECTURE: Formal Specifications. How to reason with Algebraic Specifications.
1 Programming Languages Fundamentals Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM.
Parse & Syntax Trees Syntax & Semantic Errors Mini-Lecture.
CSE 311 Foundations of Computing I Lecture 17 Structural Induction Spring
These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and are provided with permission by.
Formal Semantics of Programming Languages 虞慧群 Topic 1: Introduction.
CPS 506 Comparative Programming Languages Syntax Specification.
3.2 Semantics. 2 Semantics Attribute Grammars The Meanings of Programs: Semantics Sebesta Chapter 3.
Programming Languages and Design Lecture 3 Semantic Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
Syntax and Semantics CIS 331 Syntax: the form or structure of the expressions, statements, and program units. Semantics: the meaning of the expressions,
School of Computing and Mathematics, University of Huddersfield CHA2545: WEEK 4 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE TUTORIAL: Do exercises.
1 / 48 Formal a Language Theory and Describing Semantics Principles of Programming Languages 4.
8.4 Use Scientific Notation Algebra. Scientific Notation Numbers such as 1,000,000, 153,000 and are written in standard form. Another way to write.
CMSC 330: Organization of Programming Languages Operational Semantics a.k.a. “WTF is Project 4, Part 3?”
School of Computing and Engineering, University of Huddersfield CHA2545: WEEK 14 – SEMANTICS EXAMPLE LECTURE: SIMPLE EXAMPLE OF SEMANTICS DEFINITION TUTORIAL/PRACTICAL:
Textbook C for Scientists and Engineers © Prentice Hall 1997 Available at NUS CO-OP at S$35.10.
C H A P T E R T W O Linking Syntax And Semantics Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
LECTURE 4 Syntax. SPECIFYING SYNTAX Programming languages must be very well defined – there’s no room for ambiguity. Language designers must use formal.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Denotational Semantics.
CMSC 330: Organization of Programming Languages Operational Semantics.
School of Computing and Mathematics, University of Huddersfield CAS810: WEEK 8 LECTURE: LAMBDA CALCULUS SEMANTICS TUTORIAL: exercises.
CSE 311: Foundations of Computing Fall 2013 Lecture 18: Structural induction, regular expressions.
CSE 311 Foundations of Computing I Lecture 19 Recursive Definitions: Context-Free Grammars and Languages Autumn 2012 CSE
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
Dr. M. Al-Mulhem Denotational Semantics 1 Chapter 4 Fundamentals (Denotational Semantics)
Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. L05-1 September 21, 2006http:// Types and Simple Type.
Programming Languages
Semantic Analysis Chapter 4.
Theory of Computation Lecture 4: Programs and Computable Functions II
CS 614: Theory and Construction of Compilers
A lightening tour in 45 minutes
Programming Languages
C H A P T E R T W O Syntax.
Lecture 4: Lexical Analysis & Chomsky Hierarchy
Programming Languages 2nd edition Tucker and Noonan
Denotational Semantics
Syntax vs Semantics Backus-Naur Form Extended BNF Derivations
Algebraic Specification Software Specification Lecture 34
Presentation transcript:

School of Computing and Engineering, University of Huddersfield CHA2545: WEEK 14 LECTURE: ABSTRACT SYNTAX SIMPLE EXAMPLE OF SEMANTICS DEFINITION TUTORIAL/PRACTICAL: - Last weeks exercise 5 - Haskell/Gofer revision..follow WEB NOTES/EXERCISES NB supporting notes for all these topics in web page

School of Computing and Engineering, University of Huddersfield ABSTRACT SYNTAX n concrete syntax: to write programs we need to know exactly how statements are formed and their exact written notation. n abstract syntax: to gain an understanding of the general structure of a language we only need to know how the components relate.

School of Computing and Engineering, University of Huddersfield ABSTRACT SYNTAX : assignment example JAVA / C: X = X + 1; or X++; BASIC: LET X = X + 1 COBOL: ADD 1 TO X GIVING X PASCAL: X := X + 1 HASKELL: NOT ALLOWED !! INCREMENT X

School of Computing and Engineering, University of Huddersfield ABSTRACT SYNTAX - DEFns: We tend to use abstract “algebraic” notation to abstract away from particular syntax… bit like BNF without the concrete bits: :  ABSTRACT SYNTAX: ( (“Y”), ( (“X”), (“1”)))

School of Computing and Engineering, University of Huddersfield ABSTRACT SYNTAX - Function heading example Bool greater_than(Int x, Int y) (JAVA-like) greater_than(x : integer; y : integer) : integer (PASCAL-like) ABSTRACT constructor: :  Haskell a bit different: greater_than: integer integer --> integer greater_than(x,y) =...

School of Computing and Engineering, University of Huddersfield ABSTRACT SYNTAX RELATED WORKS: - -a compiler starts compiling by turning characters in a program into TOKENS, then turning the token list into an ABSTRACT SYNTAX TREE. - -in Java and Haskell we can use CONSTRUCTORS to construct instances of data types – these are like abstract syntax definitions

School of Computing and Engineering, University of Huddersfield DENOTATIONAL SEMANTICS OF BINARY NUMERALS In a denotational defn, we MAP abstract syntax classes to meanings (explicit objects) in a well known language! e.g. binary, octal, roman numeral => base 10 natural numbers

School of Computing and Engineering, University of Huddersfield BINARY NUMERALS: ABSTRACT SYNTAX 1 :  BinDidgit 0 :  BinDidgit D: BinDigit  BinNum N: BinNum BinDigit  BinNum NB: alternative notation: BinDigit => 1 | 0 BinNum => BinDigit | BinNum; BinDigit

School of Computing and Engineering, University of Huddersfield SEMANTICS meaning function M: -- maps BinNum to Decimals M[D(1)] =1---Rule 1 M[D(0)] = 0 ---Rule 2 M[ N(n,0) ] = M[n] x 2---Rule 3 M[ N(n,1) ] = M[n] x Rule 4

School of Computing and Engineering, University of Huddersfield Binary Numerals: Example Meaning of 101 = M[N(N(D(1),0),1)] = M[N(D(1),0)] x 2 +1 using Rule 4 = (M[D(1)] x 2) x using Rule 3 = (1 x 2 ) x using Rule 1 = 5

School of Computing and Engineering, University of Huddersfield BUT WHAT OF SEMANTICS OF NATURAL NUMBERS? We can give semantics via an algebraic specification (see later in the term) where we gave the essential meaning of “objects” in terms of a set of axioms which relate the syntactic expression -- the axioms say what expressions are equal.

School of Computing and Engineering, University of Huddersfield Giving semantics via algebra: Numbers zero :  Num successor : Num  Num add : Num Num  Num for all x,y in Num add(successor(x),y) = successor(add(x,y)) -- (1) add(zero,y) = y -- (2) add(x,y) = add(y,x) etc PROVE =2 !!!!!

School of Computing and Engineering, University of Huddersfield Haskell The DENOTATIONS of Syntax Classes of Program Languages will be FUNCTIONS IN LAMBDA CALCULUS These can be written in Haskell (~= Gofer) Haskell is: The “standard” pure, lazy functional language Practical: Haskell revision

School of Computing and Engineering, University of Huddersfield Conclusion n Abstract Syntax / Abstract Syntax Definitions are important as we use them to decompose the language into different ‘constructs’ in a way that abstracts away particular syntax forms. n For each construct we can then give a (composite) semantic definition. n The semantics of the language is then defined in terms of the semantics of each individual construct.