SlideShare a Scribd company logo
1 of 30
Download to read offline
ahead of one’s time
Domain Specific Languages
Groovy, Antlr
“Computer programming language of limited
expressivenes focused on a particular domain”
Specialized to solve problems within that domain
Easy to understand
Executable by computer
Not necessarily a completely new language(Internal/External)
HTML, CSS, RegEx, XSLT, Spring xml configs, SQL...
What is Domain specific language?
DSL goals
To be more expressive in its domain – more powerful
Include domain experts in application development
Extraction of bussines logic – separate lifecycle
Easier work in its domain
Let's think about Turtle
● It can move in 2 dimensional space
● It can draw paths
● We can turn it, move and reset it
DSL Example – problem
Requirements & Goals
We want to move the turtle by DSL
We want to execute the DSL actions one by one
Comparison between Groovy and Antlr
DSL Example
●
4 actions
– Parametrized
●
excluding reset
– changing state of the turtle
– changing state of the world
●
Sequential evaluation
turn left
move 5
turn right
move 30
pen down
turn right
move 5
turn right
move 3
pen up
reset
DSL Example – Semantic model
Representation of the same subject DSL describes
DSL populates the semantic model
Covers semantic aspects of the problem
Not depending on the DSL
In this case quite simple:
Action Turtle World
Execution class model
<<interface>>
Executor
GroovyExecutor AntlrExecutor
<<interface>>
Action
TurnLeftAction
ResetAction
PenUpAction
PenDownAction
MoveAction
TurnRightAction
DSL in Groovy
GroovyShell shell = new GroovyShell();
Script script = shell.parse(config);
script.run();
…..aand we are done, right?
DSL in Groovy
...not yet
Let's see how its evaluated
turn left
move 5
pen down
turn right
reset
●
●
●
turn(left) // left is a var
move(5) // 5 is number
pen(down) // down is var
turn(right) // right is var
reset // reset is var
DSL in Groovy – Binding methods
●
● Binding binding = new Binding()
● binding.setVariable("move", new Closure<Object>(null) {
– @Override
– public Object call(Object... args) {
● turtleActions.add(new MoveAction((Integer)
args[0]));
● return null;
– }
● });
DSL in Groovy – Binding variables
binding.setVariable("left", TurnDirection.LEFT);
binding.setVariable("right", TurnDirection.RIGHT);
binding.setVariable("down", PenState.DOWN);
binding.setVariable("up", PenState.UP);
DSL in Groovy – Binding reset
●
● Binding binding = new Binding() {
@Override
– public Object getVariable(String name) {
● if ("reset".equals(name)) {
– turtleActions.add(new ResetAction());
– return null;
● }
● return super.getVariable(name);
– }
● };
DSL in Groovy – Security, restrictions & tweaks
Compilation customization
● Import customization
– Regular, static, star
● AST transformation customization
– Rewriting methods...
● SecureASTCustomizer
– Allow/disallow – closures, imports, method
definitions, tokens, constant types...
Security manager
● Restricting permissions
Antlr
●
● ANTLR (ANother Tool for Language Recognition)
● Powerful parser generator for reading, processing,
executing, or translating structured text or binary files.
● From a grammar, ANTLR generates a parser that can build
and walk parse trees.
Antlr – Principles
DSL in Antlr – Grammar - Base
●
● grammar Turtle;
●
● execution
● : action+
● ;
● action
● : turnAction
● | moveAction
● | penAction
● | resetAction
● ;
DSL in Antlr – Grammar - Actions
–
– turnAction
● : TURN direction;
– direction
● : LEFT
● | RIGHT
● ;
– moveAction
● : MOVE NUMBER
● ;
–
–
–
– penAction
● : PEN penState;
penState
● : UP
● | DOWN
● ;
– resetAction
– : RESET
– ;
DSL in Antlr – Grammar - Tokens
●
● TURN : 'turn';
● MOVE : 'move';
● RESET : 'reset';
● LEFT : 'left';
● RIGHT : 'right';
● PEN : 'pen';
● UP : 'up';
● DOWN : 'down';
● NUMBER : [1-9][0-9]*;
● WS
● : ( ' ' | 't' | 'r' | 'n' )+ -> skip
● ;
DSL in Antlr – Grammar – Parse tree
DSL in Antlr
Antlr generates:
● Token list
● TurtleLexer
● TurtleParser
● TurtleListener – SAX approach
● TurtleBaseListener
● TurtleVisitor – DOM approach
● TurtleBaseVistor
DSL in Antlr – Visitor
TurtleActionBuildingVisitor extends
TurtleBaseVisitor<List<TurtleAction>> {
@Override
public List<TurtleAction> visitResetAction(
@NotNull ResetActionContext ctx) {
return toList(new ResetAction());
}
...
}
DSL in Antlr – Visitor
– public List<TurtleAction> visitPenAction(
– @NotNull PenActionContext ctx) {
● PenStateContext penStateContext = ctx.penState();
● If (penStateContext.UP() != null) {
– return toList(new PenUpAction());
● }
● if (penStateContext.DOWN() != null) {
– return toList(new PenDownAction());
● }
● throw new IllegalStateException("Unknown pen state:" +
penStateContext.getText());
– }
DSL in Antlr – Executor
●
● ANTLRInputStream input = new ANTLRInputStream(dsl);
●
● TurtleLexer turtleLexer = new TurtleLexer(input);
●
● CommonTokenStream tokenStream = new
– CommonTokenStream(turtleLexer);
●
● TurtleParser turtleParser = new TurtleParser(tokenStream);
●
DSL in Antlr – Executor
●
● ExecutionContext executionContext =
– turtleParser.execution();
●
● TurtleActionBuildingVisitor turtleActionBuildingVisitor =
– new TurtleActionBuildingVisitor();
●
● List<TurtleAction> actionList =
● turtleActionBuildingVisitor.visit(executionContext);
DSL in action
Which tool is better?
Pros & Cons
Groovy
✔ Lot of goodness out of the box
✔ Expressions evaluation
✔ GPL fallback
✔ Interoperability with Java
✔ Built-in intepretation
✗ Security & restricting
✗ Hidden complexity
✗ Syntax restrictions
Antrl
✔ Encourages separation
✔ Syntax validation
✔ Tooling
✔ Left Recursion support
✔ No Syntax restrictions
✗ Grammar complexity
✗ Visitor restrictions
✗ Custom interpretation
Useful references
http://www.slideshare.net/predo/embedding-groovy-in-a-java-application
http://www.slideshare.net/glaforge/going-to-mars-with-groovy-domainspecific-languages
http://www.antlr.org/
Fowler, M. 2010. Domain-Specific Languages
ahead of one’s time
Thank you for your attention
For more information, please contact me at
vganz@davincisoftware.sk

