This document discusses domain-specific languages (DSLs) and how Smalltalk is well-suited for building DSLs. It provides examples of internal DSLs built in Smalltalk, including Mondrian for visualization, Glamour for data exploration, and Seaside for web applications. It also discusses techniques for mastering embedded DSLs, such as adopting, extending, or overloading syntax and semantics. Finally, it notes how Smalltalk provides homogeneous tools that are useful for building DSLs.
1 of 80
Downloaded 12 times
More Related Content
Choose'10: Stephane Ducasse - Powerful DSL engineering in Smalltalk
2. S.Ducasse
RMod
A word of introduction
Re鍖ective, metamodeler and happy programmer
Wrote several books on Smalltalk
Pharo by example, Squeak by Example, ...
Pushed Moose
http://www.moosetechnology.org
Building Pharo
http://www.pharo-project.org
Maintained Squeak
http://www.squeak.org
2
3. S.Ducasse
RMod
RMOD INRIA Team
Software evolution and software composition
Axis 1: Maintaining large software systems
Moose: a platform for reengineering,
http://moosetechnology.com
Axis 2: Modular and Secure Re鍖ective languages
Revisiting fundamental aspects of OO languages
Traits (SUN Microsystems...), Classboxes
Pharo open-source Smalltalk
http://www.pharo-project.org
Starting to work on a secure re鍖ective languages
3
4. S.Ducasse
RMod
Roadmap
A word about design
Smalltalk an executable modeling language
Internal DSLs industrial examples
Mondrian
Glamour
Seaside
Helvetia: mastering embedded languages
Tools: PetitParser
Conclusion
4
16. S.Ducasse
RMod
A Simple and Pure Model
Everything is an object (no primitive)
Only message passing (virtual)
Public methods/Private attributes
Single inheritance
Class extension (Program slices)
Closures
16
30. S.Ducasse
RMod
initialize
Initialize the internal state of a newly created tomagoshi
super initialize.
tummy := 0.
hunger := 2 atRandom + 1.
self dayStart.
self wakeUp
dayStart
night := false.
dayCount := 10
30
31. S.Ducasse
RMod
timePass
"Manage the night and day alternance and digestion"
Beeper beep.
dayCount := dayCount -1.
dayCount isZero
ifTrue:[ self nightOrDayEnd.
dayCount := 10].
self digest
digest
"Digest slowly: every two cycle, remove one from the tummy
(dayCount isDivisibleBy: 2)
ifTrue: [ tummy := tummy -1]
31
35. S.Ducasse
RMod
External Languages
Tools: make, 鍖ex, yacc
Data: awk, sed, XPath, Regular Expressions, SQL
+ expressive, full control
- expensive to implement, no tools, hard to pass data around
35
37. S.Ducasse
RMod
Embedded Languages
Language Workbenches: JetBrains MPS, Intentional Software
+ common infrastructure for different languages
- new language, new tools, non-standard host language,
targeted at domain experts (no programmers)
37
39. S.Ducasse
RMod
Mondrian a scriptable visualization language
fast brainstorming of ideas
interactive
developed by Girba/Meer (SCG, Bern),
maintained, optimized by Bergel (Pleaid, Santiago, Chile)
heavily used by researchers in reengineering
part of Moose
39
40. S.Ducasse
RMod
The view consists of nodes and edges
view :=ViewRenderer new.
view nodes: classes.
view edges: classes from: [:each | each superclass]
to: [:each | each].
view treeLayout.
view open.
40
41. S.Ducasse
RMod
Visual representation is given by the shape
view :=ViewRenderer new.
view borderedRectangleShape height: [:each |
each numberOfMethods].
view nodes: classes.
view edges: classes
from: [:each | each superclass]
to: [:each | each].
view treeLayout.
view open.
41
42. S.Ducasse
RMod
Blocks can be replaced by symbols
view :=ViewRenderer new.
view borderedRectangleShape height:
#numberOfMethods.
view nodes: classes.
view edgesFrom: #superclass.
view treeLayout.
view open.
42
51. S.Ducasse
RMod
Seaside
To build dynamic applications
Applications in production since 2002
Natural Flow
Reusable statefull components
Secure by default
Web 2.0
http://www.seaside.st
51
77. S.Ducasse
RMod
Scannerless Parsers combine what is usually done by two independent tools
(scanner and parser) into one. This makes writing a grammar much simpler and
avoids common problems when grammars are composed.
Parser Combinators are building blocks for parsers modeled as a graph of composable
objects; they are modular and maintainable, and can be changed, recomposed,
transformed and re鍖ected upon.
Parsing Expression Grammars (PEGs) provide ordered choice. Unlike in parser
combinators, the ordered choice of PEGs always follows the 鍖rst matching alternative
and ignores other alternatives. Valid input always results in exactly one parse-tree, the
result of a parse is never ambiguous.
Packrat Parsers give linear parse time guarantees and avoid common problems with
left-recursion in PEGs.
77
78. S.Ducasse
RMod
BNF
ID ::= letter { letter | digit } ;
Ometa2
id = letter (letter | digit)*
PetitParser
id := #letter asParser ,
! (#letter asParser / #digit asParser) star
78
79. S.Ducasse
RMod
Smalltalk is a serious player in DSL
Trivial model
Trivial syntax
Internal DSLs
Embedded DSLs
Full tool support
Extensible (build your own)
Executable
79