Reflections on teaching MPS
within a university course
Turku Centre for Computer Science
Mikhail Barash
Åbo Akademi Finland
MPS
@mikhail_barash
Course overview
DSL Xtext MPS design
Course overview
zoo of DSLs
definition of a DSL
semantic models
examples
advantages problems
abstract syntax trees grammars parser generators
Xtext
Xtend
writing a grammar
model modification type checking code generationscoping
projectional editing
structureMPS editor typesystem textgen generator behavior
DSL design concerns
intentions
language workbenches overview
trainees considerable practical experience
intensive tutorialtraining focused on MPS
limited time allocate to trainings
interactive
attribute grammars parsing
type checking semantics
megamodeling rewriting
code generation testing
…
“classical” course
Rascal
How to introduce projectional editing?
form builders
Scratch-like
MS Access MS Access
How to introduce projectional editing?
Mathcad
MS FrontPage
Projectional editing & modeling
semantic model
syntactic
projection
placeholder
“smooth” editing
model
projection edited projection
projection
model
editor transforms text “sin” to projection of sine
“^” is transformed to projection of exponentiation
placeholder
Equation Editor
Microsoft Word vs. JetBrains MPS
select a placeholder
select desired concept from a menu
type something that would identify some concept
select something to augment it
either by typing
or by selecting
from menu
copy-paste copy entire subtrees
trigger for concept
alias
Parsing vs. projectional editing
int class = template + 5; template= + ;classint 5
<expression>= ;<name>int
<variable declaration>
= ;<name>int
<variable declaration>
<expression>
<left> + <right>
textual
projectional
concept
trigger for concept
trigger
editor always has access to AST
current concept
containing concept
<name>int
name: string
any string can be used here
changes will be propagated
throughout the source code
concepts can also be
chosen from a menu user’s intention
Projectional editing
textual form of code only meant for the programmer
projectional editing
allows languages to evolve
but it is unambiguous
languages can be combined with each other
set of node types that can be added to ASTnew DSL
nodes are selected explicitly no ambiguities in AST
textual syntax can look ambiguous
How to motivate it?
no parsing needed
non-textual notations
Starting with Xtext
grammar
validator
code generator
type checking
scoping
quickfixes
formatting
Starting with Xtext
grammar
validator
code generator
type checking
scoping
quickfixes
formatting
concrete ∩ abstract syntax
Starting with Xtext
grammar
validator
code generator
type checking
scoping
quickfixes
formatting
Java/Xtend
concrete ∩ abstract syntax
Starting with Xtext
grammar
validator
code generator
type checking
scoping
quickfixes
formatting
Java/Xtend
Java/Xtend
concrete ∩ abstract syntax
Starting with Xtext
grammar
validator
code generator
type checking
scoping
quickfixes
formatting
Java/Xtend
Java/Xtend
Java/Xtend
concrete ∩ abstract syntax
Starting with Xtext
grammar
validator
code generator
type checking
scoping
quickfixes
formatting
Java/Xtend
Java/Xtend
Java/Xtend
Java/Xtend
concrete ∩ abstract syntax
Starting with Xtext
grammar
validator
code generator
type checking
scoping
quickfixes
formatting internal DSL
Java/Xtend
Java/Xtend
Java/Xtend
Java/Xtend
concrete ∩ abstract syntax
Starting with Xtext
grammar
validator
code generator
type checking
scoping
quickfixes
formatting
M→T
internal DSL
Java/Xtend
Java/Xtend
Java/Xtend
Java/Xtend
concrete ∩ abstract syntax
Teaching MPS: topics covered
structure
editor
code generator
type system
intentions
formatting
M→T
abstract syntax
… editor
constraintsbehavior
actions
M→M
concrete syntax
development journey
Teaching MPS: topics covered
structure
editor
code generator
type system
intentions
formatting
M→T
abstract syntax
… editor
constraintsbehavior
actions
M→M
concrete syntax
DSL DSL DSL
DSL DSL
DSL
DSL
DSL DSL DSL
development journey
MPS: Editor aspect
button to negate
the current value
returns a JButton with event
handler that negates value
reading and writing data from an AST node requires
to handle node access explicitly
cells explained “on paper” first
MPS: Structure aspect structure of language
vs. structure of its
implementation
MPS: Structure aspect
language concepts IfStatement
abstract syntax
of the language
Entity
structure of language
vs. structure of its
implementation
MPS: Structure aspect
language concepts
technical concepts
IfStatement
NodeRendering
abstract syntax
of the language
Entity
VarReference
used to define diagram
editor for concept Node
structure of language
vs. structure of its
implementation
MPS: TypeSystem aspect
checking rules are in TypeSystem
check rules are still inference rules
:==: is not an assignment
Code generation
easier to start with model-to-text transformations
Learning objectives
program model! =
language its syntax! ≠
programming in MPS developing an API* ≈
abstract vs. concrete syntax
MPS multiple concrete syntaxes can be defined
language can evolve! a motivation for projectional editing
source code text! ≠
textual graphicaltabular mathematicalnotations
right level of abstractions
clearly separated