More Related Content

What's hot

Scala + WattzOn, sitting in a tree....
Scala + WattzOn, sitting in a tree....Scala + WattzOn, sitting in a tree....
Scala + WattzOn, sitting in a tree....Raffi Krikorian
 
DConf 2016: Keynote by Walter Bright
DConf 2016: Keynote by Walter Bright DConf 2016: Keynote by Walter Bright
DConf 2016: Keynote by Walter Bright Andrei Alexandrescu
 
Declarative Infrastructure Tools
Declarative Infrastructure Tools Declarative Infrastructure Tools
Declarative Infrastructure Tools Yulia Shcherbachova
 
Tweaking performance on high-load projects
Tweaking performance on high-load projectsTweaking performance on high-load projects
Tweaking performance on high-load projectsDmitriy Dumanskiy
 
Handling 20 billion requests a month
Handling 20 billion requests a monthHandling 20 billion requests a month
Handling 20 billion requests a monthDmitriy Dumanskiy
 
Swift Sequences & Collections
Swift Sequences & CollectionsSwift Sequences & Collections
Swift Sequences & CollectionsCocoaHeads France
 
Using QString effectively
Using QString effectivelyUsing QString effectively
Using QString effectivelyRoman Okolovich
 
Imports my sql
Imports my sqlImports my sql
Imports my sqlobertksg
 
Stream Processing in the Cloud - Athens Kubernetes Meetup 16.07.2019
Stream Processing in the Cloud - Athens Kubernetes Meetup 16.07.2019Stream Processing in the Cloud - Athens Kubernetes Meetup 16.07.2019
Stream Processing in the Cloud - Athens Kubernetes Meetup 16.07.2019Rafał Leszko
 
ConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with GroovyConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with GroovyIván López Martín
 
JVM performance options. How it works
JVM performance options. How it worksJVM performance options. How it works
JVM performance options. How it worksDmitriy Dumanskiy
 
Groovy and Grails talk
Groovy and Grails talkGroovy and Grails talk
Groovy and Grails talkdesistartups
 
Quirrel & R for Dummies
Quirrel & R for DummiesQuirrel & R for Dummies
Quirrel & R for DummiesJohn De Goes
 

What's hot (20)

Scala
ScalaScala
Scala
 
Scala + WattzOn, sitting in a tree....
Scala + WattzOn, sitting in a tree....Scala + WattzOn, sitting in a tree....
Scala + WattzOn, sitting in a tree....
 
Meetup slides
Meetup slidesMeetup slides
Meetup slides
 
DConf 2016: Keynote by Walter Bright
DConf 2016: Keynote by Walter Bright DConf 2016: Keynote by Walter Bright
DConf 2016: Keynote by Walter Bright
 
Declarative Infrastructure Tools
Declarative Infrastructure Tools Declarative Infrastructure Tools
Declarative Infrastructure Tools
 
RealmDB for Android
RealmDB for AndroidRealmDB for Android
RealmDB for Android
 
Playing the toStrings
Playing the toStringsPlaying the toStrings
Playing the toStrings
 
Tweaking performance on high-load projects
Tweaking performance on high-load projectsTweaking performance on high-load projects
Tweaking performance on high-load projects
 
Handling 20 billion requests a month
Handling 20 billion requests a monthHandling 20 billion requests a month
Handling 20 billion requests a month
 
Swift Sequences & Collections
Swift Sequences & CollectionsSwift Sequences & Collections
Swift Sequences & Collections
 
Using QString effectively
Using QString effectivelyUsing QString effectively
Using QString effectively
 
Imports my sql
Imports my sqlImports my sql
Imports my sql
 
Stream Processing in the Cloud - Athens Kubernetes Meetup 16.07.2019
Stream Processing in the Cloud - Athens Kubernetes Meetup 16.07.2019Stream Processing in the Cloud - Athens Kubernetes Meetup 16.07.2019
Stream Processing in the Cloud - Athens Kubernetes Meetup 16.07.2019
 
ConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with GroovyConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with Groovy
 
JVM performance options. How it works
JVM performance options. How it worksJVM performance options. How it works
JVM performance options. How it works
 
Groovy and Grails talk
Groovy and Grails talkGroovy and Grails talk
Groovy and Grails talk
 
Objective c(lang)
Objective c(lang)Objective c(lang)
Objective c(lang)
 
Quirrel & R for Dummies
Quirrel & R for DummiesQuirrel & R for Dummies
Quirrel & R for Dummies
 
Hadoop + Clojure
Hadoop + ClojureHadoop + Clojure
Hadoop + Clojure
 
Nicety of Java 8 Multithreading
Nicety of Java 8 MultithreadingNicety of Java 8 Multithreading
Nicety of Java 8 Multithreading
 

Viewers also liked

EclipseCon Europe 2011
EclipseCon Europe 2011EclipseCon Europe 2011
EclipseCon Europe 2011Sigasi
 
ANTLR Conference - OpenSpotLight driven by ANTLR
ANTLR Conference - OpenSpotLight driven by ANTLRANTLR Conference - OpenSpotLight driven by ANTLR
ANTLR Conference - OpenSpotLight driven by ANTLRAlexandre Porcelli
 
Graphical Programming is Dead
Graphical Programming is DeadGraphical Programming is Dead
Graphical Programming is DeadSigasi
 
Plc2 2015 your own ide
Plc2 2015 your own idePlc2 2015 your own ide
Plc2 2015 your own ideSigasi
 
Plc2 2015 first time right coding
Plc2 2015 first time right codingPlc2 2015 first time right coding
Plc2 2015 first time right codingSigasi
 
Shortening the feedback loop: faster and better code development
Shortening the feedback loop: faster and better code developmentShortening the feedback loop: faster and better code development
Shortening the feedback loop: faster and better code developmentSigasi
 
Building a software business — lessons learned
Building a software business — lessons learnedBuilding a software business — lessons learned
Building a software business — lessons learnedSigasi
 
Antlr Conference Drools & Hibernate
Antlr Conference   Drools & HibernateAntlr Conference   Drools & Hibernate
Antlr Conference Drools & HibernateAlexandre Porcelli
 
Domain specific languages in eclipse with Xtext (Zeus, UGent)
Domain specific languages in eclipse with Xtext (Zeus, UGent)Domain specific languages in eclipse with Xtext (Zeus, UGent)
Domain specific languages in eclipse with Xtext (Zeus, UGent)Sigasi
 
How to build a virtual machine
How to build a virtual machineHow to build a virtual machine
How to build a virtual machineTerence Parr
 
Creating your own coding style
Creating your own coding styleCreating your own coding style
Creating your own coding styleSigasi
 
An Update on the A400M, May 2013
An Update on the A400M, May 2013An Update on the A400M, May 2013
An Update on the A400M, May 2013ICSA, LLC
 
A400M Update June 2014
A400M Update June 2014A400M Update June 2014
A400M Update June 2014ICSA, LLC
 
Rear Admiral (Retired) Rapp looks at the role of LVC training
Rear Admiral (Retired) Rapp looks at the role of LVC trainingRear Admiral (Retired) Rapp looks at the role of LVC training
Rear Admiral (Retired) Rapp looks at the role of LVC trainingICSA, LLC
 
Airbus helicopters trade media briefing_2016
Airbus helicopters trade media briefing_2016Airbus helicopters trade media briefing_2016
Airbus helicopters trade media briefing_2016ICSA, LLC
 
Captain Nick Walker on the Queen Elizabeth Class Aircraft Carriers
Captain Nick Walker on the Queen Elizabeth Class Aircraft CarriersCaptain Nick Walker on the Queen Elizabeth Class Aircraft Carriers
Captain Nick Walker on the Queen Elizabeth Class Aircraft CarriersICSA, LLC
 
Code Generation Cambridge 2013 Introduction to Parsing with ANTLR4
Code Generation Cambridge 2013  Introduction to Parsing with ANTLR4Code Generation Cambridge 2013  Introduction to Parsing with ANTLR4
Code Generation Cambridge 2013 Introduction to Parsing with ANTLR4Oliver Zeigermann
 
Fadec full authority digital engine control-final
Fadec  full authority digital engine control-finalFadec  full authority digital engine control-final
Fadec full authority digital engine control-finalAbhishek Alankar
 
М.Гайворонский -- опыт разработки САУ двигателя
М.Гайворонский -- опыт разработки САУ двигателяМ.Гайворонский -- опыт разработки САУ двигателя
М.Гайворонский -- опыт разработки САУ двигателяAnatoly Levenchuk
 

Viewers also liked (20)

EclipseCon Europe 2011
EclipseCon Europe 2011EclipseCon Europe 2011
EclipseCon Europe 2011
 
ANTLR Conference - OpenSpotLight driven by ANTLR
ANTLR Conference - OpenSpotLight driven by ANTLRANTLR Conference - OpenSpotLight driven by ANTLR
ANTLR Conference - OpenSpotLight driven by ANTLR
 
Graphical Programming is Dead
Graphical Programming is DeadGraphical Programming is Dead
Graphical Programming is Dead
 
Plc2 2015 your own ide
Plc2 2015 your own idePlc2 2015 your own ide
Plc2 2015 your own ide
 
Plc2 2015 first time right coding
Plc2 2015 first time right codingPlc2 2015 first time right coding
Plc2 2015 first time right coding
 
Shortening the feedback loop: faster and better code development
Shortening the feedback loop: faster and better code developmentShortening the feedback loop: faster and better code development
Shortening the feedback loop: faster and better code development
 
Building a software business — lessons learned
Building a software business — lessons learnedBuilding a software business — lessons learned
Building a software business — lessons learned
 
Antlr Conference Drools & Hibernate
Antlr Conference   Drools & HibernateAntlr Conference   Drools & Hibernate
Antlr Conference Drools & Hibernate
 
