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+and-. - BitExpressions : Extends
ExpressionsBasiswith bit expressions like&or<<. - SetExpressions : Extends
ExpressionBasiswith set expressions like{a * a | a in b, a < 10}. - StreamExpressions :
Extends
CommonExpressionswith stream expressions like1:Abs:<2,~,3>. - LambdaExpressions : Extends
ExpressionBasiswith lambda expressions likea -> a + 2. - TupleExpressions : Extends
ExpressionBasiswith tuple expressions like(a, b)or(a, b, c, d). - OCLExpressions : Extends
ExpressionsBasiswith OCL expressions likea implies b. - UglyExpressions : Extends
ExpressionBasiswith expressions likeinstanceofand(Person)a. - OptionalOperators : Extends
CommonExpressionswith expressions for optionals likea ?: 0 - JavaClassExpressions : Extends
CommonExpressionswith Java expressions likenew. - StreamExpressions : Extends
CommonExpressionswith stream expressions likea : 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.