Model-Driven Language Engineering

Similar documents
Model-Driven Language Engineering. Franck Fleurey

ThingML: A Modelling Language for the Internet of Things

Introduction to Dependable Systems: Meta-modeling and modeldriven

Model Driven Engineering (MDE)

Kermeta Language Overview

Grammars. Prof. Andreas Prinz. Introduction, Compilers. Examples Meta-models vs. Grammars Summary

Meta-modeling with OCL & KerMeta

The Eclipse Modeling Framework and MDA Status and Opportunities

Metamodeling with Metamodels. Using. UML/MOF including OCL

Model Transformation Techniques

Compositional Model Based Software Development

Model Querying with Graphical Notation of QVT Relations

Weaving Executability into Object-Oriented Meta-Languages

Introduction to MDE and Model Transformation

Introduction to OpenArchitectureWare

Defining Domain-Specific Modeling Languages

ECLIPSE MODELING PROJECT

Outline. A little history. Outline. The Unified Modeling Language Opportunities and Challenges for Formal Methods

MDD with OMG Standards MOF, OCL, QVT & Graph Transformations

with openarchitectureware

Model-Driven Engineering (MDE) Lecture 1: Metamodels and Xtext Regina Hebig, Thorsten Berger

Kermeta tutorial. How to create a metamodel. François Tanguy, Didier Vojtisek. Abstract

ATL: Atlas Transformation Language. ATL User Manual

ADT: Eclipse development tools for ATL

challenges in domain-specific modeling raphaël mannadiar august 27, 2009

Metamodeling. 16. April 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 1

INF5120 Modellbasert Systemutvikling Modelbased System development

It s all Done with Mirrors Patterns and OCL. KMF Kent Modelling Framework D.H.Akehurst and O.Patrascoiu

Model Transformations for Embedded System Design and Virtual Platforms

Software Industrialization

Static analysis and testing of executable DSL specification

Computation Independent Model (CIM): Platform Independent Model (PIM): Platform Specific Model (PSM): Implementation Specific Model (ISM):

Design and Prototypical Implementation of a Pivot Model as Exchange Format for Models and Metamodels in a QVT/OCL Development Environment

Compiler construction

Ingegneria del Software Corso di Laurea in Informatica per il Management. Introduction to UML

Developing Web-Based Applications Using Model Driven Architecture and Domain Specific Languages

Model transformations. Overview of DSLE. Model transformations. Model transformations. The 4-layer architecture

Christian Doppler Laboratory

Advanced Topics in Software Engineering (02265) Ekkart Kindler

Model Transformation Testing Challenges

Language engineering and Domain Specific Languages

Automation of Semantic Web based Digital Library using Unified Modeling Language Minal Bhise 1 1

Science of Computer Programming. Aspect-oriented model-driven skeleton code generation: A graph-based transformation approach

UML 2.5: Specification Simplification

Modellierung operationaler Aspekte von Systemarchitekturen. Master Thesis presentation. October 2005 March Mirko Bleyh - Medieninformatik

Softwaretechnik Model Driven Architecture Meta Modeling

Model-driven analysis and synthesis of textual concrete syntax

Program generation for schema-based, typed data access

A Comparison of Ecore and GOPPRR through an Information System Meta Modeling Approach

Model driven Engineering & Model driven Architecture

Metamodeling. Janos Sztipanovits ISIS, Vanderbilt University

Model-Level Integration of the OCL Standard Library Using a Pivot Model with Generics Support

Plan. Language engineering and Domain Specific Languages. Language designer defines syntax. How to define language

INF5120 Modellbasert Systemutvikling Modelbased System development

BLU AGE 2009 Edition Agile Model Transformation

Syntax and Grammars 1 / 21

CSSE 490 Model-Based Software Engineering: Introduction to Domain Engineering

Towards Formalizing Domain-specific Modeling Languages. Kai Chen Janos Sztipanovits Sandeep Neema

The Unified Modelling Language. Example Diagrams. Notation vs. Methodology. UML and Meta Modelling

Dresden OCL2 in MOFLON

A Formal Foundation Supporting MDD --- ZOOM Approach

Sequence Diagram Generation with Model Transformation Technology

Small is Beautiful Building a flexible software factory using small DSLs and Small Models

Index. business modeling syntax 181 business process modeling 57 business rule 40

INF5120 Modelbased System development

DiverSE s Seminar about Software Language Engineering

A Metamodel independent approach for Conflict Detection to support distributed development in MDE. Mostafa Pordel A THESIS

