engineering
play

Engineering Example of the ThingML language Franck Fleurey SINTEF - PowerPoint PPT Presentation

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


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

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

  3. Outline  Abstract syntax  Concrete syntax  Editor(s)  Static semantics  Dynamic semantics  Interpreter  Compiler  Debugger  … INF5120 – 2013 – Franck Fleurey (franck.fleurey@sintef.no) 3

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

  5. 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? INF5120 – 2013 – Franck Fleurey (franck.fleurey@sintef.no) 5

  6. What is the Internet of Things (IoT)? INF5120 – 2013 – Franck Fleurey (franck.fleurey@sintef.no) 6

  7. 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  ... INF5120 – 2013 – Franck Fleurey (franck.fleurey@sintef.no) 7

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

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

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

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

  12. ThingML: Action Language ?forward Forward on entry do reset_wheel_position() motor_start() end ... action do motor_set_speed(speed) motor_set_direction(FW) end INF5120 – 2013 – Franck Fleurey (franck.fleurey@sintef.no) 12

  13. 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. INF5120 – 2013 – Franck Fleurey (franck.fleurey@sintef.no) 13

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

  15. ThingML Abstract Syntax INF5120 – 2013 – Franck Fleurey (franck.fleurey@sintef.no) 15

  16. Abstract syntax – State Machines Model x/y a /b S1 S2 S3 y/x b/a INF5120 – 2013 – Franck Fleurey (franck.fleurey@sintef.no) 16

  17. Abstract syntax – State Machines Model x/y a /b S1 S2 S3 y/x b/a Meta-Model ow ningFSM 1 Transition * ow nedState currentState source outgoingTransition FSM input: EString State 0..1 output: EString 1 * name: EString run() initialState incomingTransition target fire() reset() step() 1 1 0..1 INF5120 – 2013 – Franck Fleurey (franck.fleurey@sintef.no) 17

  18. What do we get? Model x/y a /b S1 S2 S3 y/x b/a Meta-Model ow ningFSM 1 Transition * ow nedState currentState source outgoingTransition FSM input: EString State 0..1 output: EString 1 * name: EString run() initialState incomingTransition target fire() reset() step() 1 1 0..1 INF5120 – 2013 – Franck Fleurey (franck.fleurey@sintef.no) 18

  19. Outline  Abstract syntax  Concrete syntax  Editor(s)  Static semantics  Dynamic semantics  Interpreter  Compiler  Debugger  … INF5120 – 2013 – Franck Fleurey (franck.fleurey@sintef.no) 19

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

  21. ThingML Concrete syntax  Made a attempt at graphical  Made an attempt with UML  Endded-up with a text-based syntax  Built with EMFText INF5120 – 2013 – Franck Fleurey (franck.fleurey@sintef.no) 21

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

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

  24. 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 INF5120 – 2013 – Franck Fleurey (franck.fleurey@sintef.no) 24

  25. ThingML Editor INF5120 – 2013 – Franck Fleurey (franck.fleurey@sintef.no) 25

  26. Outline  Abstract syntax  Concrete syntax  Editor(s)  Static semantics  Dynamic semantics  Interpreter  Compiler  Debugger  … INF5120 – 2013 – Franck Fleurey (franck.fleurey@sintef.no) 26

  27. 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. INF5120 – 2013 – Franck Fleurey (franck.fleurey@sintef.no) 27

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

  29. OCL for static semantics  Can be used at both – M1 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 INF5120 – 2013 – Franck Fleurey (franck.fleurey@sintef.no) 29

  30. Static semantics example ow ningFSM 1 Transition * ow nedState currentState source FSM outgoingTransition input: EString State 0..1 output: EString 1 * name: EString run() initialState incomingTransition target fire() reset() step() 1 1 0..1 Context FSM inv: ownedState->forAll(s1,s2| s1.name=s2.name implies s1=s2) INF5120 – 2013 – Franck Fleurey (franck.fleurey@sintef.no) 30

  31. Outline  Abstract syntax  Concrete syntax  Editor(s)  Static semantics  Dynamic semantics  Interpreter  Compiler  Debugger  … INF5120 – 2013 – Franck Fleurey (franck.fleurey@sintef.no) 31

  32. Dynamic semantics  Depends on the purpose of the language ow ningFSM 1 Transition * ow nedState currentState source FSM outgoingTransition input: EString State 0..1 output: EString 1 * name: EString run() initialState incomingTransition target fire() reset() step() 1 1 0..1  What is the meaning of the model? INF5120 – 2013 – Franck Fleurey (franck.fleurey@sintef.no) 32

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend