Component-Based Language Engineering Frédéric Fondement
Swiss Federal Institute of Technology, Lausanne Software Engineering Laboratory SMV & LGL Seminar Les Diablerets, June 6th, 2005
Contents z Language Engineering z Language Components z Identified Kinds of Components z Tuning z Outlook
© F. Fondement
-2-
June 10, 2004
Contents z Language Engineering z Language Components z Identified Kinds of Components z Tuning z Outlook
© F. Fondement
-3-
June 10, 2004
Language Engineering z Very Heart of Model/Language Driven Engineering Compiler Provider
z Well-Known Domain Abstractions (Ladder /
CASE tool Provider
Domain Engineer
Language Engineering
Phototool / Architecture…)
vs. (more or less) adapted Generic Purpose Languages (UML/…) Project Architect
z Proliferation of Languages © F. Fondement
-4-
June 10, 2004
Language Construction Concrete Syntax
© F. Fondement
-5-
June 10, 2004
Language Construction Concrete Syntax +
Abstract Syntax
S1
ModelElement T12
name : String
S2
S 2.1
S 2.2
StateMachine source subvertex *
StateVertex
Event
outgoing
1
*
1
*
target
trigger 0..1 Transition
*
incoming top 1 State
PseudoState
«enumeration» PseudoStateKind
kind : PseudoStateKind container 0..1
© F. Fondement
Composite State
Simple State
-6-
Final State
initial choice ...
June 10, 2004
Language Construction Concrete Syntax +
Abstract Syntax
+
Semantics
S1
T12
S2
S 2.1
S 2.2
ModelElement name : String
StateMachine source subvertex *
StateVertex
Event
outgoing *
1
trigger 0..1 Transition
*
1 target
*
incoming top 1 State
PseudoState
«enumeration» PseudoStateKind
kind : PseudoStateKind container 0..1
© F. Fondement
Composite State
Simple State
-7-
Final State
initial choice ...
June 10, 2004
Problems in Language Engineering z An Endeavour to Capture Knowledge in a Language • Concrete Syntax + Abstract Syntax + Semantics
z Built from Scratch z Built from A to Z z Recurrent Comparable Solutions • At syntax level • E.g. UML & MOF (incl. different versions)
• At concepts levels • E.g. Merise & UML; Scenarios & MSC
• At semantics level • E.g. OCL & SQL ; Java and Smalltalk objects
• Evolution of Standards (versions)
© F. Fondement
-8-
June 10, 2004
Contents z Language Engineering z Language Components z Identified Kinds of Components z Tuning z Outlook
© F. Fondement
-9-
June 10, 2004
The Idea
Compiler Provider
CASE tool Provider
Domain Engineer
Project Architect
Language Engineering «include»
Language Composition
«include»
Language Adaptation
«include» Language Tuning
© F. Fondement
- 10 -
June 10, 2004
An Example : Generic OCL Framework Model View
OCL
UML-MV Adapter
Model View Model View Java-MV OCL MM Parser
Adapter
Model View
«metamodel» Model View
MyMM-MV Adapter
UML MM UML MM
Java AS Java AS
My MM My MM
UML Editor
Java Parser
My Repository
«metamodel» OCL MM © F. Fondement
- 11 -
June 10, 2004
An Example : Generic OCL Framework Model View
OCL
UML-MV Adapter
Model View Model View Java-MV OCL MM Parser
Adapter
Model View
MyMM-MV Adapter
Instance View (extends ModelView)
OCL Interpreter
OCL MM
© F. Fondement
UML MM UML MM
Java AS Java AS
My MM My MM
Model View OCL MM - 12 -
UML Editor
Java Parser
My Repository
KM MM
OCL - KM Compiler June 10, 2004
Contents z Language Engineering z Language Components z Identified Kinds of Components z Tuning z Outlook
© F. Fondement
- 13 -
June 10, 2004
Kind Of Component : Repository z Metamodel-Driven z Already at work • XMI • JMI • …
My MM
© F. Fondement
- 14 -
My Repository
June 10, 2004
Kind Of Component : Editors z Environment to Edit / Render a Graphical Model z (can integrate a repository)
UML MM
UML Editor
z Technologies • Specific CASE tools – hand-coded • Meta-Editors – Platform-specific
z Concrete syntax cannot be formalized !
© F. Fondement
- 15 -
June 10, 2004
«Interface» GraphicalObject
Kind Of Component : Editors
• Properties • Behaviours
Constraining Part M etaClasses Transition Scheme
Proposal to define (graphical) Concrete Syntaxes z SVG templates
Transition
me 1
Iconic Part Display Classes
Display M anager Classes dm 1
TransitionDM
vo 1
SVGTransition
1 «connects» SVGArrowEnd start 1 «connects» end
z Mapping model z Consistency Constraints State Scheme
Simple me State 1
dm *
Simple StateDM
vo 1
SVGSimpleState
1 «contains» name Pseudo me State 1
dm 1
Pseudo StateDM
SVGText
vo SVGPseudo State 1 SVGInitial
... © F. Fondement
SVGArrowEnd
0..1 SVGText «nearby» event text:String
PseudoState Scheme
• MM vs. Representation • Spatial Relationships
contains() connects() nearby() overlaps()
- 16 -
SVGChoice
June 10, 2004
Kind Of Component : Adapters z Isolation Layer between Components at Model Level • Reusability of components (incl. Model Transformations) • Implementation of Interfaces
z Maps Required Interfaces (Model View) with Actual Interfaces (UML / Java / MyMM / …) z Could be realized by Model Transformation • Synchronization issues Model View
MyMM-MV Adapter
My MM
z Proposal : Use Refined Views • The View Pattern – at model level • The View in Databases © F. Fondement
- 17 -
June 10, 2004
Kind Of Component : Adapters RDB Model View 1 * 1 Class
1 *
State Attribute
1 *
MV-RDB Adapter 1
«refines»
Table Column isPK : Boolean isFK : Boolean 1
Class Attribute
package MV-RDB_Adapter context Class inv : self.name = self.table.name inv : self.attribute.column = self.table.column->reject(isPK or isFK) inv : self.state->isEmpty context Attribute inv : self.name = self.attribute.name endpackage © F. Fondement
- 18 -
June 10, 2004
Kind Of Component : Adapters «MTLLibrary» 1 ModelView
«MTLLibrary» OCLAbstractSyntax
«model»
«MTLLibrary» Core20Adapter
«MTLLibrary» FondueAdapter
«MTLLibrary» FondueAdapter
«model»
«model»
1 «MTLLibrary» «model»UML20Adapter
«MTLLibrary» MOF20Adapter
«metamodel» Fondue
1
core20 OCL4Fondue «model» uml20 {refines core20} 1
1 «metamodel» Core20
«metamodel» UML20
© F. Fondement
«model» mof20 1 {refines core20} «metamodel» MOF20
- 19 -
June 10, 2004
Kind Of Component : Parser z Text (Tokens) => Model z Often requires Several Passes z Idea • First pass creates a model • Each pass has its model
Decorated Decorated ... Metamodel
Text
«text analyser» lexer/parser
© F. Fondement
Decorated Metamodel
*
* «model transformation» Pass 1
- 20 -
Metamodel
«model transformation» Pass N
June 10, 2004
Kind Of Component : Parser C o n s tra in in g P a rt
Scheme
Transition
M e ta C la s s e s
D is p la y M a n a g e r C la s s e s d mme T r a n s itio n D M 1 1
T r a n s itio n « d e c o ra tio n » s ta rtS ta te : S trin g
Ic o n ic P a rt D is p la y C la s s e s vo 1
1 s ta rtS ta te 1 e n d S ta te 0 ..1
Scheme
PseudoState
event
P s e u d o S ta te
md e m 1 1
P s e u d o S ta te D M
vo 1
Text Analyser # Editor ? z Text templates => (decorated) Model z Constraints
T r a n s itio n R u le N am e T oken N am e T oken N am e T oken
P s e u d o S ta te R u le In it T o k e n C h o ic e T o k e n
...
Decorated Decorated ... Metamodel
Text
«text analyser» lexer/parser
© F. Fondement
Decorated Metamodel
*
* «model transformation» Pass 1
- 21 -
Metamodel
«model transformation» Pass N
June 10, 2004
Other Kinds of Components z Model Transformations • Compilers • Metrics • Derivation • Product Lines
• …
z Interpreters • Requires an execution environment • Transformation to “Semantically-Rich” Metamodels • KerMeta / adapted Action Semantics / COOPN / … • Requires Type Translations !
z Code Generators • An RFP at the OMG • Related to Text Analyser construction(?)
© F. Fondement
- 22 -
June 10, 2004
Contents z Language Engineering z Language Components z Identified Kinds of Components z Tuning z Outlook
© F. Fondement
- 23 -
June 10, 2004
Tuning Components z Adapt an Almost Solution • OCL extended to support Temporal Constraints • OCL extended to Fondue • Action Semantics extended to Web Application Engineering
z Extend Structure z Add / Change Behaviour of Components z Tuning Depends on the Kind of Component
© F. Fondement
- 24 -
June 10, 2004
Tuning Components
Text
Tuned Decorated Decorated ... Metamodel
Tuned Decorated Metamodel
Tuned Metamodel
Decorated Decorated ... Metamodel
Decorated Metamodel
Metamodel
«text analyser» lexer/parser
«?????» «??????» Tuned Analyser
© F. Fondement
*
* «model transformation» Pass 1
«Weaves In» «model transformation aspect» Tuned Pass 1
- 25 -
«model transformation» Pass N
«Weaves In» «model transformation aspect» Tuned Pass N
June 10, 2004
Outlook Validate the Complete Approach z Implement Graphical Concrete Syntax Rendering • Semester project completed
z Realize Concrete Parser • OCL is under development (thanks to Amit)
z Improve / Validate Aspects for Tuning • Generic Aspect Weaver as a Language Component
z Study Refinement Alternatives • Overloading allInstances + delete + navigation • Event-based © F. Fondement
- 26 -
June 10, 2004
Language Modules z Components:
z Language Modules
• Reusable Parts • Define their Vision of the Environment
• Reusable Parts • Define their Vision of the Extended Language
• Required Interfaces
• Required Model
• Solution for a Problem
• Solution for a Problem
• Provided Interfaces
• E.g. OCL
z Language Modules • Can solve Semantics Level • Interpreter (for “Semantically-Rich” Languages) • Model Transformation (to “Semantically-Rich Language”)
• Can solve Concepts Level • New Concepts • Independent from the rest of the language – E.g. OCL module
• Can Solve Concrete Syntax level
© F. Fondement
- 27 -
June 10, 2004
The Netsilon Example
© F. Fondement
- 28 -
June 10, 2004
Netsilon z DSL for Web Application Engineering z Includes Multi-Platform Code Generator
© F. Fondement
- 29 -
June 10, 2004
Netsilon children 0..* 2 parents
wife
Person public String name public String surname public Gender gender public PersonStatus status
Gender
0..1
public String male public String female
0..1 husband
public Marriage marry(Person person) Marriage public Date date
Business Model
Hypertext Model
Presentation Model
Deployment Model Xion
© F. Fondement
- 30 -
June 10, 2004
Netsilon
Business Model
Hypertext Model
Presentation Model
Deployment Model Xion
© F. Fondement
- 31 -
June 10, 2004
Netsilon
Business Model
Hypertext Model
Presentation Model
Deployment Model Xion
© F. Fondement
- 32 -
June 10, 2004
Netsilon
Business Model
Hypertext Model
Presentation Model
Deployment Model Xion
person.parents.children->asSet()->excluding(person) ->select(p : p.gender == #female)->sortedBy(p : p.name) © F. Fondement
- 33 -
June 10, 2004
Netsilon
Business Model
Hypertext Model
Presentation Model
Deployment Model Xion
© F. Fondement
- 34 -
June 10, 2004
Netsilon : Code Generator Business Model
PIM
Model Transformations z Use z Composition z Selection
Hypertext Model
Presentation Model
Xion
Platform Dependent PSM
Object Business Relational Tier Generation Mapping
PSM Business Logic
«use»
Xion to Intermediate
Navigation to Scripts
«use»
User Tier Generation
Intermediate Language
SQL Abstract Syntax Schema Management
Classes
Instructions
Scripts
Data Access Query
Database Request «use»
Technology Dependent PSM
«merge» «merge» «merge»
Oracle SQL Abstract Syntax
«use»
PHP Generation
JSP Generation {xor}
{xor} MySQL Abstract Syntax
PostgreSQL Abstract Syntax
PHP
Java JSP
© F. Fondement
- 35 -
Servlet Generation
Servlet
June 10, 2004
Netsilon : Code Generator Business Model
PIM
Hypertext Model
Model Transformations
Xion
Platform Dependent PSM
Intermediate Language
Presentation Model
Object Business Relational Tier Generation Mapping
PSM Business Logic
«use»
Xion to Intermediate
Navigation to Scripts
«use»
User Tier Generation
Intermediate Language
SQL Abstract Syntax Schema Management
Classes
Instructions
Scripts
Data Access Query
Database Request «use»
Technology Dependent PSM
«merge» «merge» «merge»
Oracle SQL Abstract Syntax
«use»
PHP Generation
JSP Generation {xor}
{xor} MySQL Abstract Syntax
PostgreSQL Abstract Syntax
PHP
Java JSP
© F. Fondement
- 36 -
Servlet Generation
Servlet
June 10, 2004
Netsilon : Code Generator Business Model
PIM
Hypertext Model
Model Transformations
Xion
Platform Dependent PSM
Intermediate Language
Presentation Model
Object Business Relational Tier Generation Mapping
PSM Business Logic
«use»
Xion to Intermediate
Navigation to Scripts
«use»
User Tier Generation
Intermediate Language
SQL Abstract Syntax Schema Management
Classes
Instructions
Scripts
Data Access Query
Database Request «use»
Target Models z Composition z Refinement © F. Fondement
Technology Dependent PSM
«merge» «merge» «merge»
Oracle SQL Abstract Syntax
«use»
PHP Generation
JSP Generation {xor}
{xor} MySQL Abstract Syntax
PostgreSQL Abstract Syntax
PHP
Java JSP
- 37 -
Servlet Generation
Servlet
June 10, 2004
Netsilon: Realization z Concrete Syntax • Text : Modified Text Editor + “XionToIntermediate” transformation • Graph : Java Library (Tigris GEF) – modified UML CASE + Hand-made panels • Properties : Swing
z Abstract Syntax
• Java Classes • Intermediate Language : XML
z Semantics (i.e. Transformations and Code Generation) • Java (extended visitor pattern + factory pattern) + REGEXP • XSLT
z A Lot of Code ! z No other Language Reused (OCL / UML) z Nothing reusable ! © F. Fondement
- 38 -
June 10, 2004
Netsilon children 0..* 2 parents
wife
Person public String name public String surname public Gender gender public PersonStatus status
Gender
0..1
public String male public String female
0..1 husband
public Marriage marry(Person person) Marriage public Date date
Business Model
Hypertext Model
Presentation Model
Deployment Model Xion
person.parents.children->asSet()->excluding(person) ->select(p : p.gender == #female)->sortedBy(p : p.name) © F. Fondement
- 39 -
June 10, 2004
Netsilon : Code Generator Business Model
PIM
Hypertext Model
Model Transformations
Xion
Platform Dependent PSM
Intermediate Language
Presentation Model
Object Business Relational Tier Generation Mapping
PSM Business Logic
«use»
Xion to Intermediate
Navigation to Scripts
«use»
User Tier Generation
Intermediate Language
SQL Abstract Syntax Schema Management
Classes
Instructions
Scripts
Data Access Query
Database Request «use»
Target Models
Technology Dependent PSM
«merge» «merge» «merge»
Oracle SQL Abstract Syntax
«use»
PHP Generation
JSP Generation {xor}
{xor} MySQL Abstract Syntax
PostgreSQL Abstract Syntax
PHP
Java JSP
© F. Fondement
- 40 -
Servlet Generation
Servlet
June 10, 2004