Reflections on teaching JetBrains MPS within a university course

  • 1.
    Reflections on teachingMPS within a university course Turku Centre for Computer Science Mikhail Barash Åbo Akademi Finland MPS @mikhail_barash
  • 2.
  • 3.
    Course overview zoo ofDSLs definition of a DSL semantic models examples advantages problems abstract syntax trees grammars parser generators Xtext Xtend writing a grammar model modification type checking code generationscoping projectional editing structureMPS editor typesystem textgen generator behavior DSL design concerns intentions language workbenches overview
  • 4.
    trainees considerable practicalexperience intensive tutorialtraining focused on MPS limited time allocate to trainings interactive
  • 5.
    attribute grammars parsing typechecking semantics megamodeling rewriting code generation testing … “classical” course Rascal
  • 6.
    How to introduceprojectional editing? form builders Scratch-like MS Access MS Access
  • 7.
    How to introduceprojectional editing? Mathcad MS FrontPage
  • 8.
    Projectional editing &modeling semantic model syntactic projection placeholder “smooth” editing model projection edited projection projection model editor transforms text “sin” to projection of sine “^” is transformed to projection of exponentiation placeholder Equation Editor
  • 9.
    Microsoft Word vs.JetBrains MPS select a placeholder select desired concept from a menu type something that would identify some concept select something to augment it either by typing or by selecting from menu copy-paste copy entire subtrees trigger for concept alias
  • 10.
    Parsing vs. projectionalediting int class = template + 5; template= + ;classint 5 <expression>= ;<name>int <variable declaration> = ;<name>int <variable declaration> <expression> <left> + <right> textual projectional concept trigger for concept trigger editor always has access to AST current concept containing concept <name>int name: string any string can be used here changes will be propagated throughout the source code concepts can also be chosen from a menu user’s intention
  • 11.
    Projectional editing textual formof code only meant for the programmer projectional editing allows languages to evolve but it is unambiguous languages can be combined with each other set of node types that can be added to ASTnew DSL nodes are selected explicitly no ambiguities in AST textual syntax can look ambiguous How to motivate it? no parsing needed non-textual notations
  • 12.
    Starting with Xtext grammar validator codegenerator type checking scoping quickfixes formatting
  • 13.
    Starting with Xtext grammar validator codegenerator type checking scoping quickfixes formatting concrete ∩ abstract syntax
  • 14.
    Starting with Xtext grammar validator codegenerator type checking scoping quickfixes formatting Java/Xtend concrete ∩ abstract syntax
  • 15.
    Starting with Xtext grammar validator codegenerator type checking scoping quickfixes formatting Java/Xtend Java/Xtend concrete ∩ abstract syntax
  • 16.
    Starting with Xtext grammar validator codegenerator type checking scoping quickfixes formatting Java/Xtend Java/Xtend Java/Xtend concrete ∩ abstract syntax
  • 17.
    Starting with Xtext grammar validator codegenerator type checking scoping quickfixes formatting Java/Xtend Java/Xtend Java/Xtend Java/Xtend concrete ∩ abstract syntax
  • 18.
    Starting with Xtext grammar validator codegenerator type checking scoping quickfixes formatting internal DSL Java/Xtend Java/Xtend Java/Xtend Java/Xtend concrete ∩ abstract syntax
  • 19.
    Starting with Xtext grammar validator codegenerator type checking scoping quickfixes formatting M→T internal DSL Java/Xtend Java/Xtend Java/Xtend Java/Xtend concrete ∩ abstract syntax
  • 20.
    Teaching MPS: topicscovered structure editor code generator type system intentions formatting M→T abstract syntax … editor constraintsbehavior actions M→M concrete syntax development journey
  • 21.
    Teaching MPS: topicscovered structure editor code generator type system intentions formatting M→T abstract syntax … editor constraintsbehavior actions M→M concrete syntax DSL DSL DSL DSL DSL DSL DSL DSL DSL DSL development journey
  • 22.
    MPS: Editor aspect buttonto negate the current value returns a JButton with event handler that negates value reading and writing data from an AST node requires to handle node access explicitly cells explained “on paper” first
  • 23.
    MPS: Structure aspectstructure of language vs. structure of its implementation
  • 24.
    MPS: Structure aspect languageconcepts IfStatement abstract syntax of the language Entity structure of language vs. structure of its implementation
  • 25.
    MPS: Structure aspect languageconcepts technical concepts IfStatement NodeRendering abstract syntax of the language Entity VarReference used to define diagram editor for concept Node structure of language vs. structure of its implementation
  • 26.
    MPS: TypeSystem aspect checkingrules are in TypeSystem check rules are still inference rules :==: is not an assignment
  • 27.
    Code generation easier tostart with model-to-text transformations
  • 28.
    Learning objectives program model!= language its syntax! ≠ programming in MPS developing an API* ≈ abstract vs. concrete syntax MPS multiple concrete syntaxes can be defined language can evolve! a motivation for projectional editing source code text! ≠ textual graphicaltabular mathematicalnotations right level of abstractions clearly separated