Graph-Based Operational Semantics

Slides:



Advertisements
Similar presentations
Dataflow Analysis for Datarace-Free Programs (ESOP 11) Arnab De Joint work with Deepak DSouza and Rupesh Nasre Indian Institute of Science, Bangalore.
Advertisements

Static Single-Assignment ? ? Introduction: Over last few years [1991] SSA has been Stablished as… Intermediate program representation.
Semantics Static semantics Dynamic semantics attribute grammars
Intermediate Code Generation
Exercise 1 Generics and Assignments. Language with Generics and Lots of Type Annotations Simple language with this syntax types:T ::= Int | Bool | T =>
Analysis of programs with pointers. Simple example What are the dependences in this program? Problem: just looking at variable names will not give you.
3-Valued Logic Analyzer (TVP) Tal Lev-Ami and Mooly Sagiv.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
CS7100 (Prasad)L16-7AG1 Attribute Grammars Attribute Grammar is a Framework for specifying semantics and enables Modular specification.
1 Compiler Construction Intermediate Code Generation.
Getting started with ML ML is a functional programming language. ML is statically typed: The types of literals, values, expressions and functions in a.
Program Representations. Representing programs Goals.
Model checking dynamic states in GROOVE Arend Rensink Formal Methods and Tools University of Twente.
1 Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications.
30 March 2005, IPA lentedagen, BredaGraph-Based State Spaces1 Graph Transformation for Model Transformation Arend Rensink University of Twente.
Functional programming: LISP Originally developed for symbolic computing Main motivation: include recursion (see McCarthy biographical excerpt on web site).
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Kernel language semantics Carlos Varela RPI Adapted with permission.
Programming Language Semantics Mooly SagivEran Yahav Schrirber 317Open space html://
Semantics with Applications Mooly Sagiv Schrirber html:// Textbooks:Winskel The.
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
Recap from last time: live variables x := 5 y := x + 2 x := x + 1 y := x y...
Operational Semantics Semantics with Applications Chapter 2 H. Nielson and F. Nielson
CSE 413 Programming Languages & Implementation Hal Perkins Autumn 2012 Context-Free Grammars and Parsing 1.
Behaviour-Preserving Model Transformation Arend Rensink, University of Twente IPA Spring Days, 18 April 2012.
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 10, 10/30/2003 Prof. Roy Levow.
Validated Model Transformation Tihamér Levendovszky Budapest University of Technology and Economics Department of Automation and Applied Informatics Applied.
1 Graph-Based State Spaces Arend Rensink, University of Twente CamPaM 2012 April 2012Graph-Based State Spaces.
Chapter 3 Part II Describing Syntax and Semantics.
1 Groove demo (sf.net/projects/groove) Arend Rensink, University of Twente Computer Automated Multi-Paradigm Modelling, April 2012 April 2012Computer Automated.
Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications Chapter.
Formal Semantics of Programming Languages 虞慧群 Topic 2: Operational Semantics.
Operational Semantics Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
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
Credible Compilation With Pointers Martin Rinard and Darko Marinov Laboratory for Computer Science Massachusetts Institute of Technology.
LECTURE 10 Semantic Analysis. REVIEW So far, we’ve covered the following: Compilation methods: compilation vs. interpretation. The overall compilation.
Manuel Fahndrich Jakob Rehof Manuvir Das
Operational Semantics of Scheme
Chapter 3 – Describing Syntax
Compiler Design – CSE 504 Type Checking
Context-Sensitive Analysis
Parsing & Context-Free Grammars
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 5, 09/25/2003 Prof. Roy Levow.
Chapter 3 – Describing Syntax
Interpreters Study Semantics of Programming Languages through interpreters (Executable Specifications) cs7100(Prasad) L8Interp.
Abstract Syntax Trees Lecture 14 Mon, Feb 28, 2005.
Syntax versus Semantics
Compiler Construction (CS-636)
Declarative Computation Model Kernel language semantics (Non-)Suspendable statements (VRH ) Carlos Varela RPI October 11, 2007 Adapted with.
Parsing & Context-Free Grammars Hal Perkins Autumn 2011
Compiler Design 4. Language Grammars
(Slides copied liberally from Ruth Anderson, Hal Perkins and others)
The Metacircular Evaluator
Over-Approximating Boolean Programs with Unbounded Thread Creation
Lecture 7: Introduction to Parsing (Syntax Analysis)
Representation, Syntax, Paradigms, Types
The Metacircular Evaluator
The Metacircular Evaluator (Continued)
Declarative Computation Model Single assignment store (VRH 2
6.001 SICP Interpretation Parts of an interpreter
Parsing & Context-Free Grammars Hal Perkins Summer 2004
Introduction to Graph Transformation
Assignments and Procs w/Params
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Model Checking Graph Grammars
Parsing & Context-Free Grammars Hal Perkins Autumn 2005
Procedure Linkages Standard procedure linkage Procedure has
COMPILER CONSTRUCTION
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 2, 09/04/2003 Prof. Roy Levow.
Visual Programming Languages ICS 539 Icon System Visual Languages & Visual Programming, Chapter 1, Editor Chang, 1990 ICS Department KFUPM Sept. 1,
Presentation transcript:

Graph-Based Operational Semantics Kaminski, Seidl et al. Muscholl Estonian Summer School on Computer and Systems Science Lecture 2 Arend Rensink, University of Twente

Graph-Based Operational Semantics Seen yesterday Graphs and morphisms Graphs: Tuples of nodes, labels, edges Morphisms: node and edge mappings State invariants as graph properties Graph transformation rules Single-graph and multi-graph representation Rule applications as pushouts Negative application conditions GROOVE tool State space generation Graphs as states Graph productions as transitions ESSCASS Lecture 2, 26 August 2007 Graph-Based Operational Semantics

Graph-Based Language Semantics Program (textual) Abstract Syntax Graph compilation Program Graph flow graph construction Execution Graphs simulation Syntax level Semantic level Execution Graphs Execution Graphs Here, we directly start with flow graphs ESSCASS Lecture 2, 26 August 2007 Graph-Based Operational Semantics

Graph-Based Operational Semantics Flow graph simulation Flow type graph Solution for inheritance? Multiple “node labels” Any Procedure-node also labelled Element Element true Procedure Stop flow Predicate Start false ESSCASS Lecture 2, 26 August 2007 Graph-Based Operational Semantics

Build instance graphs using grammar Graph rules for visual “flow language” Compare: textual (context-free) rules Elem ::= Seq | Cond | Stop Seq ::= Proc SEMI Elem Proc ::= ... | Start Cond ::= IF Pred THEN Elem ELSE Elem create Pred create Stop merge: creates cycles create Proc temporary edge start graph ESSCASS Lecture 2, 26 August 2007 Graph-Based Operational Semantics

Simulation using a graph grammar Execution type graph pc initially points to Start pc-edge follows flow, true and false Thread pc Element true Procedure Stop flow Predicate Start false ESSCASS Lecture 2, 26 August 2007 Graph-Based Operational Semantics

Graph-Based Operational Semantics Simulation rules Initial rule Create Thread and pc if it does not exist Flow rules One per program construct regular expression ESSCASS Lecture 2, 26 August 2007 Graph-Based Operational Semantics

Extending the language Boring: simulation copies flow graph! Exercise: add Fork-statement to type graph to construction grammar to simulation grammar Effect: Fork creates a new Thread with pc-edge pointing to well-defined Start threads are unnamed no Join possible ESSCASS Lecture 2, 26 August 2007 Graph-Based Operational Semantics

Graph-Based Operational Semantics Modular extension Flow graph: Construction rule: Element true Procedure Stop flow Predicate Start false run Fork Simulation rule: ESSCASS Lecture 2, 26 August 2007 Graph-Based Operational Semantics

Textual operational semantics BNF grammar Stat ::= Prim | Skip | Seq | Block | If | While Seq ::= Stat Stat Block ::= LBRACE Stat RBRACE If ::= IF Cond Stat ELSE Stat While ::= WHILE Cond Stat Derivation rules per statement type Premisses and conclusion are predicates Transitions Stat  Stat’ Termination Stat Premisse1 Premisse2 … Conclusion ESSCASS Lecture 2, 26 August 2007 Graph-Based Operational Semantics

Rules for the textual language (1) Basic Sequential Block Prim ! Skip Skip  Stat1 ! Stat1’ Stat1 Stat2 ! Stat1’ Stat2 Stat1 Stat2 ! Stat2’ Stat1 Stat2 ! Stat2’ Stat1 Stat2  Stat1 Stat2  Stat ! Stat’ { Stat } ! Stat’ Stat  { Stat }  ESSCASS Lecture 2, 26 August 2007 Graph-Based Operational Semantics

Rules for the textual language (2) If While nondeterminism: condition not regarded if Cond Stat1 else Stat2 ! Stat1 if Cond Stat1 else Stat2 ! Stat2 while Cond Stat ! Stat while Cond Stat while Cond Stat ! Skip ESSCASS Lecture 2, 26 August 2007 Graph-Based Operational Semantics

Example textual semantics Program: while (c1) { if (c2) p1 else if (c3) { p2; p3 } else ; } p4 Semantics w ;w i1 i2 w i1 i2 p1 p4 p2 p3 ESSCASS Lecture 2, 26 August 2007 Graph-Based Operational Semantics

Extending the language How about Fork? Stat ::= … | Fork Fork ::= FORK Stat Extend the semantic predicates Transitions S1 | S2 | …  S1’ | S2’ | … for vectors of Stats Less modular than for graph-based rules! fork Stat ! Skip | Stat S1 ! S1’ | S1’’ S1 S2 ! S1’ S2 | S1’’ S1 ! S1’ … | S1 | … ! … | S1’ | … ESSCASS Lecture 2, 26 August 2007 Graph-Based Operational Semantics

Example textual semantics Program: p1; fork { if (c1) p2 } while (c2) p3 Semantics p1 w i w i p2 p3 ;w ESSCASS Lecture 2, 26 August 2007 Graph-Based Operational Semantics

Difference visual/textual semantics Aspect Textual Visual Derivation method proof tree (derivation) pushout (one-shot) Syntax term: manipulated graph: fixed Context in rules? no (context free, compositional) yes (context sensitive, whole-world) Mathematical structure ad hoc (non-uniform) graph (uniform) ESSCASS Lecture 2, 26 August 2007 Graph-Based Operational Semantics

Overall framework for GT semantics Abstract Syntax Graph: control flow added - variables resolved Run-Time Graph: - data values - heap structure - stack structure fixed points to adapted Operational rules manipulate run-time graph Track program (control) location Perform data calculations Add & delete heap slots ESSCASS Lecture 2, 26 August 2007 Graph-Based Operational Semantics

Graph-Based Operational Semantics Modelling data Simple structures Singly-linked lists Global variables: x, y etc Dereferencing: x^, y^ etc Assignments (= procedure nodes), e.g.: x^ = y (assigns y to x’s out-reference) x = y^ (halts if y has no out-reference) x = new (assigns new node to x) Comparisons (in predicates), e.g.: x == y x == null (true if x points to node for null) ESSCASS Lecture 2, 26 August 2007 Graph-Based Operational Semantics

Example: List reversal Program while (v != null) { t = w; w = v; v = v^; w^ = t; } Global variables v: contains the initial list w: should contain the result list, initially null t: auxiliary variable, initially null Initial state Example: v w t Nil ESSCASS Lecture 2, 26 August 2007 Graph-Based Operational Semantics

Representation choices Variables become nodes (not edges) Value represented by outgoing pointer Advantages: Uniformity with list nodes One rule for assignment rather than per variable Special node for null Alternative: null value = “no pointer” Advantages No case distinctions in rules, e.g. comparison Missing pointer always an error (except for null) ESSCASS Lecture 2, 26 August 2007 Graph-Based Operational Semantics

Extended syntax type graph Element true flow false Proc Stop Pred Compare condition Assign left right Target left right Expr Indir Dir Create Deref Alias Null Eq Neq Ident id id ESSCASS Lecture 2, 26 August 2007 Graph-Based Operational Semantics

Graph-Based Operational Semantics Example syntax rules Elem-Pred Elem-Proc Proc-Assign Elem-merge Compare-Eq Target-Dir Expr-Alias Expr-Create ESSCASS Lecture 2, 26 August 2007 Graph-Based Operational Semantics

List reversal syntax graph Complete Flow Assigns Assigns with variables ESSCASS Lecture 2, 26 August 2007 Graph-Based Operational Semantics

Graph-Based Operational Semantics Language choices Assignment and expression distinct Alternative: Assign a subcategory of Expr Conditions and expressions distinct For simplicity Occur in distinct contexts (no boolean vars) Alternative: Condition as boolean expression No nested expressions Extension rather straightforward Identifiers already resolved One node per variable ESSCASS Lecture 2, 26 August 2007 Graph-Based Operational Semantics

Typing the run-time graphs Variable for instantiated Idents Run-time variable distinct from syntax! Global variables: one instance per Ident Pointer id from Var to corresponding Ident Object for structures on the heap Outgoing pointer val to next Object Special object Nil (distinct from syntax!) Var also modelled as a special Object Auxiliary nodes for expression values Pointer at from Aux to corresponding Expr Alternative: introduce a stack ESSCASS Lecture 2, 26 August 2007 Graph-Based Operational Semantics

Run-time type graph: Expressions abstract Store val 0..1 no incoming val no outgoing val Var Nil Aux Obj Expr (from syntax) at Ident (from syntax) id singleton ESSCASS Lecture 2, 26 August 2007 Graph-Based Operational Semantics

Run-time type graph: Conditions no confusion due to distinct contexts Aux val Condition (from syntax) at Boolean singletons False True ESSCASS Lecture 2, 26 August 2007 Graph-Based Operational Semantics

List reversal initial state ESSCASS Lecture 2, 26 August 2007 Graph-Based Operational Semantics

Generic representation choices No arrows from syntax to run-time Use singletons where required Auxiliary nodes for intermediate values Extra indirectional layer High-level graph structure Program graph: syntax, flow, name resolution Value graph: heap, global values & variables Frame graph: stack, local variables, threads ESSCASS Lecture 2, 26 August 2007 Graph-Based Operational Semantics

Operational rules: Initialisation init True init False init Nil init Var init Thread ESSCASS Lecture 2, 26 August 2007 Graph-Based Operational Semantics

Operational rules: Expressions Alias Deref Create Null ESSCASS Lecture 2, 26 August 2007 Graph-Based Operational Semantics

Other operational rules Assign-Dir Condition-Eq (failed) Pred-False ESSCASS Lecture 2, 26 August 2007 Graph-Based Operational Semantics

Graph-Based Operational Semantics Seen today Visual and textual operational semantics With and without parallelism Statements and expressions with data Type graph and instances Graph structure Program graph Frame graph Value graph Operational semantics One or two rules per syntax construct Completely modular ESSCASS Lecture 2, 26 August 2007 Graph-Based Operational Semantics