Welcome! This page 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.
So, take on good shoes, lace them tight and start going ...
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 (You may ignore the IntelliJ IDEA MPS plugin for now).
With MPS installed you will be able to continue on the Fast Track.
Raw time estimate - 30 minutes
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 Robot Kaja 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 Scripts 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.
We also shot an instructional screen-cast to help you start. Check it out.
Raw time estimate - 10 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
We summarized the core essential tips on how to leverage the projectional editor. Please, check out the Commanding the editor page and keep it ready when making your first steps in MPS.
Raw time estimate - 40 minutes
Now you must be curious about how the robot sample language has been created. Please, open again the Robot Kaja 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.
The next screen-cast to watch, MPS basics - creating your first language, 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 Constants language, which is also included as a sample project with MPS distributions.
Raw time estimate - 20 minutes
Now that you understand the internal workings of MPS you may like to slow down a bit and read a few documents describing how people use MPS. We've collected a few case studies that may inspire you to your own ideas on building something great around MPS.
You may find a complete list of user stories in the Use cases section of the MPS documentation.
Raw time estimate - 3 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.
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. 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 Constants 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.
- Complex - defines a Java extension to work with complex numbers
- XML Literals - allows XML literals to be used directly in Java code as first-class language elements. The language builds on top of jetbrains.mp.xml and generates into into org.jdom.* API. The user-inserted XML code may refer back to the surrounding Java context to easily parametrize.
- 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.
- Lambda Calculus - a language simulating lambda calculus, with projectional editor and generation into Java
- Agreement - an example of a business-oriented DSL
- 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).
- 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
- Plain Text - a very bare bone example modeling and generating plain text files using custom persistence to save and load models to/from disk.
- Calculator - the language created as part of the Calculator Tutorial.
Raw time estimate - 30 minutes
Once built, MPS languages can be deployed into IntelliJ IDEA and used side-by-side with traditional Java code. We prepared a guide dedicated to Java programmers willing to use an existing MPS language inside IntelliJ IDEA. Essentially, you install the IntelliJ IDEA MPS plugin to enable MPS in IDEA. Then you can install languages as further IDEA plugins, either from the IntelliJ IDEA repository or directly from a zip file.
Here's a list of documentation sources that you may need on your path to MPS mastery
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.
- Editor cookbook
- Generator cookbook
- Commenting out - a cookbookd showing how to leverage attributes, scopes and error suppression to add support for commenting out code in your languages
- Documentation comments - a cookbookd showing how to leverage attributes to add support for documentional comments in your languages
- Cookbook - Type System
- SModel language reference documentation to show you how to query your models
- Regular expressions
- Finding your way out - a brief collection of guidelines that should help you move forward when you get stuck somewhere.
Full-blown user guides will provide exhaustive information on their respective subject.
- Java developer's User Guide (IntelliJ IDEA)
- DSL developer's User Guide (standalone MPS-based IDEs)
- 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 documentation page will give you all the remaining pointers to case studies, tutorials, FAQs and other pieces of MPS documentation.
To set common terminology and avoid confusion, we wrote down the most frequent terms for you:
|Abstract Syntax Tree (AST)||a logical representation of code in memory (and disk) in the shape of a tree forest that describes hierarchies of nodes. These nodes have a notion of a parent-child relationship. Additionally, two nodes can be mutually connected with explicit references that go across the hierarchy structure.|
|BaseLanguage||a projectional clone of Java 6. I follows the Java specification and is 1:1 compatible with Java 6. Additionally, MPS provides several handy extensiont to BaseLanguagem such dates, collections, closures and many others.|
|Code generation||the process of transfromation code from one model (AST) into another model. For example, code describing a set of business rules can be transformed into plain Java so that it can be compiled with javac and run as part of an enterprise application.|
|DevKit||A package of related languages that have been grouped for user convenience.|
|Domain Specific Language (DSL)||a language dedicated to a particular problem domain, typically created with the aim of simplicity and greater expressivity compared to a general purpose language.|
|Language plugin||a packaged library ( a zip file) containing all the required elements in order to use a language either inside either IntelliJ IDEA or MPS.|
|Projectional editor||an editor that allows the user to edit the AST representation of code directly, while mimicing the behavior of a text editor to some extent. The user sees text on teh screen and edits it, however, in reality the text is only an illusion (projection) of an AST.|
|Module||The top-level organization element of an MPS project that typically groups several models together. It can have three basic types: Solution, Language and DevKit and may depend on other modules and models.|
|Model||A lower-level organizational element grouping individual concepts. It may depend on other models.|
|Structure||A language aspect defining all types (concepts) of AST nodes that can be used in the language together with their relationships.|
|Concept||A definition that describes the abstract structure of a syntax element. E.g. the IfStatement concepts says that an if holds a boolean Expression and up-to two StatementLists.|
|Constraints||A language aspect holding additional restrictions on concepts, their properties and relationships.|
|Behavior||Allows the language designer to define behavior of the language concepts.|
|Editor||Holds vizualization definitions of individual language concepts. Since the way concepts are viewed and edited on the screen can be customized, the editors specify how the user will interact with the language.|
|Scope||The set of elements that are visible and applicable to a particular position within a program. Typically only a sub-set of all elements of a particular kind can be used at any given program location.|
|Typesystem||A set of rules that validate and infer types of concepts in a program.|
|Actions|| User-invoked commands that may perform changes to the code. Actions can be attached to keyboard shortcuts or menu items.
|Intention actions||Context-sensitive actions offered to the language user through a small pop-up window triggered by the Alt + Enter key shortcut. These actions typically perform a relatively local refactoring to the code under carret or a selected block of code.|
|Surround With intention actions||Intentions applicable to a selected block of code that wrap the block by another concept. E.g. Surround with Try-Catch.|
|Refactoring||A potentially substantial automated change in code structure triggered by a user action.|