Welcome! This tutorial was designed specifically for developers, who are completely new to MPS and prefer a guided tour through the MPS landscape. You will walk the beaten path one step at a time, following clear marks that show you where to go next. The information is structured so that you progress from simpler concepts to the more involved ones and at the end of the journey you'll understand MPS and will be able to use it effectively on your projects.
We admit that there are easier tasks in the world than learning MPS. Language design is a complex domain and projectional editing needs some getting used to. It helps a lot if you have prior experience with DSLs or language workbenches, but it is not necessary for understanding this tutorial. Just expect more bumps on the road. There certainly will be a lot of them - partly also because MPS has its own problems and bugs. So you are in for a tough experience that may take quite a big amount of your time.
Bear in mind that many have walked through here before and succeeded. If you persist you'll be rewarded - you'll become a language designer who can prepare custom-tailored DSLs, integrate them into projects and develop high-value software with them.
So, take on good shoes, lace them tight and start going ...
- Ten steps to mastery
- ステップ 1 - Why MPS
- Step 2 - Install MPS and study the fundamentals
- Step 3 - MPS from the programmer's perspective
- Configure the editor
- Be safe, wear the seatbelts
- A quick ride
- Step 4 - MPS from the language designer's perspective
- Step 5 - Projectional editing tips and tricks
- Step 6 - Creating your first language
- Step 7 - Shapes tutorial
- Step 8 - Calculator tutorial
- Step 9 - The Garage project tutorial
- Step 10 - Generator tutorial
- Reviewing the progress
- Moving up the ladder
- Documentation sources
- Academic papers
- Guided Trainings
- General documentation
- Other sample projects
- Language extensions:
- Standalone languages:
- Samples to tutorials:
Ten steps to mastery
ステップ 1 - Why MPS
Raw time estimate - 45 minutes
Let's start with some motivation for learning MPS.
First of all, check out a two-minute overview video about MPS - なぜJetBrains MPSなのか(英語) , so you can assess whether this tool offers something that you need on your projects.
Our new VoiceMenu demo application(英語) has been created to give people coming from different domains of expertise a quick understanding of the potential of MPS. Watch a short https://youtu.be/pVIywLXDuRo(英語)。
JetBrains MPS is an efficient and reliable development tool that has been adopted by software vendors on both commercial and academic projects. MPS-based DSLs have been adopted in wide range of domains, such as legislation modelling, electrical engineering, insurance industry, embedded software, medicine systems, bio-informatics and data analysis. The " 使い方(英語) " page lists several of the successful projects and gives a high-level overview of the technology used.
You may also like to slow down a bit and read a few documents describing how people have succeeded with MPS. We've collected a few case studies that may inspire you to your own ideas on building something great around MPS.
Step 2 - Install MPS and study the fundamentals
Raw time estimate - 45 minutes
Watch this video first - 初めての走行(英語) . It gives you the essential information into how MPS is organised, how it works and how users are supposed to interact with it.
If you are carefully evaluating MPS there must be many questions hoping up in your head while watching videos or reading stories about MPS usages. I believe that some of these questions have already been answered in the MPS FAQ page . Check it out,
Read a gentle introductory article on MPS fundamentals(英語) by Mikhail Barash. This is definitely worth your time at this moment, since you will understand all the principles as soon as you read the article.
Stop for a minute now and skim through a short page listing the essential terms like node, Concept, AST in order to understand better the terminology used down the line.
Plain reading about MPS will never teach you as much as trying it for real yourself. You might have done this already, but if not, grab MPS from the download site(英語) and install it. With MPS installed you will be able to continue on the Fast Track。
Step 3 - MPS from the programmer's perspective
Raw time estimate - 45 minutes
Before you continue, you should probably get to know the most distinct feature of MPS - the projectional editor. Check out a video(英語) that explains all the differences between traditional textual editors and the MPS projectional editor and lists the numerous benefits of this approach.
Configure the editor
We are all different. If the default settings that MPS comes with do not fit your habits, you can always change them in the 環境設定 (MacOs, press Cmd +、 ) or 設定 (Windows, press Control + Shift + Space , or go to the menu File -> Settings ). One of the most likely settings to change is the font size in the Editor -> General section:
Be safe, wear the seatbelts
Knowing keyboard shortcuts turns good developers into great ones. As you learn MPS you will internalize various key combinations that trigger useful MPS functionalities. There's one key combination that you should remember from the very beginning, though - コントロール/コマンド+ Z . One again - コントロール/コマンド+ Z . It is the 元に戻す action. Whenever you either intentionally or by mistake do something wrong and you want do get back to functional code, turn to コントロール/コマンド+ Z .
A quick ride
Since we programmers like trying things, how about taking the MPS editor for a simple test ride first? You may get the first impressions instantly, if you start MPS and open the ロボットカヤ sample project. This project defines an artificial language to command a virtual robot. The robot can move within a rectangular area, drop and collect marks and check the surrounding cells for walls and marks. You write スクリプト using the built-in commands as well as new commands that you create on the fly. When you run the script a simulator written in Java is started to visualize the execution of your program.
To open the project, start your fresh MPS, click on the サンプル・プロジェクトを開く button and pick robot_Kaja. The sample projects have been installed into your HOME/MPSSamples folder.
We also shot an instructional screen-cast to help you start(英語) . Check it out.
Step 4 - MPS from the language designer's perspective
Raw time estimate - 40 minutes
Now you must be curious about how the robot sample language has been created. Please, open again the ロボットカヤ sample project and play our explanatory screen-cast showing you round the language definition fundamentals(英語) . As you go through the video, pause frequently and look around the sample project yourself. This way you will understand a typical language structure and see the relationships between its individual parts.
At this point you should understand that language definition consists of several aspects. Some of these are mandatory, some are optional:
構造 - Defines the kinds of nodes (called 概念 ) that may be used in user models. Each node in the program (model) refers to its concept. 概念 specify, which properties, children and references nodes may have. 概念 can extend other 概念 and implement ConceptInterfaces .
- 制約 - Restricts the relationships between nodes as well as the allowed values for properties beyond the rules defined in 構造 . Constraints typicaly define:
the target scope for references (a collection of allowed nodes a reference can point to)
situations, in which a node can be a child/parent/ancestor of another node
allowed values for properties
property accessor methods (Getter および Setter)
振る舞い - Just like classes in OOP hold methods, 概念 may define methods and static methods that can be invoked on nodes in a polymorphic way. ノード thus carry behaviour alongside their properties and relationships.
エディター - Instead of defining a parser that would translate code from an editable form (i.e. text) into the tree-like structure that a computer could manipulate, MPS offers the concept of projectional editor, which let's the user edit the AST directly. The エディター aspect enables language designers to create a UI for editing their concept concepts.
アクション - Since the MPS editor manipulates the underlying AST directly, some editing actions, such as copy-paste or replacing one node with another one translate into non-trivial AST changes. The アクション aspect holds definitions of such customised AST transformations.
インテンション - All modern IDEs assist developers with instant code manipulating action available under a handy key-shortcut (Alt + Enter in MPS). Language authors can define such little code transformations for their languages in the インテンション aspect.
型システム - Language that need to type-check their code need to provide type-system rules. The MPS type-system engine will evaluate the rules on-the-fly, calculate types for nodes and report
errors, wherever the calculated type differs from the expectations.
So called checking rules may additionally be defined to verify non-typesystem assertions about the model.
データフロー - The ability to understand the flow of values and the flow of control through language constructs helps languages report issues such as unreachable code or nullポインタエラーの可能性 . Language designer can leverage the データフロー aspect to define the flow for each concept, which MPS will then use to calculate the dataflow for the whole program.
生成プログラム - Models written in one or more languages get ultimately translated into runnable code in some target general-purpose language and platform, such as Java. Along the way models get gradually transformed so that repeatedly concepts get replaced with concepts from a lower level of abstraction until the bottom-line level is reached. The rules for translating concepts and their proper ordering is defined in the 生成プログラム aspect.
TextGen - During code generation after the 生成プログラム has reached the bottom-line AST representation, the TextGen phase kicks in and translates all nodes in the model into their textual representation and saves the resulting textual source files on disk.
Step 5 - Projectional editing tips and tricks
Raw time estimate - 30 minutes
When editing code in MPS you will run into situations when your coding habits interfere with the projectional nature of the MPS editor. I'm actually pretty confident that you have already discovered such surprises during your experiments. Code in MPS is not text, but instead it is a projection of the abstract syntax (AST). This gives several benefits to language designers and, at the same time, makes the editing experience slightly different and more-restrictive than in the commonplace text editors. This may or may not be considered to be an advantage, nevertheless, there is a learning curve to projectional editing. In general, in projectional code you more rely on the assistance of the editor. Code-completion, block selection and intention actions should become your close friends in order to become an efficient projectional coder. There's a good and a bad side to it:
good - in less than a week of programming in the MPS editor people typically get back to their full speed of coding they experienced before in text-based IDEs
bad - projectional editing is highly addictive and you may find text-based editors less compelling and less helpful than you thought they'd been before
Step 6 - Creating your first language
Raw time estimate - 3 hours
The next screen-cast to watch, MPSの基本 - あなたの最初の言語を作るこ(英語)と , will show you the typical workflow when creating a new language - building the structure, defining the editor and implementing the generator. You will see the creation process of the 定数 language, which is also included as a sample project with MPS distributions.
Now you're recommended to watch a series of short high-level videos that will give you a brief introduction into each of the aspects of a language definition:
Step 7 - Shapes tutorial
Raw estimate - 2 hours
Here's an opportunity for you to quickly get your own language. Check out the MPS entry-level Shapes Tutorial and build a language that enables non-programmers to build scenes of graphical shapes.
Step 8 - Calculator tutorial
Raw time estimate - 8 hours
Now you must be curious to find out more details about language design in MPS, right? Having given you all the fundamental information and some level of experience, the introductory tutorials should have left you in a good position to dive deeper and build a sample language all the way from the ground up. The Calculator tutorial(英語) will guide you through the process of language creation. You start with an empty project and end up with a language to build Java Swing-based visual applications. Try it out and have fun.
Step 9 - The Garage project tutorial
Raw time estimate - 5 hours
The Calculator tutorial should have left you with good overall knowledge of language design. Now it is time for a more thorough exercise. The garage project will have you create several interconnected languages, package them as reusable plugins and stack languages one above the other. To handle the complexity of this tutorial, we leverage the Stepik platform for online education. Enrol in the free MPS Elementary Course(英語)。
Step 10 - Generator tutorial
Raw time estimate - 4 hours
The final bit of knowledge that needs practising is the generator. The Generator tutorial will now teach you more subtle options that the MPS generator offers. You will learn about the different types of macros, generator scripts, utility models and more.
Reviewing the progress
Congratulations! By completing the above tutorials and exercises you've made a serious dent into the language design world. Your knowledge and command of MPS could now be qualified somewhere above the Advanced beginner stage of the Dreyfus model of skill acquisition(英語) . This is definitely a good time to celebrate and perhaps also to let us know(英語) about you success.
Moving up the ladder
The next stage in the Dreyfus model of skill acquisition(英語) is Competent . Once you reach that stage you'll be able to work on your own without concrete guidelines and supervision. But for this to happen, you'll need to spend more time solving various problems with MPS. If you already have an idea of a language to implement, go ahead and do it. If not, try to come up with a useful little language. You could as well try to re-implement one or more of the MPS samples and then see how closely you got. Or just pick a sample as the starting point and move it forward - add language features, implement a generator, add type-system rules, polish the editing experience - whatever feels like the right challenge for you.
Additionally, you should try these in order to become Competent in MPS and language design:
Study the 共通言語パターン
Study the cookbooks to deepen your knowledge of the various aspects of language design
Get to know quotations and anti-quotations
Get a feel for the user guide so you can quickly find the information that you need
Learn some of the keyboard shortcuts by heart
Become active in the MPS community and try to answer the forum(英語) questions of people that walk behind you on the same path to MPS mastery
After becoming Competent you should definitely continue gaining experience. The more you work with MPS and the more divert your projects are, the faster you'll be moving up on the Dreyfus model of skill acquisition(英語) scale. If you set yourself a goal to become Proficient and ultimately an エキスパート in MPS, you might consider trying:
- Studying and practising advanced topics, such as:
Helping MPS expand into there areas by creating a base language for a different target language/platform - Python, Ruby, Dart, Haskell, Go, etc
Speaking about MPS at events
Helping us evolve the documentation
Contributing code(英語) to the MPS project
Although there's not much detailed documentation to guide you at this experience level and you'll have to be self-driven most of the time, we'll always be happy to discuss, advise and cooperate with you.
Here's a list of documentation sources that you may need on your path to MPS mastery
Fabien Campagne wrote The MPS Language Workbench: Volume I and Volume II books, which you can purchase both electronically and as paper-back. Get them here(英語)。
The publications(英語) page collects all relevant papers about MPS and the related field.
The get slightly simplified practical information as well as some tips and tricks on individual aspects of language design, you may try some of the cookbooks.
共通言語パターン - if you need guidelines on how to implement certain functionality
説明コメント - a cookbookd showing how to leverage attributes to add support for description comments attached to arbitrary nodes
SModel language reference documentation to show you how to query your models
解決方法を見つける - a brief collection of guidelines that should help you move forward when you get stuck somewhere.
A full-blown reference documentation provides exhaustive information on MPS. Check out the Language designer's User Guide。
Over time the MPS team has created a large collection of screen-casts covering many aspects of MPS use and language design. You may check them out all nicely sorted at the MPS screen-cast page or directly at the MPS channel of JetBrains TV(英語)。
The MPS team offers hands-on trainings. Check out the details:
The MPS documentation page(英語) will give you all the remaining pointers to case studies, tutorials, FAQs and other pieces of MPS documentation.
Other sample projects
MPS comes with several sample projects that you may play with to get a better grasp of language development. I recommend you tried them out, perhaps in the order as they are listed below. Find out what they do and how they are implemented. They may teach you important lessons. Don't worry if you sometimes cannot figure out how a particular feature has been implemented. Most likely you will find an answer in one of the following exercises and then you can revisit the sample and the thing will just click instantly.
Here's a list of the samples that we've prepared for you:
SampleJavaExtensions - a collection of small handy Java enhancements, such as parallel for loop , unless statement, Money literal , decision tables and 定数 definition. The sample will teach you how to extend existing general purpose languages with custom constructs. You may also like to watch a short screen-cast introducing the individual extensions(英語)。
複合 - defines a Java extension to work with complex numbers
XML リテラル - allows XML literals to be used directly in Java code as first-class language elements. The language builds on top of .xml and generates into into org.jdom.* API. The user-inserted XML code may refer back to the surrounding Java context to easily parametrize.
math - provides fancy-looking math language extension to Java, which allows you to enter complex numbers, matrixes, intervals, summation, product and other common mathematical operations in a natural way.
LanguagePatterns - a set of sample languages illustrating implementations of common language patterns in MPS. It is useful for beginners to see in isolation concrete implementations of typical language constructs. This sample project is gradually being updated with new patterns.
MultipleProjections - an example of a simple state machine language that focuses on the mechanism of multiple projections per concept. The programmer, who uses the language, can on-the-fly switch between several pre-defined notations as she progressed with her state-machine definition. All the available notations are defined in the language or its extensions.
MultiTarget - illustrates how to have a single language generated into multiple different target languages.
Custom Aspects - shows the ways to define custom aspects for language definition. Check out the Custom language aspect cookbook for details.
Cross Model Generation - illustrates how to use custom generator plans to achieve cross-model generation.
- Component Dependencies - a minimalistic example of a language for expressing dependencies between components of a system, which provides three alternative editor notations:
Customized Debugger - an example of hooking a languages with the Java debugger, even when the language neither extends nor generates into BaseLanguage .
マインド・マップ - an intuitive example of defining a diagramming notation, including a set of customized graphical symbols
State machine (Secret Compartment language/ DSL book sample) - an example of a state machine language, including a state machine test language. An overview screen-cast is available(英語) to help you get started.
The Simplest Language - a minimalistic example generating a Hello world application printing out a customized message. Shows the very basics of language generation.
マイグレーション - a simple example of migration scripts to migrate two interconnected languages using both the smodel API and TransformStatement .
Lambda Calculus - a language simulating lambda calculus, with projectional editor and generation into Java
Agreement - an example of a business-oriented DSL
式 - a simplified expression language to allow you to play with the type system and the 型システムトレース tool. The language gives you a bare-bone expressions language with minimal editor support, but with well structured type-system rules, which you can help you learn the core of how MPS calculates types. Read more in the 型システムのデバッグ documentation.
Fixed Length Reader - illustrates how to create a language for describing binary data formats. Comes with a stub for a hypothetical runtime library that would extract elements from binary data using the supplied data format description (called configuration).
HighLevel Languages - an example of defining a custom set of language definition languages. Illustrates how to define your own way to codify structure and editor for a language.
Sample Language - A very intuitive and minimalistic example showing how to implement a common pattern of a root concept containing definitions as well as references to them. In this sample, we simulate Java classes, method definitions and method calls. However, such a pattern is quite frequent in many languages and it is worthwhile to spend some time investigating. You may also check out a brief screen-cast showing you round this sample.
Formula Language - a sample definition of an expression language, including editor actions and a generator
ノート Organizer - a sample DSL plugin for IntelliJ IDEA including a build script, that simulates a task/todo list. Tasks can have different priorities, states and categories, which by themselves can also be customized. The task lists can be filtered using several kinds of Swing UI components and the user can choose among several alternative visualizations of the task lists. Shows as an example of filtering node collections, alternative editors and direct incorporation of Swing components into form-like notations.
State Chart - an example of a state-chart definition language that generates state charts in the SCXML(英語) standard.
Requirement Tracking (new) - an example of a universal, language-agnostic requirement tracking language. Goals of a software project can be captured in specification documents written using the provided requirement tracking language. Mentions of relevant requirements can be inserted into code at places that implement these requirements. The mentions can be used in code that uses any MPS language. The sample features Node Attributes, non-trivial scoping and multiple switchable editors for a single concept.
属性 - a sample illustrating the transparent handling of attributes in text-gen and the generator. The two CommentAttribute node attribute concepts are passed through the generator unchanged so that their text-gen can convert them to text.
Sample Facet - illustrates a simple make facet that intercepts the make process.
軽量DSL - examples of usages of the jetbrains.mps.baselanguage.lightweightDSL language to build internal "lightweight" DSLs embedded into BaseLanguage classes.
Heating controller - a simple language providing two notations to specify heating plans for a hypothetical home heating controller. The default notation allows for textual representation, while a language extension provides an alternative tabular notation.
Progress Indicator - a set of actions that illustrate the proper way to handle progress bars in actions, how to make actions cancellable and enable them to run in the background.
xmlPersistence - a non-trivial example of implementing custom persistence using the new Open API.The plugin contains three solutions (a build script, a persistence implementation and a plugin descriptor). The custom persistence implementation will load/save XML documents. Please check out our カスタム持続クックブック for details.
Samples to tutorials:
図形 - the language created as part of the introductory Shapes Tutorial。
ロボットカヤ - the language for commanding a virtual robot used in many of the introductory screencasts. Now includes a sample コンテキストアシスタント implementation.
電卓 - the language created as part of the 計算機のチュートリアル(英語)。
Generator demo - the set of languages developed as part of the Generator Tutorial。
図形 - MPS入門チュートリアル