What is Metamodeling and Code Generation All About

Construction of Complex UML Profiles

Eclipse Development Tools for Epsilon

(800) Toll Free (804) Fax Introduction to Java and Enterprise Java using Eclipse IDE Duration: 5 days

Model-Driven Iterative Development of 3D Web-Applications Using SSIML, X3D and JavaScript

Frustrated by all the hype?

Programmiersprachen (Programming Languages)

Coral: A Metamodel Kernel for Transformation Engines

Using Scala for building DSL s

Horváth Ákos Bergmann Gábor Dániel Varró István Ráth

Kermeta. in compiled mode

Reconciling TGGs with QVT

OCL. Heinrich Hussmann, Birgit Demuth, and Frank Finger. Dresden University of Technology, Department of Computer Science

SCENARIO-BASED REQUIREMENTS MODELLING

openarchitectureware 4.1 An introduction

Proceedings of the 6th Educators Symposium: Software Modeling in Education at MODELS 2010 (EduSymp 2010)

Model Driven Engineering

Ontology Summit2007 Survey Response Analysis. Ken Baclawski Northeastern University

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

Semantic Analysis and Type Checking

Introduction to Software Engineering 10. Software Architecture

A Proposed Engine Implementation Mechanism to Execute the Code of Relations Query/View/Transformation Language

Orccad, a Model Driven Architecture and Environment for Real-Time Control. Soraya Arias Florine Boudin Roger Pissard-Gibollet Daniel Simon

All you need are models Anneke Kleppe, Klasse Objecten

Transition from EBNF to Xtext

From Object Composition to Model Transformation with the MDA

USING ABSTRACT STATE MACHINES TO SUPPORT UML MODEL INSTANTIATION CHECKING

Software Engineering: A Practitioner s s Approach, 6/e Roger Pressman. Chapter 28 Formal Methods

ROLE OF OCL AND ITS SUPPORTING TOOLS IN REQUIREMENT SPECIFICATION

Computer Science at Kent

New Programming Paradigms

OMG Modeling Glossary B

Semantic Web Domain Knowledge Representation Using Software Engineering Modeling Technique

Transcription:

Model-Driven Language Engineering Example of the ThingML language Franck Fleurey SINTEF Research Scientist (franck.fleurey@sintef.no) http://www.fleurey.com/franck INF520 - April 202

Language Engineering Programming languages Domain specific languages Modelling languages Who is the user? What is the purpose? INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 2

Abstract syntax Concrete syntax Editor(s) Static semantics Dynamic semantics Interpreter Compiler Debugger Outline INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 3

Model-driven language engineering Traditionally: Grammar / Compilers approaches Modelling Focus on the abstract syntax More flexible concrete syntaxes Better modularity More maintainable INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 4

Example of the ThingML language What is ThingML Name comes from Internet of Things (IoT) Who are the target users? What is the purpose? What are the alternatives? INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 5

What is the Internet of Things (IoT)? INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 6

Example applications Health domain and ambient assisted living Energy domain and smart grids Environmental monitoring and oil and gas Safety in hazardous environments Automotive industry... INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 7

Programming IoT systems Distributed Asynchronous Parallel Event based Imperative programing is not well suited INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 8

ThingML: Architecture Model Robot control Movement control Distance Sensor Collision Sensor Left Wheel control Right Wheel control INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 9

ThingML: Component Reusable unit (Black box) component type (Thing) Wheel Controller Port Messages <= forward(speed:int) <= backward(speed:int) <= stop() => wheel_position(position: int) instances Left Wheel control Right Wheel control INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 0

ThingML: State Machines Wheel Controller Stopped?forward?stop?stop!wheel_position Forward Control Port?backward backward!wheel_position INF520 203 Franck Fleurey (franck.fleurey@sintef.no)

ThingML: Action Language?forward Forward action do motor_set_speed(speed) motor_set_direction(fw) end on entry do reset_wheel_position() motor_start() end... INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 2

ThingML Abstract syntax What are the concepts of the language? Components Instances States Transitions What are the relations between these concepts Tools: EMF, MOF, etc. INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 3

Comparing Abstract Syntax Systems Technology # Technology #2 (formal grammars (MOF + OCL) attribute grammars, etc.) Technology #3 (XML Meta-Language) Technology #4 (Ontology engineering) M 3 EBNF MOF A XML DTD Or Schema Upper Level Ontologies M 2 Pascal Language Grammar The UML meta-model A XML document A XML DTD or Schema KIF Theories M A specific Pascal Program A specific execution of a Pascal program A Specific UML Model A Specific phenomenon corresponding to a UML Model A XML document + Xlink, Xpath, XSLT + RDF, OIL, DAML + etc. [XMI=MOF+XML+OCL] (From J. Bézivin) +Description Logics +Conceptual Graphs +etc. INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 4

