C LAUS B RABRAND © S EMANTICS (Q1,’05) S EP 1, 2005 C LAUS B RABRAND © 2005, University of Aarhus [ ] [

Slides:



Advertisements
Similar presentations
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
Advertisements

Semantics Q S EMANTICS (Q1,’07) Week 1 Jacob Andersen PhD student
CSE 425: Semantic Analysis Semantic Analysis Allows rigorous specification of a program’s meaning –Lets (parts of) programming languages be proven correct.
ISBN Chapter 3 Describing Syntax and Semantics.
CS 355 – Programming Languages
CS21 Decidability and Tractability
Lecture 02 – Structural Operational Semantics (SOS) Eran Yahav 1.
C LAUS B RABRAND S EMANTICS (Q1,’05) S EP 8, 2005 C LAUS B RABRAND © 2005, University of Aarhus [ ] [
1 Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications.
Programming Language Semantics Mooly SagivEran Yahav Schrirber 317Open space html://
C LAUS B RABRAND Inference Systems J AN 27, 2009 I NFERENCE S YSTEMS Claus Brabrand IT University of Copenhagen [
C LAUS B RABRAND S EMANTICS (Q1,’05) S EP 8, 2005 C LAUS B RABRAND © 2005, University of Aarhus [ ] [
C LAUS B RABRAND © S EMANTICS (Q1,’06) S EP 3, 2006 C LAUS B RABRAND © 2005–2006, University of Aarhus [ ] [
Deterministic FA/ PDA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 4 Updated by Marek Perkowski.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Operational Semantics.
C SC 473 Automata, Grammars & Languages Automata, Grammars and Languages Discourse 01 Introduction.
1 Semantics Q S EMANTICS (Q1,’07) Week 2 Jacob Andersen PhD student
1 Semantics Q S EMANTICS (Q1,’07) Week 3 Jacob Andersen PhD student
C LAUS B RABRAND © S EMANTICS (Q1,’06) A UG 31, 2006 C LAUS B RABRAND © 2005–2006, University of Aarhus [ ] [
C LAUS B RABRAND S EMANTICS (Q1,’06) S EP 14, 2006 C LAUS B RABRAND © , University of Aarhus [ ] [
1 Semantics Q S EMANTICS (Q1,’07) Week 4 Jacob Andersen PhD student
C LAUS B RABRAND & J ACOB A NDERSEN © S EMANTICS (Q1,’07) Aug 30, 2007 Adapted version for dSem 2007 Original story by: C LAUS B RABRAND © 2005–2006, University.
Operational Semantics Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Describing Syntax and Semantics
C LAUS B RABRAND S EMANTICS (Q1,’06) S EP 7, 2006 C LAUS B RABRAND © , University of Aarhus [ ] [
C LAUS B RABRAND S EMANTICS (Q1,’06) S EP 21, 2006 C LAUS B RABRAND © , University of Aarhus [ ] [
C LAUS B RABRAND S EMANTICS (Q1,’05) S EP 22, 2005 C LAUS B RABRAND © 2005, University of Aarhus [ ] [
Finite State Machines Data Structures and Algorithms for Information Processing 1.
Formal Language Finite set of alphabets Σ: e.g., {0, 1}, {a, b, c}, { ‘{‘, ‘}’ } Language L is a subset of strings on Σ, e.g., {00, 110, 01} a finite language,
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 7 Mälardalen University 2010.
Syntax & Semantic Introduction Organization of Language Description Abstract Syntax Formal Syntax The Way of Writing Grammars Formal Semantic.
DECIDABILITY OF PRESBURGER ARITHMETIC USING FINITE AUTOMATA Presented by : Shubha Jain Reference : Paper by Alexandre Boudet and Hubert Comon.
A New Look at LR(k) Bill McKeeman, MathWorks Fellow for Worcester Polytechnic Computer Science Colloquium February 20, 2004.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 2.
1 Chapter 2 Finite Automata (part b) Windmills in Holland.
CSCI 2670 Introduction to Theory of Computing September 15, 2005.
PART I: overview material
Chapter Twenty-ThreeModern Programming Languages1 Formal Semantics.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
CS 363 Comparative Programming Languages Semantics.
Formal Semantics Chapter Twenty-ThreeModern Programming Languages, 2nd ed.1.
Copyright © Curt Hill Languages and Grammars This is not English Class. But there is a resemblance.
Bernd Fischer RW713: Compiler and Software Language Engineering.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
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,
1 / 48 Formal a Language Theory and Describing Semantics Principles of Programming Languages 4.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications Chapter.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
C HAPTER 3 Describing Syntax and Semantics. D YNAMIC S EMANTICS Describing syntax is relatively simple There is no single widely acceptable notation or.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen Department of Computer Science University of Texas-Pan American.
Formal Semantics of Programming Languages 虞慧群 Topic 2: Operational Semantics.
Operational Semantics Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
CSCI 2670 Introduction to Theory of Computing September 16, 2004.
Program Analysis and Verification Noam Rinetzky Lecture 2: Operational Semantics 1 Slides credit: Tom Ball, Dawson Engler, Roman Manevich, Erik.
Chapter 1 INTRODUCTION TO THE THEORY OF COMPUTATION.
Describing Syntax and Semantics
CS510 Compiler Lecture 4.
CIS Automata and Formal Languages – Pei Wang
CSE 105 theory of computation
Intro to Data Structures
CSE 105 theory of computation
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
COMPILER CONSTRUCTION
CSE 105 theory of computation
Presentation transcript:

C LAUS B RABRAND © S EMANTICS (Q1,’05) S EP 1, 2005 C LAUS B RABRAND © 2005, University of Aarhus [ ] [ ] S EMANTICS (Q1,’05) W EEK 1

C LAUS B RABRAND S EMANTICS (Q1,’05) [ 2 ] S EP 1, 2005 Week 1 - Outline Introduction Welcome Course Presentation [ homepage ]homepage Prerequisitional (discrete) Mathematics Relations Inference Systems Transition Systems The Language “L” Virtual Machine Semantics

C LAUS B RABRAND © S EMANTICS (Q1,’05) S EP 1, 2005 I NFERENCE S YSTEMS Keywords: relations, axioms, rules, (co-)inductive interpretation, fixed-points

C LAUS B RABRAND S EMANTICS (Q1,’05) [ 4 ] S EP 1, 2005 Relations Example 1 : “even” relation: Written as: as a short-hand for: … and as: as a short-hand for: Example 2 : “equals” relation: Written as: as a short-hand for: … and as: as a short-hand for: Example 3 : “DFA transition” relation: Written as: as a short-hand for: … and as: as a short-hand for: | _ even  Z | _ even 4 | _ even 5 4  | _ even 5  | _ even 2  3 (2,3)  ‘=’ ‘=’  Z  Z (2,2)  ‘=’ 2 = 2 ‘  ’  Q    Q q  q’  (q, , q’)  ‘  ’ (p, , p’)  ‘  ’p  p’ 

C LAUS B RABRAND S EMANTICS (Q1,’05) [ 5 ] S EP 1, 2005 Inference System Inference System: Inductive (recursive) specification of relations Consists of axioms and rules Example: Axiom: “0 (zero) is even”! Rule: “If n is even, then m is even (where m = n+2)” | _ even 0 | _ even n | _ even m m = n+2 | _ even  Z

C LAUS B RABRAND S EMANTICS (Q1,’05) [ 6 ] S EP 1, 2005 Terminology Meaning: “If n is even, then m is even (provided m = n+2)”; or “m is even, if n is even (provided m = n+2)” | _ even n | _ even m m = n+2 premise(s) conclusion side-condition(s)

C LAUS B RABRAND S EMANTICS (Q1,’05) [ 7 ] S EP 1, 2005 Abbreviation Often, rules are abbreviated: Rule: “If n is even, then m is even (provided m = n+2)”; or “m is even, if n is even (provided m = n+2)” Abbreviated rule: “If n is even, then n+2 is even”; or “n+2 is even, if n is even” | _ even n | _ even n+2 | _ even n | _ even m m = n+2

C LAUS B RABRAND S EMANTICS (Q1,’05) [ 8 ] S EP 1, 2005 Even Example (cont’d) Axiom: “0 (zero) is even”! Rule: “If n is even, then n+2 is even” Is 6 even?!? The inference tree proves that: | _ even 0 | _ even 2 | _ even 4 | _ even 6 | _ even 0 | _ even n | _ even n+2 [rule 1 ] [axiom 1 ] inference tree | _ even 6

C LAUS B RABRAND S EMANTICS (Q1,’05) [ 9 ] S EP 1, 2005 Relation Definition (Interpretation) Actually, an inference system: …is a demand specification for a relation: The three relations: R = {0, 2, 4, 6, …}(aka., 2N) R’ = {0, 2, 4, 5, 6, 7, 8, …} R’’ = {…, -2, -1, 0, 1, 2, …}(aka., Z) …all satisfy the (above) specification! | _ even 0 | _ even n | _ even n+2 [rule 1 ] [axiom 1 ] | _ even  Z (0  ‘| _ even ’)  (  n  ‘| _ even ’  n+2  ‘| _ even ’)

C LAUS B RABRAND S EMANTICS (Q1,’05) [ 10 ] S EP 1, 2005 Inductive Interpretation A relation: …induces a function: Definition: ‘lfp’ (least fixed point) ~ least solution: | _ even 0 | _ even n | _ even n+2 [rule 1 ] [axiom 1 ] F: P(Z)  P(Z) | _ even  Z F(R) = {0}  { n+2 | n  R } F(Ø) = {0}F 2 (Ø) = F({0}) = {0,2}F 3 (Ø) = F 2 ({0}) = F({0,2}) = {0,2,4} … | _ even := lfp(F) =  F n (Ø) n | _ even  P(Z) From rel. to rel. 2N   = F n (Ø) ~ “Anything that can be proved in ‘n’ steps” 

C LAUS B RABRAND S EMANTICS (Q1,’05) [ 11 ] S EP 1, 2005 Co-inductive Interpretation (  ) A relation:  …induces a function: Definition: ‘gfp’ (greatest fixed point) ~ greatest solution: | _ even 0 | _ even n | _ even n+2 [rule 1 ] [axiom 1 ] F: P(Z)  P(Z) | _ even  Z F(R) = {0}  { n+2 | n  R } F(Z) = Z | _ even := gfp(F) =  F n (Z) n | _ even  P(Z) From rel. to rel. F 2 (Z) = F(Z) = Z  F 3 (Z) = F 2 (Z) = F(Z) = Z  … Z  = F n (Z) ~ “Anything that cannot be disproved in ‘n’ steps”

C LAUS B RABRAND S EMANTICS (Q1,’05) [ 12 ] S EP 1, 2005 Example: “less-than-or-equal-to” Relation: Is ”1  2” ?!? Yes, because there exists an inference tree: In fact, it has two inference trees: 0  0 n  m n  m+1 [rule 1 ] [axiom 1 ] ‘  ’  N  N n  m n+1  m+1 [rule 2 ] 0  0 0  1 1  2 [rule 2 ] [rule 1 ] [axiom 1 ] 0  0 1  1 1  2 [rule 1 ] [rule 2 ] [axiom 1 ]

C LAUS B RABRAND © S EMANTICS (Q1,’05) S EP 1, 2005 T RANSITION S YSTEMS Keywords: Configuration, Final Configuration, Transition, Action / label

C LAUS B RABRAND S EMANTICS (Q1,’05) [ 14 ] S EP 1, 2005 Definition: Transition System A Transition System is (just) a structure:  is a set of configurations      is a binary relation (called the transition relation) We will write instead of Other times we use the following notation:  ,     ’  ’( ,  ’)     ’  ’  |_ ’ |_ ’   ’  ’ …

C LAUS B RABRAND S EMANTICS (Q1,’05) [ 15 ] S EP 1, 2005 The transition may be illustrated as: We will (often) be using: For instance: A Transition   ’  ’ ’’  = system configuration = 

C LAUS B RABRAND S EMANTICS (Q1,’05) [ 16 ] S EP 1, 2005 Def: Terminal Transition System A Terminal Transition System is a structure:  is the set of configurations      is the transition relation T   is a set of final configurations …satisfying: i.e. “all configurations in ‘T’ really are terminal”.  , , T     T :   ’   :    ’

C LAUS B RABRAND S EMANTICS (Q1,’05) [ 17 ] S EP 1, 2005 Example: Finite Automaton A Finite Automaton (FA) is a quintuplet: Q finite set of states  finite set of input symbols q 0  Qinitial state F  Qset of acceptance states  : Q    P(Q)state transition relation M =  Q, , q 0, F,   Q = { 0,1,2 }  = {  = { toss,heads,tails } (0,toss)  {1,2}, q 0 = 0 (1,heads)  {0}, F = { 0 } (2,tails)  {0} }

C LAUS B RABRAND S EMANTICS (Q1,’05) [ 18 ] S EP 1, 2005 Example: FA Transition System (1) Define (FA) Trans. Sys. by: Configurations: Transition relation: i.e., we have whenever Final Configurations:  M := Q   *   M,  M, T M  T M := { | q  F }  M := { (, ) | q,q’  Q, a , w  *, q’  (q,a) } “State component” “Data component” q’   (q,a)  M Recall:     

C LAUS B RABRAND S EMANTICS (Q1,’05) [ 19 ] S EP 1, 2005 Example: FA Trans. Sys. (Cont’d) Behavior:  M  T M L(M) := { w   * |  T :  *  }

C LAUS B RABRAND S EMANTICS (Q1,’05) [ 20 ] S EP 1, 2005 Def: Labelled Transition System A Labelled Transition System is a structure:  is the set of configurations A is the set of actions (= labels)     A   is the transition relation Note: we will write instead of  , A,     ’  ’ a ( , a,  ’)  ‘  ’

C LAUS B RABRAND S EMANTICS (Q1,’05) [ 21 ] S EP 1, 2005 The labelled transition may be illustrated as: The labels(/actions) add the opportunity of describing transitions: Internally (e.g., information about what went on internally) Externally (e.g., information about communication /w env) …or both. A Labelled Transition   ’  ’ ’’ a a

C LAUS B RABRAND S EMANTICS (Q1,’05) [ 22 ] S EP 1, 2005 Example: FA Transition System (2) Given Finite Automaton: Define Labelled Terminal Transition System: Configurations: Labels: Transition relation: Final configurations:  M := Q   M, A M,  M, T M  T M := F q  M q’ := q’  (q,a) A M :=  a M =  Q, , q 0, F,  

C LAUS B RABRAND S EMANTICS (Q1,’05) [ 23 ] S EP 1, 2005 Example: FA Trans. Sys. (Cont’d) Behavior: Define ”  *” as the transitive closure of ”  ” on sequences of labels: 0  M 1  M 0  M 2  M 0  T M L(M) := { w  A* |  q  T : q 0  * q w toss heads toss tails L(M) := { a a’ … a’’  A* |  q  T : q 0  q’  …  q a a’ a’’

C LAUS B RABRAND S EMANTICS (Q1,’05) [ 24 ] S EP 1, 2005 FA: Machine 1 vs. Machine 2 The two transition systems are very different: Machine 1: ”I transitioned from to ” Implicit: ”…by consuming part of (internal) data component” Machine 2: ”I transitioned from q to q’ …by inputing an ’a’ symbol from the (external) environment!”  M q  M q’ a

C LAUS B RABRAND S EMANTICS (Q1,’05) [ 25 ] S EP 1, 2005 More Examples… More Examples in [Plotkin, p. 6 – 13]: Three Counter Machine (***) Context-Free Grammars (**) Petri Nets (*) They illustrate expressive power of transition systems no new points...except formalizing input/output behavior (also later here…) Read these yourself…

C LAUS B RABRAND © S EMANTICS (Q1,’05) S EP 1, 2005 T HE L ANGUAGE “L” Keywords: Expressions, Boolean Expressions, Commands, Abstract Syntax, Concrete Syntax

C LAUS B RABRAND S EMANTICS (Q1,’05) [ 27 ] S EP 1, 2005 The Language ”L” Basic Syntactic Sets: Truthvalues: Set ranged over by: t, t’, t 0, … Numbers: Set ranged over by: m, n, … Variables: Set ranged over by: v, v’, … T = { tt, ff } N = { 0, 1, 2, …} VAR = { a, b, c, …, z } Meta-variables

C LAUS B RABRAND S EMANTICS (Q1,’05) [ 28 ] S EP 1, 2005 The Language ”L” Derived Syntactic Sets: Arithmetic Expressions ( e  Exp): Boolean Expressions ( b  BExp): Commands ( c  Com): e ::= n | v | e + e’ | e – e’ | e  e’ b ::= t | e = e’ | b or b’ | ~ b c ::= nil | v := e | c ; c’ | if b then c else c’ | while b do c

C LAUS B RABRAND S EMANTICS (Q1,’05) [ 29 ] S EP 1, 2005 Consider program: It can be (ambiguously) understood: Note: Abstract- vs. Concrete Syntax while b do c ; c’  while b do c  ; c’while b do  c ; c’  …either as: …or as: “Concrete syntax” while b c ; c’ while b c ; c’ “Abstract syntax” Parsing: “Concrete syntax”  “Abstract syntax”

C LAUS B RABRAND © S EMANTICS (Q1,’05) S EP 1, 2005 V IRTUAL M ACHINE S EMANTICS Keywords: The “SMC” Machine, Virtual Machine Semantics, Machine Code Semantics

C LAUS B RABRAND S EMANTICS (Q1,’05) [ 31 ] S EP 1, 2005 Value Stack: Set ranged over by: S Memories: Functions ranged over by: M Control Stack: Set ranged over by: C SMC Machine (Trans. Sys. Semantics): Configurations: Virtual Machines ( SMC Expressions )  =  Value Stack  Memories  Control Stack  ( T  N )* VAR  N ( Exp  { +, –,  } )* Initially Commands, and later bits of commands For accumulating partial results

C LAUS B RABRAND S EMANTICS (Q1,’05) [ 32 ] S EP 1, 2005 Configurations: Notation: i.e., “Memory Update” More common syntax for this: Memory Update  =     ( T  N  VAR )* VAR  N ( Exp  { +, –,  } )* m, if v = v’ M’(v’) = M(v’), otherwise M[m/v] M[m/v] = M’ where M[m  v]

C LAUS B RABRAND S EMANTICS (Q1,’05) [ 33 ] S EP 1, 2005 Virtual Machine Transitions Configurations: Transitions: Defined by case according to top of control stack:  =     ( T  N  VAR )* VAR  N ( Exp  { +, –,  } )* [case n ]:  [case v ]:  [case e  e’ ]:  [case + / - /  ]:  …where n = m  m’ Syntactic ‘+’ Semantic ‘+’

C LAUS B RABRAND S EMANTICS (Q1,’05) [ 34 ] S EP 1, 2005 Virtual Machine: Example Given program: and memory: (((x + 1) – y)  7)  M = [x=9,y=4]         

C LAUS B RABRAND S EMANTICS (Q1,’05) [ 35 ] S EP 1, 2005 VM Semantics: Major Drawbacks! Advantage: Easy to implement (and efficient) Drawbacks: Non-intuitive  Too concrete (e.g., stack)  Indirect semantics (not syntax directed)  Computational step?  “High-level language understood in terms of low-level machine code” “Many other machine along these lines […]. They all have a tendency to pull the syntax into pieces or at any rate to wander around the syntax creating various complex symbolic structures which do not seem particularly forced by the demands of the language itself” - Gordon Plotkin, ‘81

C LAUS B RABRAND © S EMANTICS (Q1,’05) S EP 1, 2005 N EXT W EEK… Semantics of…: “ Simple Commands and Expressions”

C LAUS B RABRAND S EMANTICS (Q1,’05) [ 37 ] S EP 1, 2005 Next week Use everything…: Inference Systems, Transition Systems, Syntax, … …to: describe explain analyse compare …semantics of Expressions:

C LAUS B RABRAND © S EMANTICS (Q1,’05) S EP 1, 2005 See you next week… Questions?