Domain specific languages in eclipse with Xtext (Zeus, UGent)
Domain specific languages in eclipse with Xtext (Zeus, UGent)Domain specific languages in eclipse with Xtext (Zeus, UGent)
Domain specific languages in eclipse with Xtext (Zeus, UGent)
 
How to build a virtual machine
How to build a virtual machineHow to build a virtual machine
How to build a virtual machine
 
Creating your own coding style
Creating your own coding styleCreating your own coding style
Creating your own coding style
 
An Update on the A400M, May 2013
An Update on the A400M, May 2013An Update on the A400M, May 2013
An Update on the A400M, May 2013
 
A400M Update June 2014
A400M Update June 2014A400M Update June 2014
A400M Update June 2014
 
Fadec and hums
Fadec and humsFadec and hums
Fadec and hums
 
Rear Admiral (Retired) Rapp looks at the role of LVC training
Rear Admiral (Retired) Rapp looks at the role of LVC trainingRear Admiral (Retired) Rapp looks at the role of LVC training
Rear Admiral (Retired) Rapp looks at the role of LVC training
 
Airbus helicopters trade media briefing_2016
Airbus helicopters trade media briefing_2016Airbus helicopters trade media briefing_2016
Airbus helicopters trade media briefing_2016
 
Captain Nick Walker on the Queen Elizabeth Class Aircraft Carriers
Captain Nick Walker on the Queen Elizabeth Class Aircraft CarriersCaptain Nick Walker on the Queen Elizabeth Class Aircraft Carriers
Captain Nick Walker on the Queen Elizabeth Class Aircraft Carriers
 
Code Generation Cambridge 2013 Introduction to Parsing with ANTLR4
Code Generation Cambridge 2013  Introduction to Parsing with ANTLR4Code Generation Cambridge 2013  Introduction to Parsing with ANTLR4
Code Generation Cambridge 2013 Introduction to Parsing with ANTLR4
 
Fadec full authority digital engine control-final
Fadec  full authority digital engine control-finalFadec  full authority digital engine control-final
Fadec full authority digital engine control-final
 
М.Гайворонский -- опыт разработки САУ двигателя
М.Гайворонский -- опыт разработки САУ двигателяМ.Гайворонский -- опыт разработки САУ двигателя
М.Гайворонский -- опыт разработки САУ двигателя
 

Similar to DSL-Optimized Title for Domain Specific Languages Document

Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)Jonathan Felch
 
Optimizing a large angular application (ng conf)
Optimizing a large angular application (ng conf)Optimizing a large angular application (ng conf)
Optimizing a large angular application (ng conf)A K M Zahiduzzaman
 
Apache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLabApache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLabCloudxLab
 
Leveraging your Knowledge of ORM Towards Performance-based NoSQL Technology
Leveraging your Knowledge of ORM Towards Performance-based NoSQL TechnologyLeveraging your Knowledge of ORM Towards Performance-based NoSQL Technology
Leveraging your Knowledge of ORM Towards Performance-based NoSQL TechnologyDATAVERSITY
 
Ruby on Big Data (Cassandra + Hadoop)
Ruby on Big Data (Cassandra + Hadoop)Ruby on Big Data (Cassandra + Hadoop)
Ruby on Big Data (Cassandra + Hadoop)Brian O'Neill
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersMiles Sabin
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersAn Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersMiles Sabin
 
The Art Of Readable Code
The Art Of Readable CodeThe Art Of Readable Code
The Art Of Readable CodeBaidu, Inc.
 
BITS: Introduction to relational databases and MySQL - Schema design
BITS: Introduction to relational databases and MySQL - Schema designBITS: Introduction to relational databases and MySQL - Schema design
BITS: Introduction to relational databases and MySQL - Schema designBITS
 
Domain-Specific Languages
Domain-Specific LanguagesDomain-Specific Languages
Domain-Specific LanguagesJavier Canovas
 
Kerberizing Spark: Spark Summit East talk by Abel Rincon and Jorge Lopez-Malla
Kerberizing Spark: Spark Summit East talk by Abel Rincon and Jorge Lopez-MallaKerberizing Spark: Spark Summit East talk by Abel Rincon and Jorge Lopez-Malla
Kerberizing Spark: Spark Summit East talk by Abel Rincon and Jorge Lopez-MallaSpark Summit
 
