model-based software engineering language (dsl) definition by martin fowler programming language...
TRANSCRIPT
Dr. Gergely Varró
16. April 2012 | Real-Time Systems Lab | Prof. Dr. Andy Schürr | Dr. Gergely Varró | 1
Model-Based Software Engineering
16. April 2012 | Real-Time Systems Lab | Prof. Dr. Andy Schürr | Dr. Gergely Varró | 2
Course Information
Forum:
https://www.fs-ist.de/forum/index.php?board=58.0
Schedule
Thursdays 13:30-16:00, 3-hour blocks
S1|03/226
2 lectures + 1 exercise / week (in average, details come later)
Exam (written, 90 min)
4 credit points
English
Audience
MSc ETiT, BSc/MSc iST, BSc/MSc (Wirtschafts-)Informatik
B 6 / M 1 – M 4
Optional course
16. April 2012 | Real-Time Systems Lab | Prof. Dr. Andy Schürr | Dr. Gergely Varró | 3
Domain-Specific Language (DSL)
Definition by Martin Fowler
Programming language
Limited expressiveness
Focuses on a particular domain
Main advantage
Productivity increase
Easier to understand by domain specialists (compared to C, C++ code)
16. April 2012 | Real-Time Systems Lab | Prof. Dr. Andy Schürr | Dr. Gergely Varró | 4
DSLs in the Computer Science Domain I.
Unix shell scripts
sh, bash, csh, awk
Domain: Data organization
Language constructs
Control-flow
String manipulation
Stream handling
Variables
Boolean expressions
Expressiveness: limited?
#!/bin/sh
PRG="$0"
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`/"$link"
fi
done
PRGDIR=`dirname "$PRG"`
EXECUTABLE=executable.sh
# ...
exec "$PRGDIR"/"$EXECUTABLE" start "$@"
16. April 2012 | Real-Time Systems Lab | Prof. Dr. Andy Schürr | Dr. Gergely Varró | 5
DSLs in the Computer Science Domain II.
Regular expressions
Domain: String matching
Performed by finite automata
Language constructs
Characters
Character groups or intervals
Character sequence, alternatives
Repetition, optionality
Arbitrary character
Beginning or end of a line
ab
[bch]?at
[A-Z][a-z]*
[:upper:][:lower:]*
.at
(great-)*grand(father|mother|parent|child)
^a+$
16. April 2012 | Real-Time Systems Lab | Prof. Dr. Andy Schürr | Dr. Gergely Varró | 6
DSLs in the Computer Science Domain III.
SysML
Domain: Automotive systems
Structural constructs
Model Element Diagram
Block Definition Diagram
Internal Block Diagram
Parametric Diagram
Behavioral constructs
Activities (slightly modified)
Interactions (UML)
State charts (UML)
Use cases (UML)
Simulators
Enterprise Architect Source: http://en.wikipedia.org/wiki/File:Sysml_diagrams_collage.jpg
16. April 2012 | Real-Time Systems Lab | Prof. Dr. Andy Schürr | Dr. Gergely Varró | 7
DSLs in the Computer Science Domain IV.
Logo
Domain: Educational programming language
Language constructs
Characters
Keywords
Procedure declaration/invocation
Local variables
197 implementations
UCBLogo
to square
repeat 4 [forward 50 right 90]
end
to flower
repeat 36 [right 10 square]
end
to spiral :size :angle
if :size > 100 [stop]
forward :size
right :angle
spiral :size + 2 :angle
end
Source: http://el.media.mit.edu/logo-foundation/logo/turtle.html With the kind permission of the Logo Foundation
16. April 2012 | Real-Time Systems Lab | Prof. Dr. Andy Schürr | Dr. Gergely Varró | 8
DSLs in the Electrical Engineering Domain I.
Matlab / Simulink
Developed by MathWorks
Domain: Control engineering, signal processing
Language constructs
Blocks
Predefined blocks in libraries
Tool support
Simulation
Graphical debugger and profiler
Model analysis and diagnostics
…
16. April 2012 | Real-Time Systems Lab | Prof. Dr. Andy Schürr | Dr. Gergely Varró | 9
DSLs in the Electrical Engineering Domain II.
VHSIC Hardware Description Language (VHDL)
Very-high-speed integrated circuits (VHSIC)
Domain: Hardware description language
Language constructs
Circuit specifications
Keywords
Input / Output ports
Libraries and their contents
Tool support
Simulation
Synthesis
Register-transfer level (RTL) description to logic gates
Code generation to a programmable logic device (FPGA)
library IEEE;
use IEEE.std_logic_1164.all;
entity neg is
port(i:in std_logic;
o:out std_logic);
end neg;
architecture N of neg is
begin
o <= not i;
end architecture N;
16. April 2012 | Real-Time Systems Lab | Prof. Dr. Andy Schürr | Dr. Gergely Varró | 10
Domain-Specific Language (DSL) Development
Why are DSLs useful and important?
Communication interface between electrical engineers and computer scientists
Passing configuration files between tools
…
Why is DSL usage insufficient?
Adaptation to special subdomains
DSL development is required
How to develop DSLs?
A general approach and tool chain
Model-Based Software Engineering
16. April 2012 | Real-Time Systems Lab | Prof. Dr. Andy Schürr | Dr. Gergely Varró | 11
Model-Based Software Engineering
Central artifact: Models in the complete development lifecycle
Related terms:
Model Driven Engineering, Model Driven [Software] Development, Model Driven
Architecture, Model Integrated Computing
Example: Logic gate networks
Logic gates (NOT, AND, OR, etc.)
Inputs and outputs
Model
neg i
o outputs
inputs
Structure vs. behaviour
16. April 2012 | Real-Time Systems Lab | Prof. Dr. Andy Schürr | Dr. Gergely Varró | 12
Defining Models
Model
Graphical
Notation
Textual
Notation entity neg is
port(i:in std_logic;
o:out std_logic);
end neg;
1 o i
neg i
o outputs
inputs
Abstract
concept
Concrete
representation
16. April 2012 | Real-Time Systems Lab | Prof. Dr. Andy Schürr | Dr. Gergely Varró | 13
Application Scenarios I.
Code generation (traditional MDA scenario)
Original proposal by the Object Management Group (OMG) in 2001
Platforms
Hardware: desktop vs. embedded system, …
Runtime environment (libraries): J2ME, J2SE, J2EE, OSGi, C#, …
Software: relational database (rows in tables), …
Platform
Independent
Model
Model-to-Model
Transformation
Platform
Specific
Model
Program
Code
Model-to-Text
Transformation
neg i
o outputs
inputs inputs
neg i
outputs
neg o
gates
neg
INSERT INTO gates
VALUES (neg);
INSERT INTO inputs
VALUES (neg,i);
INSERT INTO
outputs
VALUES (neg,o);
16. April 2012 | Real-Time Systems Lab | Prof. Dr. Andy Schürr | Dr. Gergely Varró | 14
Application Scenarios II.
Code generation (traditional MDA scenario)
Automatically
For different platforms
For the complete system / large parts
Is it a real approach (or just a vision)?
Yes: Rapid prototyping
No: Ever seen an automatically generated large software system?
Platform
Independent
Model
Model-to-Model
Transformation
Platform
Specific
Model
Program
Code
Model-to-Text
Transformation
neg i
o outputs
inputs inputs
neg i
outputs
neg o
gates
neg
INSERT INTO gates
VALUES (neg);
INSERT INTO inputs
VALUES (neg,i);
INSERT INTO
outputs
VALUES (neg,o);
16. April 2012 | Real-Time Systems Lab | Prof. Dr. Andy Schürr | Dr. Gergely Varró | 15
Application Scenarios III.
Code generation (in a more general context)
Test cases
Documentation
Program code
Configurations
Platform
Independent
Model
Model-to-Model
Transformation
Platform
Specific
Model
Program
Code
Model-to-Text
Transformation
Configuration
File
neg i
o outputs
inputs
Documentation
Test Case
16. April 2012 | Real-Time Systems Lab | Prof. Dr. Andy Schürr | Dr. Gergely Varró | 16
Application Scenarios IV.
Analyzing system behaviour
Reveal design errors
In an early development phase
Simulation
Step-by-step execution
Verification
Technique to check formal system properties
Platform
Independent
Model
Verification tool
Platform
Specific
Model
neg i
o outputs
inputs
Simulation
engine
16. April 2012 | Real-Time Systems Lab | Prof. Dr. Andy Schürr | Dr. Gergely Varró | 17
Application Scenarios V.
Bidirectional model transformation
Model synchronization
Complete information in both models
View calculation
View: projected or aggregated information
Platform
Independent
Model
Model-to-Model
Transformation
Platform
Specific
Model
neg i
o outputs
inputs
View
Well-formedness constraints
Enforced by the specification
Gates have inputs and outputs.
Enforced by static analysis (model consistency checking)
A NOT gate has one input and one output.
An AND gate has two inputs and one output.
16. April 2012 | Real-Time Systems Lab | Prof. Dr. Andy Schürr | Dr. Gergely Varró | 18
Application Scenarios VI.
Platform
Independent
Model
Static analysis
tool
neg i
o outputs
inputs
Refactoring
Perform modifications on the system model
Reverse engineering
How to build models from (legacy) source code?
16. April 2012 | Real-Time Systems Lab | Prof. Dr. Andy Schürr | Dr. Gergely Varró | 19
Application Scenarios VII.
Platform
Independent
Model
Model-to-Model
Transformation
Platform
Specific
Model
Program
Code
Text-to-Model
Transformation
neg i
o outputs
inputs
16. April 2012 | Real-Time Systems Lab | Prof. Dr. Andy Schürr | Dr. Gergely Varró | 20
Course Content Overview
Platform
Independent
Model
Model-to-Model
Transformation
Platform
Specific
Model
Metamodeling
XML schemas
Eclipse Modeling
Framework (EMF)
Program
Code
Model-to-Text
Transformation
Template-Based
Code Generation
Editors for Domain-Specific
Languages Graphical
Notation
Textual
Notation entity neg is
port(i:in std_logic;
o:out std_logic);
end neg;
Model transformation
Graph transformation
Bidirectional
transformation
1 o i
Configuration
File
16. April 2012 | Real-Time Systems Lab | Prof. Dr. Andy Schürr | Dr. Gergely Varró | 21
Goals
Description of application domains and domain-specific models by using
standard languages and technologies
Specification of model transformations (with a special focus on
declarative, rule-based techniques)
Exploration of the connection points of model-based techniques and
textual representations
Analysis, experimentation, evaluation and comparison of state-of-the-art
tools used for model-driven software development
16. April 2012 | Real-Time Systems Lab | Prof. Dr. Andy Schürr | Dr. Gergely Varró | 22
Course Schedule & Table of Contents
12.04: Introduction, Metamodeling, XML schemas
19.04: Eclipse Modeling Framework (EMF), Code generation with EMF
26.04: Graph transformation
03.05: Model transformation
10.05: Implementation techniques for graph transformation, 1st exercise: metamodeling + model transformation
17.05: Public holiday
24.05: Domain-specific languages (DSL)
31.05: 1st exercise discussion + 2nd exercise: model transformation + DSL
07.06: Public holiday
14.06: Template-based code generation
21.06: 2nd exercise discussion + 3rd exercise: code generation
28.06: Bidirectional transformation
05.07: 3rd exercise discussion + 4th exercise: bidirectional transformation
12.07: 4th exercise discussion + exam preparation
16. April 2012 | Real-Time Systems Lab | Prof. Dr. Andy Schürr | Dr. Gergely Varró | 23
Exercises I.
General overview Simple software development project
Tool usage
Enterprise Architect
Eclipse (EMF)
Actually of practical use!
Similar to the exam
Organizational issues (detailed information in forum) Problem sheet distribution + hands-on exercise solving already during the allocated
time slot in pool
1-3 weeks to finish solutions (regular consultation hours in pool, forum)
Consultation hours: Tuesdays 15:00-16:00, S3|06/069
Optional exercises, evaluation of (interesting subset of) submitted solutions
Sample solution + discussion (strengths and weaknesses) of (interesting subset of) submitted solutions
Contact Anthony Anjorin ([email protected])
16. April 2012 | Real-Time Systems Lab | Prof. Dr. Andy Schürr | Dr. Gergely Varró | 24
Exercises II.
(Optional) Now until 10.05, Tutorial: www.moflon.org
Chinese Checkers
Draughts
Sokoban
Chess
16. April 2012 | Real-Time Systems Lab | Prof. Dr. Andy Schürr | Dr. Gergely Varró | 25
Exercises III.
Goal: Describe “behaviour” of
figures in a concise manner …
16. April 2012 | Real-Time Systems Lab | Prof. Dr. Andy Schürr | Dr. Gergely Varró | 26
Java vs. DSL
public void fieldPressed(int x, int y) {
if (board[x][y]) {
current_x = x;
current_y = y;
} else {
if (current_x == x || current_y == y) {
board[x][y] = true;
board[current_x][current_y] = false;
current_x = x;
current_y = y;
}
}
}
[#][ ] => [ ][#] [ ][#] => [#][ ] [#] => [ ] [ ] => [#] [ ] => [#] [#] => [ ]
16. April 2012 | Real-Time Systems Lab | Prof. Dr. Andy Schürr | Dr. Gergely Varró | 27
References
Cole, J., Gradecki, J.D.: Mastering Apache Velocity. Wiley Computer Publishing (2003)
K. Czarnecki, U.W. Eisenecker: Generative Programming: Methods, Tools, and Applications. Addison-Wesley, 2000
Fowler, M.: Domain Specific Languages. Addison-Wesley Professional (2010)
D.S. Frankel: Model Driven Architecture – Applying MDA to Enterprise Computing. Wiley, 2003
Stahl, T., Völter, M., Bettin, J., von Stockfleth, B.: Model-Driven Software Development: Technology, Engineering, Management. John Wiley (2006)
Steinberg, D., Budinsky, F., Paternostro, M., Merks, E.: Eclipse Modeling Framework. Addison-Wesley Professional, Second edn. (2009)
van der Vlist, E.: XML Schema: The W3C’s Object-Oriented Descriptions for XML. O’Reilly Media (2002)
Walmsley, P.: Definitive XML Schema. Prentice Hall (2001)