Developing	a	new	Epsilon	Language	
through	Grammar	Extension:		
The	Epsilon	Demo	Language	(EDL)	
	
Dimitris	Kolovos	
@kolovos	
MoDELS	2016	 Advanced	Model	Management	with	Epsilon	 1
Epsilon	Demo	Language	
•  A	new	language	that	extends	EOL	and	introduces	
the	concept	of	a	"process	rule"	
•  Process	rules	are	simple	rules	that	are	executed	
for	every	instance	of	their	parameter	
	
// This will be run for every
// instance of EClass
process c : EClass {
// Here we can run arbitrary EOL code
c.name.println();
}
MoDELS	2016	 Advanced	Model	Management	with	Epsilon	 2
AnnotaLons	vs.	Grammar	Extension	
•  No	hard	rule	
•  AnnotaLons	
– Language	closer	to	EOL	
•  Grammar	extension	
– New	syntacLc	constructs	with	no	clear	mapping	to	
EOL	
MoDELS	2016	 Advanced	Model	Management	with	Epsilon	 3
Overview	
•  Two	Eclipse	plugins	
– One	for	the	language's	execuLon	engine	
•  org.eclipse.epsilon.edl.engine
•  Can	run	outside	Eclipse	
– One	for	the	language's	Eclipse-based	
development	tools	
•  org.eclipse.epsilon.edl.dt
•  Source	code	available	under	
hTps://git.eclipse.org/c/epsilon/
org.eclipse.epsilon.git/tree/examples		
MoDELS	2016	 Advanced	Model	Management	with	Epsilon	 4
EDL'S	EXECUTION	ENGINE	
org.eclipse.epsilon.edl.engine	
MoDELS	2016	 Advanced	Model	Management	with	Epsilon	 5
MoDELS	2016	 Advanced	Model	Management	with	Epsilon	 6
grammar Edl;
options {backtrack=true; output=AST;
ASTLabelType='org.eclipse.epsilon.common.parse.AST';
superClass='org.eclipse.epsilon.common.parse.EpsilonParser';}
import EolLexerRules, EolParserRules;
tokens { EDLMODULE; PROCESS; }
@header { package org.eclipse.epsilon.edl.parse; }
@lexer::header { package org.eclipse.epsilon.edl.parse; }
edlModule : importStatement* (edlModuleContent)* EOF
-> ^(EDLMODULE importStatement* edlModuleContent*);
edlModuleContent : processRule | operationDeclaration ;
processRule : r='process'^ formalParameter statementBlock
{$r.setType(PROCESS);} ;
ANTLR	Grammar:	Edl.g	
MoDELS	2016	 Advanced	Model	Management	with	Epsilon	 7
EdlModule.java	
•  InstanLates	the	generated	parser	
•  Obtains	a	homogeneous	concrete	syntax	tree	
(CST)	from	the	generated	EDL	parser	
•  Transforms	the	CST	into	an	abstract	syntax	tree	
(AST)	
–  AST	contains	instances	of	ProcessRule,	IfStatement,	
WhileStatement	etc.	
•  Executes	the	AST	
•  Heavily	reuses	EolLibraryModule	
–  70	lines	of	code	(excluding	imports	and	header)	
MoDELS	2016	 Advanced	Model	Management	with	Epsilon	 8
ProcessRule.java	
•  Abstract	syntax	element	for	EDL's	process	
rules	
•  Can	populate	itself	from	a	process	rule	CST	
•  Can	execute	itself	
•  Heavily	reuses	EOL	
– 40	lines	of	code	(excluding	imports	and	header)	
MoDELS	2016	 Advanced	Model	Management	with	Epsilon	 9
EDL's	ExecuLon	Engine	
•  ~15	lines	of	ANTLR	grammar	
•  <	200	lines	of	Java	code	
– <	100	non-empty	lines	(excluding	imports	and	
header)	
– Much	of	the	code	is	seTers	and	geTers	
MoDELS	2016	 Advanced	Model	Management	with	Epsilon	 10
EDL'S	ECLIPSE-BASED	
DEVELOPMENT	TOOLS	
org.eclipse.epsilon.edl.dt	
MoDELS	2016	 Advanced	Model	Management	with	Epsilon	 11
Overview	
•  Three	faciliLes	
–  New	EDL	file	wizard	
•  NewEdlFileWizard:	Trivial	(15	lines	of	code)	
–  Editor	
•  Syntax	highlighLng,	outline	view	etc.	
–  Launching	faciliLes	
•  Standard	Eclipse	run	configuraLon,	debugger	
•  Heavily	reuse	EOL's	respecLve	faciliLes	
–  364	lines	of	code	in	total	
–  168	lines	excluding	headers	and	imports	
–  +	49	lines	of	XML	for	the	plumbing	(plugin.xml)	
•  Compared	to	the	annotaLon-based	approach	we	need	to	also	
develop	(largely	by	extending	EOL's)	
–  an	editor	
–  a	debugger	
MoDELS	2016	 Advanced	Model	Management	with	Epsilon	 12
EDL	EDITOR	
87	lines	of	code	
MoDELS	2016	 Advanced	Model	Management	with	Epsilon	 13
MoDELS	2016	 Advanced	Model	Management	with	Epsilon	 14
MoDELS	2016	 Advanced	Model	Management	with	Epsilon	 15
LAUNCHING	FACILITIES	
MoDELS	2016	 Advanced	Model	Management	with	Epsilon	 16
MoDELS	2016	 Advanced	Model	Management	with	Epsilon	 17
MoDELS	2016	 Advanced	Model	Management	with	Epsilon	 18
EDL's	Development	Tools	
Class	 LoC	 Exc.	Imports/Headers	
EdlModuleContentProvider	 37	 26	
EdlModuleElementLabelProvider	 38	 18	
EdlEditor	 59	 33	
EdlEditorStaLcTemplateContributor	 29	 10	
EdlSourceConfiguraLonTab	 48	 31	
EdlDebugger	 28	 11	
EdlLaunchConfiguraLonDelegate	 30	 12	
EdlLaunchConfiguraLonTabGroup	 24	 7	
NewEdlFileWizard	 32	 15	
EdlPlugin	 21	 5	
Total	 346	 168	
MoDELS	2016	 Advanced	Model	Management	with	Epsilon	 19
Summary	
•  <300	lines	of	code	for	a	new	model	
management	language	with	custom	syntax	
– …	and	its	development	tools	
•  Not	bad	at	all	😎	
MoDELS	2016	 Advanced	Model	Management	with	Epsilon	 20
MoDELS	2016	 Advanced	Model	Management	with	Epsilon	 21

Developing a new Epsilon Language through Grammar Extension: The Epsilon Demo Language (EDL)