Introduction to Scalding and Monoids
Introduction to Scalding and MonoidsIntroduction to Scalding and Monoids
Introduction to Scalding and MonoidsHugo Gävert
 
Building Go Web Apps
Building Go Web AppsBuilding Go Web Apps
Building Go Web AppsMark
 
MongoDB - A Document NoSQL Database
MongoDB - A Document NoSQL DatabaseMongoDB - A Document NoSQL Database
MongoDB - A Document NoSQL DatabaseRuben Inoto Soto
 

Similar to DSL-Optimized Title for Domain Specific Languages Document (20)

Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)
 
Groovy.pptx
Groovy.pptxGroovy.pptx
Groovy.pptx
 
Optimizing a large angular application (ng conf)
Optimizing a large angular application (ng conf)Optimizing a large angular application (ng conf)
Optimizing a large angular application (ng conf)
 
Introduction to Domain-Driven Design
Introduction to Domain-Driven DesignIntroduction to Domain-Driven Design
Introduction to Domain-Driven Design
 
Apache Spark & Streaming
Apache Spark & StreamingApache Spark & Streaming
Apache Spark & Streaming
 
Apache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLabApache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLab
 
Lobos Introduction
Lobos IntroductionLobos Introduction
Lobos Introduction
 
Leveraging your Knowledge of ORM Towards Performance-based NoSQL Technology
Leveraging your Knowledge of ORM Towards Performance-based NoSQL TechnologyLeveraging your Knowledge of ORM Towards Performance-based NoSQL Technology
Leveraging your Knowledge of ORM Towards Performance-based NoSQL Technology
 
Ruby on Big Data (Cassandra + Hadoop)
Ruby on Big Data (Cassandra + Hadoop)Ruby on Big Data (Cassandra + Hadoop)
Ruby on Big Data (Cassandra + Hadoop)
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java Developers
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersAn Introduction to Scala for Java Developers
An Introduction to Scala for Java Developers
 
The Art Of Readable Code
The Art Of Readable CodeThe Art Of Readable Code
The Art Of Readable Code
 
BITS: Introduction to relational databases and MySQL - Schema design
BITS: Introduction to relational databases and MySQL - Schema designBITS: Introduction to relational databases and MySQL - Schema design
BITS: Introduction to relational databases and MySQL - Schema design
 
9.4json
9.4json9.4json
9.4json
 
Domain-Specific Languages
Domain-Specific LanguagesDomain-Specific Languages
Domain-Specific Languages
 
DSL in scala
DSL in scalaDSL in scala
DSL in scala
 
Kerberizing Spark: Spark Summit East talk by Abel Rincon and Jorge Lopez-Malla
Kerberizing Spark: Spark Summit East talk by Abel Rincon and Jorge Lopez-MallaKerberizing Spark: Spark Summit East talk by Abel Rincon and Jorge Lopez-Malla
Kerberizing Spark: Spark Summit East talk by Abel Rincon and Jorge Lopez-Malla
 
Introduction to Scalding and Monoids
Introduction to Scalding and MonoidsIntroduction to Scalding and Monoids
Introduction to Scalding and Monoids
 
Building Go Web Apps
Building Go Web AppsBuilding Go Web Apps
Building Go Web Apps
 
MongoDB - A Document NoSQL Database
MongoDB - A Document NoSQL DatabaseMongoDB - A Document NoSQL Database
MongoDB - A Document NoSQL Database
 

More from Davinci software

Samuel Hopko & Daniel Rajčan - Cloud Computing
Samuel Hopko & Daniel Rajčan - Cloud ComputingSamuel Hopko & Daniel Rajčan - Cloud Computing
Samuel Hopko & Daniel Rajčan - Cloud ComputingDavinci software
 
Michal Hitka - Craft conference
Michal Hitka - Craft conferenceMichal Hitka - Craft conference
Michal Hitka - Craft conferenceDavinci software
 
Peter Kobes - What you should know about a professional Software Company
Peter Kobes - What you should know about a professional Software CompanyPeter Kobes - What you should know about a professional Software Company
Peter Kobes - What you should know about a professional Software CompanyDavinci software
 
