+ All Categories
Home > Documents > Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

Date post: 14-Dec-2015
Category:
Upload: will-demers
View: 216 times
Download: 0 times
Share this document with a friend
Popular Tags:
34
Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1
Transcript
Page 1: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

1

Elevator SimulatorDSL Project

Presented by

Miguel Garzón and

Stéphane Leblanc

Page 2: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

2

Elevator Simulator

• Framework to test the behaviors of elevators in different scenarios

• Open Source (LGPL)• Java Project• Authors: Neil McKellar and Chris Dailey• More details can be found at

http://elevatorsim.sourceforge.net/

Page 3: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

3

Elevator Simulator DSL

• Domain Specific Language (DSL) over the Elevator Simulator API

• Allow to create elevator simulation scenarios

Page 4: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

4

Introductory Example

• View the example

Page 5: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

5

Page 6: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

6

Goals of the DSL

1. Easy to read2. Concise3. Easy to write4. Maintainable5. Easy to parse

Page 7: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

7

Target Audience

• Developers– Who want to create scenarios for the Elevator

Simulator– Who want to look at a DSL implementation

example• Non-programmers not taken into account

Page 8: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

8

DSL Metamodel (1)

Page 9: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

9

• User VariablesDSL Metamodel (2)

Page 10: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

10

DSL Overview – Metamodel (3)

Page 11: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

11

DSL Creation Technology (1)

JET

Page 12: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

12

DSL Creation Technology (2)

• Eclipse IDEThe Elevator Simulator DSL is deeply integrated

with Eclipse. Our DSL comes in the form of an Eclipse Plug-in.

Page 13: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

13

DSL Creation Technology (3)

• Xtext for definition of BNF Grammar and Metamodel generation.Xtext is an Eclipse-based DSL generator that was released in 2006 and is built on top of Antlr and other famous Eclipse projects.

• One can create Xtext Projects from ecore model or a grammar definition.

Page 14: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

14

xText

Xtext- Generated Artefacts

BNF GRAMMAR SEMANTIC MODEL(ECORE)

EDITOR PARSER

OPTIONAL

Generates

Generates

Page 15: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

15

xText

Xtext- Generated Artefacts

BNF GRAMMAR

SEMANTIC MODEL(ECORE)

EDITOR PARSER

EMF Model Code

Page 16: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

16

EMF Code Generation

• The generated code will consists out of the following:– Interfaces and the Factory to create the Java classes– Concrete implementation of the interfaces defined in

model– Utilities

• Possibility to modify and extend generated code.– Code that is explicitly marked as @generated NOT is

not overwritten.

Page 17: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

17

xText

Xtext- DSL Processing

BNF GRAMMAR SEMANTIC

MODEL(ECORE)

EDITOR PARSER

Generated Java ClassESIM file

Interpreted Generated

Page 18: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

18

DSL Creation Technology (4)

• JET (Java Emitter Templates): For Code Generation.

• JET will be used to translate our domain specific language into Java classes representing the scenarios that will work with the Elevator Simulator.

Page 19: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

19

JET (Java Emitter Templates) <%@ jet package="org.intranet.sim.dsl.codegen"

class="ScenarioGenerator" imports="org.intranet.sim.dsl.scenarioGenerator.*" skeleton="generator.skeleton" %>

<% Model model = (Model) argument; Scenario scenario = model.getScenario(); String displayName = scenario.getDisplayName(); String className = scenario.getName(); ...%> public class <%=className%> extends Simulator{ … }

Page 20: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

20

Xtext Features (1)

• Code Completion • Syntax Highlighting• Linking• Scoping • IntelliSense • Quick Fix• Warnings

Page 21: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

21

Xtext Features (2)

• Test cases: (for testing the editor)

Page 22: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

22

Xtext Features –Validation (1)

• Semantic Validation:From OCL constraints defined in the Ecore Model,

validation code is generated.

Page 23: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

23

Extension Points• Eclipse provides the concept of "extension

points“. • Elevator Sim provides menu actions, icons to

enhance the user experience.– org.eclipse.ui.actionSets

Page 24: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

24

Editor Sample Usage

Page 25: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

25

Intelisense: Select a Variable

Page 26: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

26

Syntactic Error: Grammatically

Incorrect

Page 27: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

27

Semantic Error: Makes No SenseSemantic Error: Makes No Sense

Page 28: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

28

Deprecated

Page 29: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

29

Quick Fix

Page 30: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

30

Strategies for Language Evolution (1)

• Incremental Migrations[FowlerMig]

V2.0V1.1V1.0

Page 31: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

31

Strategies for Language Evolution (2)

• Model-based migrations [FowlerMig]

V2.0

V1.1

V1.0

Page 32: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

32

Strategies for Language Evolution (3)

• Maintain backward compatibility (Selected)

V2.0V1.1V1.0

Page 33: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

33

Conclusion

• Elevator Simulator DSL simplifies the creation of scenarios

• Powered by XText• Allows for model interpretation and for code

generation

Page 34: Elevator Simulator DSL Project Presented by Miguel Garzón and Stéphane Leblanc 1.

34

References

• [FowlerDsl] Martin, Fowler, Domain-specific language, ISBN 0321712943

• [FowlerMig] Fowler, Martin, DSL Migration, 2009/02/05http://martinfowler.com/bliki/DslMigration.html

• Bell, Peter, DSL Evolution, 2009/12/22http://www.infoq.com/articles/dsl-evolution

• Tolvanen, JP, DSL in Practice, 2008/12/07, Software Engineering Radio, episode 119http://www.se-radio.net/?s=DSL


Recommended