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
ExpressionsBasiswith basic assignments.
- CommonExpressions: Extends
ExpressionsBasiswith common expressions like
- BitExpressions: Extends
ExpressionsBasiswith bit expressions like
- LambdaExpressions: Extends
ExpressionBasiswith lambda expressions like
a -> a + 2.
- JavaClassExpressions: Extends
CommonExpressionswith Java expressions like
The OCL project defines additional expression languages:
- OCL-OCLExpressions: Extends
ExpressionsBasisto introduce OCL to MontiCore.
- OCL-SetExpressions: Extends
ExpressionsBasisfor working with sets using OCL.
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)
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.
for an example.