ThingML Abstract Syntax INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 5

Abstract syntax State Machines Model a /b x/y S S2 y/x S3 b /a INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 6

Abstract syntax State Machines Model a /b x/y S S2 y/x S3 b /a Meta-Model ow ningfsm * ow nedstate cur rentstate run() FSM reset() 0.. initialstate name: EString step() State source tar get outgoingtrans ition * inc omingtrans ition 0.. Transi tion input: EString output: EString fire() INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 7

What do we get? Model a /b x/y S S2 y/x S3 b /a Meta-Model ow ningfsm * ow nedstate cur rentstate run() FSM reset() 0.. initialstate name: EString step() State source tar get outgoingtrans ition * inc omingtrans ition 0.. Transi tion input: EString output: EString fire() INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 8

Abstract syntax Concrete syntax Editor(s) Static semantics Dynamic semantics Interpreter Compiler Debugger Outline INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 9

Textual vs. Graphical Intermediate Wizards Concrete syntax Important: use standard and/or existing notations for the target users Tools: EMFText, GMF, etc. INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 20

ThingML Concrete syntax Made a attempt at graphical Made an attempt with UML Endded-up with a text-based syntax Built with EMFText INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 2

Blink example state machine Blink Stopped on entry!timer_start(000) thing Blink includes LedMsgs, TimerMsgs { required port HW { sends led_toggle, timer_start receives timer_timeout }?timer_timeout!led_toggle() HW <= timer_timeout() => led_toggle() => timer_start(delay:int) } statechart BlinkImpl init Blinking { state Blinking { on entry HW!timer_start (000) } } transition -> Blinking event HW?timer_timeout action HW!led_toggle () INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 22