Ladislav Božek - Čo možno neviete o Java platforme
Ladislav Božek - Čo možno neviete o Java platformeLadislav Božek - Čo možno neviete o Java platforme
Ladislav Božek - Čo možno neviete o Java platformeDavinci software
 
Tom van Ees - Academic and Commercial software Development
Tom van Ees - Academic and Commercial software DevelopmentTom van Ees - Academic and Commercial software Development
Tom van Ees - Academic and Commercial software DevelopmentDavinci software
 

More from Davinci software (6)

Samuel Hopko & Daniel Rajčan - Cloud Computing
Samuel Hopko & Daniel Rajčan - Cloud ComputingSamuel Hopko & Daniel Rajčan - Cloud Computing
Samuel Hopko & Daniel Rajčan - Cloud Computing
 
Michal Hitka - Craft conference
Michal Hitka - Craft conferenceMichal Hitka - Craft conference
Michal Hitka - Craft conference
 
Peter Kobes - What you should know about a professional Software Company
Peter Kobes - What you should know about a professional Software CompanyPeter Kobes - What you should know about a professional Software Company
Peter Kobes - What you should know about a professional Software Company
 
Ladislav Božek - Čo možno neviete o Java platforme
Ladislav Božek - Čo možno neviete o Java platformeLadislav Božek - Čo možno neviete o Java platforme
Ladislav Božek - Čo možno neviete o Java platforme
 
Tom van Ees - Academic and Commercial software Development
Tom van Ees - Academic and Commercial software DevelopmentTom van Ees - Academic and Commercial software Development
Tom van Ees - Academic and Commercial software Development
 
Peťo Rybár - Rest
Peťo Rybár - RestPeťo Rybár - Rest
Peťo Rybár - Rest
 

Recently uploaded

Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 

Recently uploaded (20)

Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 

