diff options
Diffstat (limited to 'subprojects/language/src/main/java/tools/refinery/language/Problem.xtext')
-rw-r--r-- | subprojects/language/src/main/java/tools/refinery/language/Problem.xtext | 88 |
1 files changed, 45 insertions, 43 deletions
diff --git a/subprojects/language/src/main/java/tools/refinery/language/Problem.xtext b/subprojects/language/src/main/java/tools/refinery/language/Problem.xtext index f0d6c38c..08f7a585 100644 --- a/subprojects/language/src/main/java/tools/refinery/language/Problem.xtext +++ b/subprojects/language/src/main/java/tools/refinery/language/Problem.xtext | |||
@@ -17,7 +17,8 @@ enum ModuleKind: | |||
17 | 17 | ||
18 | Statement: | 18 | Statement: |
19 | ImportStatement | Assertion | ClassDeclaration | EnumDeclaration | | 19 | ImportStatement | Assertion | ClassDeclaration | EnumDeclaration | |
20 | PredicateDefinition | /* FunctionDefinition | RuleDefinition | */ | 20 | DatatypeDeclaration | AggregatorDeclaration | PredicateDefinition | |
21 | /* FunctionDefinition | RuleDefinition | */ | ||
21 | ScopeDeclaration | NodeDeclaration; | 22 | ScopeDeclaration | NodeDeclaration; |
22 | 23 | ||
23 | ImportStatement: | 24 | ImportStatement: |
@@ -27,7 +28,7 @@ ClassDeclaration: | |||
27 | abstract?="abstract"? "class" | 28 | abstract?="abstract"? "class" |
28 | name=Identifier | 29 | name=Identifier |
29 | ("extends" superTypes+=[Relation|QualifiedName] ("," superTypes+=[Relation|QualifiedName])*)? | 30 | ("extends" superTypes+=[Relation|QualifiedName] ("," superTypes+=[Relation|QualifiedName])*)? |
30 | ("{" (featureDeclarations+=FeatureDeclaration ";"?)* "}" | "."); | 31 | ("{" (featureDeclarations+=ReferenceDeclaration ";"?)* "}" | "."); |
31 | 32 | ||
32 | EnumDeclaration: | 33 | EnumDeclaration: |
33 | "enum" | 34 | "enum" |
@@ -37,8 +38,11 @@ EnumDeclaration: | |||
37 | EnumLiteral returns Node: | 38 | EnumLiteral returns Node: |
38 | name=Identifier; | 39 | name=Identifier; |
39 | 40 | ||
40 | FeatureDeclaration: | 41 | DatatypeDeclaration: |
41 | ReferenceDeclaration /* | AttributeDeclaration | FlagDeclaration */; | 42 | "extern" "datatype" name=Identifier "."; |
43 | |||
44 | AggregatorDeclaration: | ||
45 | "extern" "aggregator" name=Identifier "."; | ||
42 | 46 | ||
43 | enum ReferenceKind: | 47 | enum ReferenceKind: |
44 | REFERENCE="refers" | CONTAINMENT="contains" | CONTAINER="container"; | 48 | REFERENCE="refers" | CONTAINMENT="contains" | CONTAINER="container"; |
@@ -53,15 +57,6 @@ ReferenceDeclaration: | |||
53 | ReferenceMultiplicity returns Multiplicity: | 57 | ReferenceMultiplicity returns Multiplicity: |
54 | "[" Multiplicity "]"; | 58 | "[" Multiplicity "]"; |
55 | 59 | ||
56 | //enum PrimitiveType: | ||
57 | // INT="int" | REAL="real" | STRING="string"; | ||
58 | // | ||
59 | //AttributeDeclaration: | ||
60 | // attributeType=PrimitiveType name=Identifier; | ||
61 | // | ||
62 | //FlagDeclaration: | ||
63 | // "bool" name=Identifier; | ||
64 | |||
65 | PredicateDefinition: | 60 | PredicateDefinition: |
66 | ("pred" | error?="error" "pred"?) | 61 | ("pred" | error?="error" "pred"?) |
67 | name=Identifier | 62 | name=Identifier |
@@ -73,14 +68,13 @@ Conjunction: | |||
73 | literals+=Expr ("," literals+=Expr)*; | 68 | literals+=Expr ("," literals+=Expr)*; |
74 | 69 | ||
75 | //FunctionDefinition: | 70 | //FunctionDefinition: |
76 | // "fn" functionType=PrimitiveType name=Identifier | 71 | // "fn" functionType=[DatatypeDefinition|QualifiedName] name=Identifier |
77 | // "(" (parameters+=Parameter ("," parameters+=Parameter)*)? ")" | 72 | // "(" (parameters+=Parameter ("," parameters+=Parameter)*)? ")" |
78 | // ("=" cases+=Case (";" cases+=Case)*)? | 73 | // ("=" cases+=Case (";" cases+=Case)*)? |
79 | // "."; | 74 | // "."; |
80 | // | 75 | // |
81 | //Case: | 76 | //Case: |
82 | // Conjunction ({Match.condition=current} "->" value=Expr)?; | 77 | // Conjunction ({Match.condition=current} "->" value=Expr)?; |
83 | |||
84 | //RuleDefinition: | 78 | //RuleDefinition: |
85 | // "rule" | 79 | // "rule" |
86 | // name=Identifier | 80 | // name=Identifier |
@@ -112,25 +106,32 @@ Parameter: | |||
112 | // name=Identifier; | 106 | // name=Identifier; |
113 | 107 | ||
114 | Expr: | 108 | Expr: |
115 | ComparisonExpr; | 109 | AssignmentExpr; |
110 | |||
111 | AssignmentExpr returns Expr: | ||
112 | BooleanExpr ({AssignmentExpr.left=current} "is" right=BooleanExpr)*; | ||
113 | |||
114 | enum BooleanBinaryOp returns BinaryOp: | ||
115 | AND="&&" | OR="||" | XOR="^^"; | ||
116 | |||
117 | BooleanExpr returns Expr: | ||
118 | ComparisonExpr ({ArithmeticBinaryExpr.left=current} | ||
119 | op=BooleanBinaryOp right=ComparisonExpr)*; | ||
116 | 120 | ||
117 | enum ComparisonOp: | 121 | enum ComparisonOp: |
118 | LESS="<" | LESS_EQ="<=" | GREATER=">" | GREATER_EQ=">=" | EQ="==" | NOT_EQ="!=" | | 122 | LESS="<" | LESS_EQ="<=" | GREATER=">" | GREATER_EQ=">=" | EQ="===" | NOT_EQ="!==" | |
119 | IN="in" | SUBSUMES=":>" | SUBSUMED_BY="<:" | ABS_EQ="===" | ABS_NOT_EQ="!=="; | 123 | IN="in" | NODE_EQ="==" | NODE_NOT_EQ="!="; |
120 | 124 | ||
121 | ComparisonExpr returns Expr: | 125 | ComparisonExpr returns Expr: |
122 | LatticeExpr ({ComparisonExpr.left=current} | 126 | LatticeExpr ({ComparisonExpr.left=current} |
123 | op=ComparisonOp right=LatticeExpr)*; | 127 | op=ComparisonOp right=LatticeExpr)*; |
124 | 128 | ||
125 | enum LatticeOp returns BinaryOp: | 129 | enum LatticeBinaryOp: |
126 | MEET="/\\" | JOIN="\\/"; | 130 | MEET="/\\" | JOIN="\\/"; |
127 | 131 | ||
128 | LatticeExpr returns Expr: | 132 | LatticeExpr returns Expr: |
129 | RangeExpr ({ArithmeticBinaryExpr.left=current} | 133 | AdditiveExpr ({LatticeBinaryExpr.left=current} |
130 | op=LatticeOp right=RangeExpr)*; | 134 | op=LatticeBinaryOp right=AdditiveExpr)*; |
131 | |||
132 | RangeExpr returns Expr: | ||
133 | AdditiveExpr ({RangeExpr.left=current} ".." right=AdditiveExpr)*; | ||
134 | 135 | ||
135 | enum AdditiveOp returns BinaryOp: | 136 | enum AdditiveOp returns BinaryOp: |
136 | ADD="+" | SUB="-"; | 137 | ADD="+" | SUB="-"; |
@@ -150,12 +151,15 @@ enum ExponentialOp returns BinaryOp: | |||
150 | POW="**"; | 151 | POW="**"; |
151 | 152 | ||
152 | ExponentialExpr returns Expr: | 153 | ExponentialExpr returns Expr: |
153 | UnaryExpr ({ArithmeticBinaryExpr.left=current} | 154 | RangeExpr ({ArithmeticBinaryExpr.left=current} |
154 | op=ExponentialOp right=ExponentialExpr)?; | 155 | op=ExponentialOp right=ExponentialExpr)?; |
155 | 156 | ||
157 | RangeExpr returns Expr: | ||
158 | UnaryExpr ({RangeExpr.left=current} ".." right=UnaryExpr)*; | ||
159 | |||
156 | UnaryExpr returns Expr: | 160 | UnaryExpr returns Expr: |
157 | ArithmeticUnaryExpr | ModalExpr | NegationExpr | CountExpr | AggregationExpr | | 161 | ArithmeticUnaryExpr | NegationExpr | |
158 | Atom | VariableOrNodeExpr | Constant | "(" Expr ")"; | 162 | CountExpr | AggregationExpr | CastExpr; |
159 | 163 | ||
160 | enum UnaryOp: | 164 | enum UnaryOp: |
161 | PLUS="+" | MINUS="-"; | 165 | PLUS="+" | MINUS="-"; |
@@ -163,23 +167,21 @@ enum UnaryOp: | |||
163 | ArithmeticUnaryExpr: | 167 | ArithmeticUnaryExpr: |
164 | op=UnaryOp body=UnaryExpr; | 168 | op=UnaryOp body=UnaryExpr; |
165 | 169 | ||
166 | enum Modality: | ||
167 | MAY="may" | MUST="must" | CURRENT="current"; | ||
168 | |||
169 | ModalExpr: | ||
170 | modality=Modality body=UnaryExpr; | ||
171 | |||
172 | NegationExpr: | 170 | NegationExpr: |
173 | "!" body=UnaryExpr; | 171 | "!" body=UnaryExpr; |
174 | 172 | ||
175 | CountExpr: | 173 | CountExpr: |
176 | "count" body=UnaryExpr; | 174 | "count" body=UnaryExpr; |
177 | 175 | ||
178 | enum AggregationOp: | ||
179 | SUM="sum" | PROD="prod" | MIN="min" | MAX="max"; | ||
180 | |||
181 | AggregationExpr: | 176 | AggregationExpr: |
182 | op=AggregationOp "{" value=Expr "|" condition=Expr "}"; | 177 | aggregator=[AggregatorDeclaration|QualifiedName] |
178 | "{" value=Expr "|" condition=ComparisonExpr "}"; | ||
179 | |||
180 | CastExpr returns Expr: | ||
181 | CastExprBody ({CastExpr.body=current} "as" targetType=[Relation|QualifiedName])?; | ||
182 | |||
183 | CastExprBody returns Expr: | ||
184 | Atom | VariableOrNodeExpr | Constant | "(" Expr ")"; | ||
183 | 185 | ||
184 | Atom: | 186 | Atom: |
185 | relation=[Relation|QualifiedName] | 187 | relation=[Relation|QualifiedName] |
@@ -190,7 +192,7 @@ VariableOrNodeExpr: | |||
190 | variableOrNode=[VariableOrNode|QualifiedName]; | 192 | variableOrNode=[VariableOrNode|QualifiedName]; |
191 | 193 | ||
192 | Constant: | 194 | Constant: |
193 | RealConstant | IntConstant | InfConstant | StringConstant | LogicConstant; | 195 | RealConstant | IntConstant | StringConstant | InfiniteConstant | LogicConstant; |
194 | 196 | ||
195 | IntConstant: | 197 | IntConstant: |
196 | intValue=INT; | 198 | intValue=INT; |
@@ -198,12 +200,12 @@ IntConstant: | |||
198 | RealConstant: | 200 | RealConstant: |
199 | realValue=Real; | 201 | realValue=Real; |
200 | 202 | ||
201 | InfConstant: | ||
202 | {InfConstant} "*"; | ||
203 | |||
204 | StringConstant: | 203 | StringConstant: |
205 | stringValue=STRING; | 204 | stringValue=STRING; |
206 | 205 | ||
206 | InfiniteConstant: | ||
207 | {InfiniteConstant} "*"; | ||
208 | |||
207 | enum LogicValue: | 209 | enum LogicValue: |
208 | TRUE="true" | FALSE="false" | UNKNOWN="unknown" | ERROR="error"; | 210 | TRUE="true" | FALSE="false" | UNKNOWN="unknown" | ERROR="error"; |
209 | 211 | ||
@@ -278,8 +280,8 @@ Identifier: | |||
278 | NonContainmentIdentifier | "contains" | "container"; | 280 | NonContainmentIdentifier | "contains" | "container"; |
279 | 281 | ||
280 | NonContainmentIdentifier: | 282 | NonContainmentIdentifier: |
281 | ID | "atom" | "multi" | "contained" | | 283 | ID | "atom" | "multi" | "contained" | "problem" | "module" | |
282 | "sum" | "prod" | "min" | "max" | "problem" | "module"; | 284 | "datatype" | "aggregator"; |
283 | 285 | ||
284 | Real returns ecore::EDouble: | 286 | Real returns ecore::EDouble: |
285 | EXPONENTIAL | INT "." (INT | EXPONENTIAL); | 287 | EXPONENTIAL | INT "." (INT | EXPONENTIAL); |