Blink example and instance groups led group app: BlinkApplication led: Led Led HW timer HW io group Timer:Timer do: DigitalOutput pin: IOPin Arduino Board configuration BlinkArduino { group led : LedArduino set led.io.digital_output.pin = DigitalPin:PIN_3 // The timer instance timer : TimerArduino // The blink application instance app : Blink connector app.hw => led.led.led connector app.hw => timer.timer } INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 23

Tooling the concrete syntax Parser to the abstract syntax Serialization (pretty-printer) Editor Good editor features Highlighting Outline Completion Navigation EMFText generates an eclipse editor INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 24

ThingML Editor INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 25

Abstract syntax Concrete syntax Editor(s) Static semantics Dynamic semantics Interpreter Compiler Debugger Outline INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 26

Static Semantics with OCL Complementing a meta-model with Well- Formedness Rules, aka Contracts e.g.; A procedure is called with the same number of arguments as specified in its declaration Expressed with the OCL (Object Constraint Language) The OCL is a language of typed expressions. A constraint is a valid OCL expression of type Boolean. A constraint is a restriction on one or more values of (part of) an object-oriented model or system. INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 27

Contracts in OO languages Inspired by the notion of Abstract Data Type Specification = Signature + Preconditions Postconditions Class Invariants Behavioral contracts are inherited in subclasses INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 28

OCL for static semantics Can be used at both M level (constraints on Models)» aka Design-by-Contract (Meyer) M2 level (constraints on Meta-Models)» aka Static semantics Tools: EMF Validation Framework Static constraints can be written in OCL or Java Well integrated with EMFText INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 29

Static semantics example ow ningfsm * ow nedstate cur rentstate run() FSM reset() 0.. initialstate name: EString step() State source tar get outgoingtrans ition * inc omingtrans ition 0.. Transi tion input: EString output: EString fire() Context FSM inv: ownedstate->forall(s,s2 s.name=s2.name implies s=s2) INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 30

Abstract syntax Concrete syntax Editor(s) Static semantics Dynamic semantics Interpreter Compiler Debugger Outline INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 3

Dynamic semantics Depends on the purpose of the language ow ningfsm * ow nedstate cur rentstate run() FSM reset() 0.. initialstate name: EString step() State source tar get outgoingtrans ition * inc omingtrans ition 0.. Transi tion input: EString output: EString fire() What is the meaning of the model? INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 32

Operational Semantics of State Machines A model Its metamodel w ow ningfsm * ow nedstate FSM cur rentstate State 0.. run() initialstate name: EString reset() step() a /b x/y S S2 S3 y/x b /a Transi tion source outgoingtrans ition input: EString * output: EString tar get inc omingtrans ition fire() 0.. Adding Operational Semantics to OO Metamodels INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 33

Example ow ningfsm * ow nedstate FSM cur rentstate State 0.. run() initialstate name: EString reset() step() source tar get outgoingtrans ition * inc omingtrans ition 0.. Transition input: EString output: EString fire() operation fire() : String source.owningfsm.currentstate := target result := output INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 34

ow ningfsm * ow nedstate FSM cur rentstate State 0.. run() initialstate name: EString reset() step() source tar get outgoingtrans ition * inc omingtrans ition 0.. Transi tion input: EString output: EString fire() operation step(c : String) : String // Get the valid transitions var validtransitions : Collection<Transition> validtransitions := outgoingtransition.select { t t.input.equals(c) } // Check if there is one and only one valid transition if validtransitions.empty then raise NoTransition.new end if validtransitions.size > then raise NonDeterminism.new end // fire the transition result := validtransitions.one.fire INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 35

ow ningfsm * ow nedstate FSM cur rentstate State 0.. run() initialstate name: EString reset() step() source Transi tion input: EString output: EString INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 36 tar get operation run() : Void outgoingtrans ition * inc omingtrans ition from var str : String until str == "exit" loop stdio.writeln("current state is " + currentstate.name) str := stdio.read("enter an input string or 'exit' to exit simulation : ") stdio.writeln(str) if str!= "exit" then do stdio.writeln("output string : " + currentstate.step(str)) rescue (ex : FSMException) stdio.writeln("error : " + ex.tostring) end end end stdio.writeln("* END OF SIMULATION *") 0.. fire()

a /b x/y S S2 y/x S3 b /a /** * Load a sample FSM from a xmi2 file */ operation loadfsm() : FSM is do var repository : EMFRepository init EMFRepository.new var resource : EMFResource resource?= repository.createresource("../models/fsm_sample.xmi", "../metamodels/fsm.ecore") resource.load // Load the fsm (we get the main instance) result?= resource.instances.one end INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 37

Abstract syntax Concrete syntax Editor(s) Static semantics Dynamic semantics Interpreter Compiler Debugger Outline INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 38

Model-to-Text vs. Model-to-Model Model-to-Text Transformations For generating: code, xml, html, doc. Should be limited to syntactic level transcoding Model-to-Model Transformations To handle more complex, semantic driven transformations INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 39

Model-to-Text Approaches For generating: code, xml, html, doc. Visitor-Based Approaches:» Some visitor mechanisms to traverse the internal representation of a model and write code to a text stream» Iterators, Write () Template-Based Approaches» A template consists of the target text containing slices of metacode to access information from the source and to perform text selection and iterative expansion» The structure of a template resembles closely the text to be generated» Textual templates are independent of the target language and simplify the generation of any textual artefacts INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 40

Classification of Model-to-Model Transformation Techniques. General purpose programming languages Java/C#... 2. Generic transformation tools Graph transformations, XSLT 3. CASE tools scripting languages Objecteering, Rose 4. Dedicated model transformation tools OMG QVT style 5. Meta-modeling tools Metacase, Xactium, Kermeta INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 4

Compiling ThingML Another way of mapping to a known language ThingML Compilers Micro-controllers (Arduino, Atmel AVRs, TI MSP430) Linux C (POSIX) Java (and Android) Scala Written in Scala. Not much generic tools but some patterns INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 42

Abstract syntax Concrete syntax Editor(s) Static semantics Dynamic semantics Interpreter Compiler Debugger Outline INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 43

ThingML Language Support multiple platforms Other micro-controllers (Other Atmel AVRs, TI MSP430) Linux C (POSIX) Java (and Android) Scala Support distribution Generation of communication protocols Transparent asynchronous messaging Bluetooth, Blootooth Smart, Xbee, RF, Open-source language and tools (http://www.thingml.org) Still under development In use in several research projects INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 44

Summary Lots of steps to create a DSL Syntax has to be good but it is not the main development effort The purpose of the language should be clear and narrow Modelling does not imply graphics and graphics do not imply modelling Modelling tools help make language engineering more accessible Lots of tools and standards can be used INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 45

Thank you for your attention! Any questions? http://www.thingml.org franck.fleurey@sintef.no INF520 203 Franck Fleurey (franck.fleurey@sintef.no) 46