Skip to content

MontiCore - Expression-Language Modules

MC Expressions can be used to formulate mathematical and programmatic expressions from a set of literals. MC Expressions are based on a system of modular and pluggable grammar parts.

Given Expression languages in MontiCore

Currently, MontiCore comprises the following expression languages:

  • ExpressionsBasis: Basis for all other expression languages. Supports names and literals.
  • AssignmentExpressions: Extends ExpressionsBasis with basic assignments.
  • CommonExpressions: Extends ExpressionsBasis with common expressions like + and -.
  • BitExpressions: Extends ExpressionsBasis with bit expressions like & or <<.
  • SetExpressions: Extends ExpressionBasis with set expressions like {a * a | a in b, a < 10}.
  • LambdaExpressions: Extends ExpressionBasis with lambda expressions like a -> a + 2.
  • TupleExpressions: Extends ExpressionBasis with tuple expressions like (a, b).
  • OCLExpressions: Extends ExpressionsBasis with OCL expressions like a implies b.
  • UglyExpressions: Extends ExpressionBasis with expressions like instanceof and (Person)a.
  • OptionalOperators: Extends CommonExpressions with expressions for optionals like a ?: 0
  • JavaClassExpressions: Extends CommonExpressions with Java expressions like new.
  • StreamExpressions: Extends CommonExpressions with stream expressions like a : b.

Furthermore, composite SI unit expressions are defined in the SI Units project:

  • SI Units (can be used to parse primitive units as well as their products, quotients, and powers)

Using Expressions

To use one or more of the existing expression languages in your MontiCore-based language its grammar needs to extend those expression languages.

Creating your own Expression language

There are some expressions you need desperately and that are not covered by the existing expression languages?
In this case, you can create a new grammar that extends at least ExpressionsBasis. In the extending grammar, you are now free to add your own expressions which however must implement the Expression interface from ExpressionsBasis grammar. To then include the new expressions in a language let it extend the corresponding grammar. See here for an example.

Further Information