DSL-Optimized Title for Domain Specific Languages Document

  • 1. ahead of one’s time Domain Specific Languages Groovy, Antlr
  • 2. “Computer programming language of limited expressivenes focused on a particular domain” Specialized to solve problems within that domain Easy to understand Executable by computer Not necessarily a completely new language(Internal/External) HTML, CSS, RegEx, XSLT, Spring xml configs, SQL... What is Domain specific language?
  • 3. DSL goals To be more expressive in its domain – more powerful Include domain experts in application development Extraction of bussines logic – separate lifecycle Easier work in its domain
  • 4. Let's think about Turtle ● It can move in 2 dimensional space ● It can draw paths ● We can turn it, move and reset it DSL Example – problem
  • 5. Requirements & Goals We want to move the turtle by DSL We want to execute the DSL actions one by one Comparison between Groovy and Antlr
  • 6. DSL Example ● 4 actions – Parametrized ● excluding reset – changing state of the turtle – changing state of the world ● Sequential evaluation turn left move 5 turn right move 30 pen down turn right move 5 turn right move 3 pen up reset
  • 7. DSL Example – Semantic model Representation of the same subject DSL describes DSL populates the semantic model Covers semantic aspects of the problem Not depending on the DSL In this case quite simple: Action Turtle World
  • 8. Execution class model <<interface>> Executor GroovyExecutor AntlrExecutor <<interface>> Action TurnLeftAction ResetAction PenUpAction PenDownAction MoveAction TurnRightAction
  • 9. DSL in Groovy GroovyShell shell = new GroovyShell(); Script script = shell.parse(config); script.run(); …..aand we are done, right?
  • 10. DSL in Groovy ...not yet Let's see how its evaluated turn left move 5 pen down turn right reset ● ● ● turn(left) // left is a var move(5) // 5 is number pen(down) // down is var turn(right) // right is var reset // reset is var
  • 11. DSL in Groovy – Binding methods ● ● Binding binding = new Binding() ● binding.setVariable("move", new Closure<Object>(null) { – @Override – public Object call(Object... args) { ● turtleActions.add(new MoveAction((Integer) args[0])); ● return null; – } ● });
  • 12. DSL in Groovy – Binding variables binding.setVariable("left", TurnDirection.LEFT); binding.setVariable("right", TurnDirection.RIGHT); binding.setVariable("down", PenState.DOWN); binding.setVariable("up", PenState.UP);
  • 13. DSL in Groovy – Binding reset ● ● Binding binding = new Binding() { @Override – public Object getVariable(String name) { ● if ("reset".equals(name)) { – turtleActions.add(new ResetAction()); – return null; ● } ● return super.getVariable(name); – } ● };
  • 14. DSL in Groovy – Security, restrictions & tweaks Compilation customization ● Import customization – Regular, static, star ● AST transformation customization – Rewriting methods... ● SecureASTCustomizer – Allow/disallow – closures, imports, method definitions, tokens, constant types... Security manager ● Restricting permissions
  • 15. Antlr ● ● ANTLR (ANother Tool for Language Recognition) ● Powerful parser generator for reading, processing, executing, or translating structured text or binary files. ● From a grammar, ANTLR generates a parser that can build and walk parse trees.
  • 17. DSL in Antlr – Grammar - Base ● ● grammar Turtle; ● ● execution ● : action+ ● ; ● action ● : turnAction ● | moveAction ● | penAction ● | resetAction ● ;
  • 18. DSL in Antlr – Grammar - Actions – – turnAction ● : TURN direction; – direction ● : LEFT ● | RIGHT ● ; – moveAction ● : MOVE NUMBER ● ; – – – – penAction ● : PEN penState; penState ● : UP ● | DOWN ● ; – resetAction – : RESET – ;
  • 19. DSL in Antlr – Grammar - Tokens ● ● TURN : 'turn'; ● MOVE : 'move'; ● RESET : 'reset'; ● LEFT : 'left'; ● RIGHT : 'right'; ● PEN : 'pen'; ● UP : 'up'; ● DOWN : 'down'; ● NUMBER : [1-9][0-9]*; ● WS ● : ( ' ' | 't' | 'r' | 'n' )+ -> skip ● ;
  • 20. DSL in Antlr – Grammar – Parse tree
  • 21. DSL in Antlr Antlr generates: ● Token list ● TurtleLexer ● TurtleParser ● TurtleListener – SAX approach ● TurtleBaseListener ● TurtleVisitor – DOM approach ● TurtleBaseVistor
  • 22. DSL in Antlr – Visitor TurtleActionBuildingVisitor extends TurtleBaseVisitor<List<TurtleAction>> { @Override public List<TurtleAction> visitResetAction( @NotNull ResetActionContext ctx) { return toList(new ResetAction()); } ... }
  • 23. DSL in Antlr – Visitor – public List<TurtleAction> visitPenAction( – @NotNull PenActionContext ctx) { ● PenStateContext penStateContext = ctx.penState(); ● If (penStateContext.UP() != null) { – return toList(new PenUpAction()); ● } ● if (penStateContext.DOWN() != null) { – return toList(new PenDownAction()); ● } ● throw new IllegalStateException("Unknown pen state:" + penStateContext.getText()); – }
  • 24. DSL in Antlr – Executor ● ● ANTLRInputStream input = new ANTLRInputStream(dsl); ● ● TurtleLexer turtleLexer = new TurtleLexer(input); ● ● CommonTokenStream tokenStream = new – CommonTokenStream(turtleLexer); ● ● TurtleParser turtleParser = new TurtleParser(tokenStream); ●
  • 25. DSL in Antlr – Executor ● ● ExecutionContext executionContext = – turtleParser.execution(); ● ● TurtleActionBuildingVisitor turtleActionBuildingVisitor = – new TurtleActionBuildingVisitor(); ● ● List<TurtleAction> actionList = ● turtleActionBuildingVisitor.visit(executionContext);
  • 27. Which tool is better?
  • 28. Pros & Cons Groovy ✔ Lot of goodness out of the box ✔ Expressions evaluation ✔ GPL fallback ✔ Interoperability with Java ✔ Built-in intepretation ✗ Security & restricting ✗ Hidden complexity ✗ Syntax restrictions Antrl ✔ Encourages separation ✔ Syntax validation ✔ Tooling ✔ Left Recursion support ✔ No Syntax restrictions ✗ Grammar complexity ✗ Visitor restrictions ✗ Custom interpretation
  • 30. ahead of one’s time Thank you for your attention For more information, please contact me at vganz@davincisoftware.sk