1 | grammar org.modelica.xtext.ModelicaAST hidden(WS, ML_COMMENT, SL_COMMENT) |
---|
2 | |
---|
3 | import "http://www.eclipse.org/emf/2002/Ecore" as ecore |
---|
4 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Program" as Program |
---|
5 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Within" as Within |
---|
6 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Class" as Class |
---|
7 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//ClassDef" as ClassDef |
---|
8 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//EnumDef" as EnumDef |
---|
9 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//EnumLiteral" as EnumLiteral |
---|
10 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//ClassPart" as ClassPart |
---|
11 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//ElementItem" as ElementItem |
---|
12 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Element" as Element |
---|
13 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//ConstrainClass" as ConstrainClass |
---|
14 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//ElementSpec" as ElementSpec |
---|
15 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//InnerOuter" as InnerOuter |
---|
16 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Import" as Import |
---|
17 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//ComponentItem" as ComponentItem |
---|
18 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//ComponentCondition" as ComponentCondition |
---|
19 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Component" as Component |
---|
20 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//EquationItem" as EquationItem |
---|
21 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//AlgorithmItem" as AlgorithmItem |
---|
22 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Equation" as Equation |
---|
23 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//AlgorithmStatement" as AlgorithmStatement |
---|
24 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Modifications" as Modifications |
---|
25 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//ElementArg" as ElementArg |
---|
26 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//RedeclareKeywords" as RedeclareKeywords |
---|
27 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Each" as Each |
---|
28 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//ElementAttributes" as ElementAttributes |
---|
29 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Variability" as Variability |
---|
30 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Direction" as Direction |
---|
31 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//ArrayDim" as ArrayDim |
---|
32 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Exp" as Exp |
---|
33 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//FunctionArgs" as FunctionArgs |
---|
34 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//NamedArg" as NamedArg |
---|
35 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Operator" as Operator |
---|
36 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Subscript" as Subscript |
---|
37 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//ComponentRef" as ComponentRef |
---|
38 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Path" as Path |
---|
39 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Restriction" as Restriction |
---|
40 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Annotation" as Annotation |
---|
41 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Comment" as Comment |
---|
42 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//ExternalDecl" as ExternalDecl |
---|
43 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//TimeStamp" as TimeStamp |
---|
44 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Iterators" as Iterators |
---|
45 | import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//TypeSpec" as TypeSpec |
---|
46 | |
---|
47 | /* |
---|
48 | * Copyright (c) 2009 - currentYear, |
---|
49 | Adrian Pop [adrpo@ida.liu.se], |
---|
50 | Atanas Pavlov [nasko.js@gmail.com] |
---|
51 | * All rights reserved. |
---|
52 | */ |
---|
53 | |
---|
54 | |
---|
55 | |
---|
56 | |
---|
57 | /*------------------------------------------------------------------ |
---|
58 | * PARSER RULES |
---|
59 | *------------------------------------------------------------------*/ |
---|
60 | |
---|
61 | StorageUnit returns Program::PROGRAM : |
---|
62 | withinClause=WithinClause |
---|
63 | (classes+=Class ';')* |
---|
64 | ; |
---|
65 | |
---|
66 | WithinClause returns Within::uWithin : |
---|
67 | {Within::WITHIN} 'within' (path=Path)? ';' |
---|
68 | | {Within::TOP} |
---|
69 | ; |
---|
70 | |
---|
71 | Class returns Class::uClass : |
---|
72 | {Class::CLASS} |
---|
73 | finalPrefix?=('final')? encapsulatedPrefix?=('encapsulated')? partialPrefix?=('partial')? |
---|
74 | restriction=Restriction (name=IDENT body=ClassDefinition | 'extends' body=ClassDefinitionExtends) |
---|
75 | ; |
---|
76 | |
---|
77 | InnerClass returns Class::uClass : |
---|
78 | {Class::CLASS} |
---|
79 | encapsulatedPrefix?=('encapsulated')? partialPrefix?=('partial')? |
---|
80 | restriction=Restriction (name=IDENT body=ClassDefinition | 'extends' body=ClassDefinitionExtends) |
---|
81 | ; |
---|
82 | |
---|
83 | ClassDefinition returns ClassDef::uClassDef : |
---|
84 | ClassDefinitionDerived |
---|
85 | | ClassDefinitionEnum |
---|
86 | | ClassDefinitionOverload |
---|
87 | | ClassDefinitionPartialDer |
---|
88 | | ClassDefinitionParts |
---|
89 | ; |
---|
90 | |
---|
91 | ClassDefinitionDerived returns ClassDef::DERIVED : |
---|
92 | '=' attributes=ElementAttributes typeSpec=TypeSpecification |
---|
93 | ('(' arguments+=ElementArg (',' arguments+=ElementArg)* ')')? comment=Comment |
---|
94 | ; |
---|
95 | |
---|
96 | ClassDefinitionEnum returns ClassDef::ENUMERATION : |
---|
97 | '=' 'enumeration' '(' enumLiterals=EnumerationDefinition ')' comment=Comment |
---|
98 | ; |
---|
99 | |
---|
100 | ClassDefinitionOverload returns ClassDef::OVERLOAD : |
---|
101 | '=' 'overload' '(' functionNames+=Path (',' functionNames+=Path)* ')' comment=Comment |
---|
102 | ; |
---|
103 | |
---|
104 | // CHECK Comment? |
---|
105 | ClassDefinitionPartialDer returns ClassDef::PDER : |
---|
106 | '=' 'der' '(' functionName=Path (',' vars+=IDENT)+ ')' |
---|
107 | ; |
---|
108 | // CHECK Comment or StringComment |
---|
109 | ClassDefinitionExtends returns ClassDef::CLASS_EXTENDS : |
---|
110 | baseClassName=IDENT ('(' |
---|
111 | modifications+=ElementArg ( ',' modifications+=ElementArg)* ')')? |
---|
112 | comment=StringComment? (parts+=ClassPartInitial)? |
---|
113 | (parts+=ClassPart)* (parts+=ClassPartExternal)? |
---|
114 | 'end' nameEnd=IDENT |
---|
115 | ; |
---|
116 | |
---|
117 | ClassDefinitionParts returns ClassDef::PARTS : |
---|
118 | comment=StringComment? (classParts+=ClassPartInitial)? |
---|
119 | (classParts+=ClassPart)* (classParts+=ClassPartExternal)? |
---|
120 | 'end' nameEnd=IDENT |
---|
121 | ; |
---|
122 | EnumerationDefinition returns EnumDef::uEnumDef : |
---|
123 | {EnumDef::ENUMLITERALS} enumLiterals+=EnumLiteral (',' enumLiterals+=EnumLiteral)* |
---|
124 | | {EnumDef::ENUM_COLON} ':' |
---|
125 | ; |
---|
126 | |
---|
127 | EnumLiteral returns EnumLiteral::uEnumLiteral : |
---|
128 | {EnumLiteral::ENUMLITERAL} literal=IDENT comment=Comment |
---|
129 | ; |
---|
130 | |
---|
131 | ClassPart returns ClassPart::uClassPart : |
---|
132 | {ClassPart::PUBLIC} 'public' (contents+=ElementItem)* |
---|
133 | |{ClassPart::PROTECTED} 'protected' (contents+=ElementItem)* |
---|
134 | |{ClassPart::EQUATIONS} 'equation' (contents+=EquationItem)* |
---|
135 | |{ClassPart::INITIALEQUATIONS} 'initial' 'equation' (contents+=EquationItem)* |
---|
136 | |{ClassPart::ALGORITHMS} 'algorithm' (contents+=AlgorithmItem)* |
---|
137 | |{ClassPart::INITIALALGORITHMS} 'initial' 'algorithm' (contents+=AlgorithmItem)* |
---|
138 | ; |
---|
139 | |
---|
140 | ClassPartInitial returns ClassPart::uClassPart : |
---|
141 | {ClassPart::PUBLIC} (contents+=ElementItem)+ |
---|
142 | ; |
---|
143 | |
---|
144 | ClassPartExternal returns ClassPart::uClassPart : |
---|
145 | {ClassPart::EXTERNAL} 'external' externalDecl=ExternalDeclaration ';' |
---|
146 | (annotationNode=Annotation ';')? |
---|
147 | ; |
---|
148 | |
---|
149 | ElementItem returns ElementItem::uElementItem : |
---|
150 | {ElementItem::ELEMENTITEM} element=Element ';' |
---|
151 | |{ElementItem::ANNOTATIONITEM} annotation_=Annotation ';' |
---|
152 | ; |
---|
153 | |
---|
154 | // FIXME Figure out the text thing |
---|
155 | // fix redeclareKeyword>s< ?=('redeclare')? |
---|
156 | //Element returns Element::uElement : |
---|
157 | // ElementElement |
---|
158 | //|{TEXT} |
---|
159 | //|{DEFINEUNIT} |
---|
160 | //; |
---|
161 | |
---|
162 | // FIXME constrainedby clause |
---|
163 | Element returns Element::ELEMENT: |
---|
164 | innerOuter=InnerOuter (specification=ElementSpecificationImport | specification=ElementSpecificationExtends) |
---|
165 | | redeclareKeywords=RedeclareKeyword? finalPrefix?='final'? |
---|
166 | innerOuter=InnerOuter (specification=ElementSpecificationClassDefinition | specification=ElementSpecificationComponents) |
---|
167 | | (redeclareKeywords=RedeclareReplaceableKeyword | redeclareKeywords=ReplaceableKeyword) innerOuter=InnerOuter |
---|
168 | (specification=ElementSpecificationClassDefinition | specification=ElementSpecificationComponents) |
---|
169 | ; |
---|
170 | |
---|
171 | //('constrainedby' name=IDENT constrainClass=ConstrainClass)? |
---|
172 | /* |
---|
173 | ConstrainClass returns uConstrainClass : |
---|
174 | {CONSTRAINCLASS} elementSpec=ElementSpecification comment=Comment |
---|
175 | ; |
---|
176 | */ |
---|
177 | |
---|
178 | |
---|
179 | ElementSpecification returns ElementSpec::uElementSpec : |
---|
180 | ElementSpecificationImport |
---|
181 | |ElementSpecificationExtends |
---|
182 | |ElementSpecificationClassDefinition |
---|
183 | |ElementSpecificationComponents |
---|
184 | ; |
---|
185 | |
---|
186 | ElementSpecificationImport returns ElementSpec::uElementSpec : |
---|
187 | {ElementSpec::IMPORT} 'import' import_=Import comment=Comment |
---|
188 | ; |
---|
189 | |
---|
190 | ElementSpecificationExtends returns ElementSpec::uElementSpec : |
---|
191 | {ElementSpec::EXTENDS} 'extends' path=Path ( '(' |
---|
192 | elementArg+=ElementArg (',' elementArg+=ElementArg)* ')' )? annotationOpt=Annotation? |
---|
193 | ; |
---|
194 | |
---|
195 | /* FIXME check the 'replaceable' */ |
---|
196 | ElementSpecificationClassDefinition returns ElementSpec::uElementSpec : |
---|
197 | {ElementSpec::CLASSDEF} /*replaceable_?=('replaceable')?*/ class_=InnerClass |
---|
198 | ; |
---|
199 | |
---|
200 | ElementSpecificationComponents returns ElementSpec::uElementSpec : |
---|
201 | {ElementSpec::COMPONENTS} attributes=ElementAttributes typeSpec=TypeSpecification |
---|
202 | components+=ComponentItem (',' components+=ComponentItem)* |
---|
203 | ; |
---|
204 | |
---|
205 | InnerOuter returns InnerOuter::uInnerOuter : |
---|
206 | {InnerOuter::INNEROUTER} 'inner' 'outer' |
---|
207 | |{InnerOuter::INNER} 'inner' |
---|
208 | |{InnerOuter::OUTER} 'outer' |
---|
209 | |{InnerOuter::UNSPECIFIED} |
---|
210 | ; |
---|
211 | |
---|
212 | //InnerOuterUnspecified returns InnerOuter::uInnerOuter : |
---|
213 | // ; |
---|
214 | |
---|
215 | // FIXME the unqualified import- perhaps in a M2M transformation |
---|
216 | Import returns Import::uImport : |
---|
217 | {Import::NAMED_IMPORT} name=IDENT '=' path=Path |
---|
218 | |{Import::QUAL_IMPORT} path=Path |
---|
219 | //|{UNQUAL_IMPORT} path=Path |
---|
220 | ; |
---|
221 | |
---|
222 | ComponentItem returns ComponentItem::uComponentItem : |
---|
223 | {ComponentItem::COMPONENTITEM} component=Component condition=ComponentCondition? comment=Comment |
---|
224 | ; |
---|
225 | |
---|
226 | ComponentCondition returns ComponentCondition::ComponentCondition : |
---|
227 | 'if' condition=Expression |
---|
228 | ; |
---|
229 | |
---|
230 | Component returns Component::uComponent : |
---|
231 | {Component::COMPONENT} name=IDENT arrayDim=ArrayDim? modification=Modification? |
---|
232 | ; |
---|
233 | |
---|
234 | EquationItem returns EquationItem::uEquationItem : |
---|
235 | {EquationItem::EQUATIONITEM} equation_=Equation comment=Comment ';' |
---|
236 | | {EquationItem::EQUATIONITEMANN} annotation_=Annotation ';' |
---|
237 | ; |
---|
238 | |
---|
239 | AlgorithmItem returns AlgorithmItem::uAlgorithmItem : |
---|
240 | {AlgorithmItem::ALGORITHMITEM} algorithm_=AlgorithmStatement comment=Comment ';' |
---|
241 | | {AlgorithmItem::ALGORITHMITEMANN} annotation_=Annotation ';' |
---|
242 | ; |
---|
243 | |
---|
244 | Equation returns Equation::uEquation : |
---|
245 | EquationIf | EquationEquals | EquationConnect | EquationFor | EquationWhenEq |
---|
246 | | EquationNoRetCall //FIXME what is this doing? |
---|
247 | //|EqFailure |
---|
248 | ; |
---|
249 | |
---|
250 | EquationIf returns Equation::EQ_IF : |
---|
251 | 'if' ifExp=Expression 'then' (equationTrueItems+=EquationItem)* |
---|
252 | (elseIfBranches+=ElseIfBranch)* |
---|
253 | ('else' (equationElseItems+=EquationItem)*)? |
---|
254 | 'end' 'if' |
---|
255 | ; |
---|
256 | |
---|
257 | ElseIfBranch returns Equation::tuple_ElseIfBranch : |
---|
258 | 'elseif' exp=Expression 'then' (equationItem+=EquationItem)* |
---|
259 | ; |
---|
260 | |
---|
261 | EquationEquals returns Equation::EQ_EQUALS : |
---|
262 | leftSide=ExprRange '=' rightSide=Expression |
---|
263 | ; |
---|
264 | EquationNoRetCall returns Equation::EQ_NORETCALL : |
---|
265 | functionName=ComponentRef '(' functionArgs=FunctionArguments? ')' |
---|
266 | ; |
---|
267 | |
---|
268 | EquationConnect returns Equation::EQ_CONNECT : |
---|
269 | 'connect' '(' connector1=ComponentRef ',' connector2=ComponentRef ')' |
---|
270 | ; |
---|
271 | |
---|
272 | EquationFor returns Equation::EQ_FOR : |
---|
273 | 'for' iterators=ForIterators 'loop' (forEquations+=EquationItem)* 'end' 'for' |
---|
274 | ; |
---|
275 | |
---|
276 | EquationWhenEq returns Equation::EQ_WHEN_E : |
---|
277 | 'when' whenExp=Expression 'then' (whenEquations+=EquationItem)* |
---|
278 | (elseWhenEquations+=ElseWhenEquationBranch)* |
---|
279 | 'end' 'when' |
---|
280 | ; |
---|
281 | |
---|
282 | ElseWhenEquationBranch returns Equation::tuple_ElseWhenEquation : |
---|
283 | 'elsewhen' exp=Expression 'then' (equationItem+=EquationItem)* |
---|
284 | ; |
---|
285 | |
---|
286 | AlgorithmStatement returns AlgorithmStatement::uAlgorithmStatement : |
---|
287 | AlgorithmIf | AlgorithmAssign | AlgorithmFor | AlgorithmWhen |
---|
288 | |AlgorithmNoRetCall |
---|
289 | | AlgorithmReturn | AlgorithmWhile | AlgorithmBreak |
---|
290 | ; |
---|
291 | |
---|
292 | AlgorithmIf returns AlgorithmStatement::ALG_IF: |
---|
293 | 'if' ifExp=Expression 'then' (trueBranch+=AlgorithmItem)* |
---|
294 | (elseIfAlgorithmBranch+=ElseIfAlgorithmBranch)* |
---|
295 | ('else' (elseBranch+=AlgorithmItem)*)? |
---|
296 | 'end' 'if' |
---|
297 | ; |
---|
298 | |
---|
299 | ElseIfAlgorithmBranch returns AlgorithmStatement::tuple_ElseIfAlgorithmBranch : |
---|
300 | 'elseif' exp=Expression 'then' (algorithmItem+=AlgorithmItem)* |
---|
301 | ; |
---|
302 | |
---|
303 | AlgorithmAssign returns AlgorithmStatement::ALG_ASSIGN: |
---|
304 | assignComponent=ExprRange ':=' value=Expression |
---|
305 | ; |
---|
306 | AlgorithmNoRetCall returns AlgorithmStatement::ALG_NORETCALL : |
---|
307 | functionCall=ComponentRef '(' functionArgs=FunctionArguments? ')' |
---|
308 | ; |
---|
309 | |
---|
310 | AlgorithmFor returns AlgorithmStatement::ALG_FOR : |
---|
311 | 'for' iterators=ForIterators 'loop' (forBody+=AlgorithmItem)* 'end' 'for' |
---|
312 | ; |
---|
313 | |
---|
314 | AlgorithmWhen returns AlgorithmStatement::ALG_WHEN_A : |
---|
315 | 'when' boolExpr=Expression 'then' (whenBody+=AlgorithmItem) |
---|
316 | (elseWhenAlgorithmBranch+=ElseWhenAlgorithmBranch)* |
---|
317 | 'end' 'when' |
---|
318 | ; |
---|
319 | |
---|
320 | ElseWhenAlgorithmBranch returns AlgorithmStatement::tuple_ElseWhenAlgorithmBranch : |
---|
321 | 'elsewhen' exp=Expression 'then' (algorithmItem+=AlgorithmItem)* |
---|
322 | ; |
---|
323 | |
---|
324 | AlgorithmReturn returns AlgorithmStatement::ALG_RETURN : |
---|
325 | {AlgorithmStatement::ALG_RETURN} 'return' |
---|
326 | ; |
---|
327 | |
---|
328 | AlgorithmWhile returns AlgorithmStatement::ALG_WHILE : |
---|
329 | {AlgorithmStatement::ALG_WHILE} 'while' boolExpr=Expression 'loop' (whileBody+=AlgorithmItem)* 'end' 'while' |
---|
330 | ; |
---|
331 | |
---|
332 | AlgorithmBreak returns AlgorithmStatement::ALG_BREAK : |
---|
333 | {AlgorithmStatement::ALG_BREAK} 'break' |
---|
334 | ; |
---|
335 | |
---|
336 | Modification returns Modifications::uModification : |
---|
337 | {Modifications::CLASSMOD} ( |
---|
338 | '(' elementArgList+=ElementArg (',' elementArgList+=ElementArg)* ')' ('=' expOption=Expression)? |
---|
339 | | ('='|':=') expOption=Expression) |
---|
340 | ; |
---|
341 | |
---|
342 | // TODO componentRef? constrain part |
---|
343 | ElementArg returns ElementArg::uElementArg : |
---|
344 | {ElementArg::MODIFICATION} each_=Each finalItem?=('final')? |
---|
345 | componentReg=ComponentRef modification=Modification? |
---|
346 | comment=StringComment? |
---|
347 | |{ElementArg::REDECLARATION} each_=Each finalItem?=('final')? |
---|
348 | redeclareKeywords=( ReplaceableKeyword | RedeclareReplaceableKeyword ) |
---|
349 | elementSpec=( ElementSpecificationClassDefinition | ElementSpecificationComponents1 ) |
---|
350 | /* constrainClass=ConstrainClass? */ |
---|
351 | |{ElementArg::REDECLARATION} each_=Each finalItem?=('final') redeclareKeywords=RedeclareKeyword |
---|
352 | elementSpec=( ElementSpecificationClassDefinition | ElementSpecificationComponents1 ) |
---|
353 | ; |
---|
354 | |
---|
355 | ElementSpecificationComponents1 returns ElementSpec::uElementSpec : |
---|
356 | {ElementSpec::COMPONENTS} attributes=ElementAttributes typeSpec=TypeSpecification |
---|
357 | components+=ComponentItem ';' |
---|
358 | ; |
---|
359 | |
---|
360 | ReplaceableKeyword returns RedeclareKeywords::uRedeclareKeywords : |
---|
361 | {RedeclareKeywords::REPLACEABLE} 'replaceable' |
---|
362 | ; |
---|
363 | |
---|
364 | RedeclareKeyword returns RedeclareKeywords::uRedeclareKeywords : |
---|
365 | {RedeclareKeywords::REDECLARE} 'redeclare' |
---|
366 | ; |
---|
367 | |
---|
368 | RedeclareReplaceableKeyword returns RedeclareKeywords::uRedeclareKeywords : |
---|
369 | {RedeclareKeywords::REDECLARE_REPLACEABLE} 'redeclare' 'replaceable' |
---|
370 | ; |
---|
371 | |
---|
372 | |
---|
373 | Each returns Each::uEach : |
---|
374 | {Each::EACH} 'each' |
---|
375 | |{Each::NON_EACH} |
---|
376 | ; |
---|
377 | |
---|
378 | ElementAttributes returns ElementAttributes::uElementAttributes : |
---|
379 | {ElementAttributes::ATTR} (flowPrefix?='flow'|streamPrefix?='stream')? |
---|
380 | variability=Variability direction=Direction arrayDim=ArrayDim? |
---|
381 | ; |
---|
382 | |
---|
383 | Variability returns Variability::uVariability : |
---|
384 | {Variability::CONST} 'constant' |
---|
385 | |{Variability::PARAM} 'parameter' |
---|
386 | |{Variability::DISCRETE} 'discrete' |
---|
387 | |{Variability::VAR} |
---|
388 | ; |
---|
389 | |
---|
390 | Direction returns Direction::uDirection : |
---|
391 | {Direction::INPUT} 'input' |
---|
392 | |{Direction::OUTPUT} 'output' |
---|
393 | |{Direction::BIDIR} |
---|
394 | ; |
---|
395 | |
---|
396 | ArrayDim returns ArrayDim::ArrayDim : |
---|
397 | {ArrayDim::ArrayDim} '[' subscripts+=Subscript (',' subscripts+=Subscript)* ']' |
---|
398 | ; |
---|
399 | |
---|
400 | Expression returns Exp::uExp : |
---|
401 | ExprIf | ExprRange |
---|
402 | ; |
---|
403 | |
---|
404 | ExprIf returns Exp::uExp : |
---|
405 | {Exp::IFEXP} 'if' ifExp=Expression 'then' trueBranch=Expression |
---|
406 | (elseIfBranch+=ExprElseIfBranchTuple)* |
---|
407 | ('else' elseBranch=Expression) |
---|
408 | ; |
---|
409 | |
---|
410 | ExprElseIfBranchTuple returns Exp::tuple_ElseIfBranch : |
---|
411 | 'elseif' exp1=Expression 'then' exp2=Expression |
---|
412 | ; |
---|
413 | |
---|
414 | ExprRange returns Exp::uExp : |
---|
415 | ExprLogical ({Exp::RANGE.start=current} ':' step=ExprLogical (':' stop=ExprLogical)? )? |
---|
416 | ; |
---|
417 | |
---|
418 | ExprLogical returns Exp::uExp : |
---|
419 | ExprLogicalTerm ({Exp::LBINARY.exp1=current} op=OperatorOr exp2=ExprLogical)? |
---|
420 | ; |
---|
421 | |
---|
422 | ExprLogicalTerm returns Exp::uExp : |
---|
423 | ExprLogicalFactor ({Exp::LBINARY.exp1=current} op=OperatorAnd exp2=ExprLogicalTerm)? |
---|
424 | ; |
---|
425 | |
---|
426 | ExprLogicalFactor returns Exp::uExp : |
---|
427 | ExprRelation | |
---|
428 | {Exp::LUNARY} op=OperatorNot exp=ExprRelation |
---|
429 | ; |
---|
430 | |
---|
431 | ExprRelation returns Exp::uExp : |
---|
432 | ExprArithmetic |
---|
433 | ({Exp::RELATION.exp1=current} op=( OperatorLess | OperatorLessEq | OperatorGreater | OperatorGreaterEq |
---|
434 | | OperatorEqual | OperatorNotEqual ) exp2=ExprArithmetic)? |
---|
435 | ; |
---|
436 | |
---|
437 | ExprArithmetic returns Exp::uExp : |
---|
438 | ExprUnaryArithmetic |
---|
439 | ({Exp::BINARY.exp1=current} op=(OperatorAdd | OperatorSub | OperatorAddEW | OperatorSubEW) exp2=ExprArithmetic2)? |
---|
440 | ; |
---|
441 | |
---|
442 | ExprArithmetic2 returns Exp::uExp : |
---|
443 | ExprArithmeticTerm |
---|
444 | ({Exp::BINARY.exp1=current} op=(OperatorAdd | OperatorSub | OperatorAddEW | OperatorSubEW) exp2=ExprArithmetic2)? |
---|
445 | ; |
---|
446 | |
---|
447 | ExprUnaryArithmetic returns Exp::uExp : |
---|
448 | ExprArithmeticTerm | |
---|
449 | {Exp::UNARY} op=(OperatorUnPlus | OperatorUnMinus | OperatorUnPlusEW | OperatorUnMinusEW) |
---|
450 | exp=ExprArithmeticTerm |
---|
451 | ; |
---|
452 | |
---|
453 | ExprArithmeticTerm returns Exp::uExp : |
---|
454 | ExprArithmeticFactor |
---|
455 | ( {Exp::BINARY.exp1=current} op=(OperatorMul | OperatorDiv | OperatorMulEW | OperatorDivEW) |
---|
456 | exp2=ExprArithmeticTerm)? |
---|
457 | ; |
---|
458 | |
---|
459 | ExprArithmeticFactor returns Exp::uExp : |
---|
460 | ExprPrimary ({Exp::BINARY.exp1=current} op=(OperatorPow | OperatorPowEW) exp2=ExprPrimary)? |
---|
461 | ; |
---|
462 | |
---|
463 | ExprPrimary returns Exp::uExp : |
---|
464 | ExprInt | ExprReal | ExprComponentRefOrCall | ExprString | ExprBool | ExprArray |
---|
465 | | ExprMatrix |
---|
466 | | ExprTuple | ExprEnd | ExprDer |
---|
467 | ; |
---|
468 | |
---|
469 | ExprInt returns Exp::INTEGER : |
---|
470 | value=UNSIGNED_INTEGER |
---|
471 | ; |
---|
472 | |
---|
473 | ExprReal returns Exp::REAL : |
---|
474 | value=UNSIGNED_REAL |
---|
475 | ; |
---|
476 | |
---|
477 | ExprComponentRefOrCall returns Exp::uExp : |
---|
478 | {Exp::CALL_INITIAL} 'initial' '(' ')' |
---|
479 | | ExprFunctionCall |
---|
480 | | ExprComponentRef |
---|
481 | ; |
---|
482 | |
---|
483 | ExprComponentRef returns Exp::uExp : |
---|
484 | {Exp::CREF} componentReg=ComponentRef |
---|
485 | ; |
---|
486 | |
---|
487 | ExprFunctionCall returns Exp::uExp : |
---|
488 | {Exp::CALL} function=ComponentRef '(' functionArgs=FunctionArguments? ')' |
---|
489 | ; |
---|
490 | |
---|
491 | ExprString returns Exp::STRING : |
---|
492 | value=STRING |
---|
493 | ; |
---|
494 | |
---|
495 | ExprBool returns Exp::BOOL : |
---|
496 | value=BOOL_VAL |
---|
497 | ; |
---|
498 | |
---|
499 | ExprArray returns Exp::ARRAY : |
---|
500 | '{' arrayExp+=Expression (',' arrayExp+=Expression)* '}' |
---|
501 | ; |
---|
502 | |
---|
503 | ExprMatrix returns Exp::MATRIX : |
---|
504 | '[' matrix+=MatrixRow (';' matrix+=MatrixRow)* ']' |
---|
505 | ; |
---|
506 | |
---|
507 | MatrixRow returns Exp::tuple_Matrix : |
---|
508 | exp+=Expression (',' exp+=Expression)* |
---|
509 | ; |
---|
510 | |
---|
511 | ExprTuple returns Exp::TUPLE : |
---|
512 | {Exp::TUPLE} '(' expressions+=Expression (',' expressions+=Expression)* ')' |
---|
513 | ; |
---|
514 | |
---|
515 | ExprEnd returns Exp::END : |
---|
516 | {Exp::END} 'end' |
---|
517 | ; |
---|
518 | |
---|
519 | ExprDer returns Exp::PARTEVALFUNCTION : |
---|
520 | 'der' '(' function_=ComponentRef (',' functionArgs=FunctionArguments)? ')' |
---|
521 | ; |
---|
522 | |
---|
523 | |
---|
524 | FunctionArguments returns FunctionArgs::uFunctionArguments : |
---|
525 | FunctionArgumentsMixed |
---|
526 | |FunctionArgumentsForIter |
---|
527 | |FunctionNamedArguments |
---|
528 | ; |
---|
529 | |
---|
530 | FunctionArgumentsMixed returns FunctionArgs::uFunctionArguments : |
---|
531 | {FunctionArgs::FUNCTIONARGS} args+=Expression (',' args+=Expression)* (',' argNames+=NamedArguments)* |
---|
532 | ; |
---|
533 | |
---|
534 | FunctionArgumentsForIter returns FunctionArgs::uFunctionArguments : |
---|
535 | {FunctionArgs::FOR_ITER_FARG} exp=Expression 'for' iterators=ForIterator |
---|
536 | ; |
---|
537 | |
---|
538 | FunctionNamedArguments returns FunctionArgs::uFunctionArguments : |
---|
539 | {FunctionArgs::FUNCTIONARGS} argNames+=NamedArguments (',' argNames+=NamedArguments)* |
---|
540 | ; |
---|
541 | |
---|
542 | NamedArguments returns NamedArg::uNamedArg : |
---|
543 | {NamedArg::NAMEDARG} argName=IDENT '=' argValue=Expression |
---|
544 | ; |
---|
545 | |
---|
546 | /* |
---|
547 | Operators |
---|
548 | */ |
---|
549 | |
---|
550 | OperatorAdd returns Operator::ADD : |
---|
551 | {Operator::ADD} '+' |
---|
552 | ; |
---|
553 | |
---|
554 | OperatorSub returns Operator::SUB : |
---|
555 | {Operator::SUB} '-' |
---|
556 | ; |
---|
557 | |
---|
558 | OperatorMul returns Operator::MUL : |
---|
559 | {Operator::MUL} '*' |
---|
560 | ; |
---|
561 | |
---|
562 | OperatorDiv returns Operator::DIV : |
---|
563 | {Operator::DIV} '/' |
---|
564 | ; |
---|
565 | |
---|
566 | OperatorPow returns Operator::POW : |
---|
567 | {Operator::POW} '^' |
---|
568 | ; |
---|
569 | |
---|
570 | OperatorUnPlus returns Operator::UPLUS : |
---|
571 | {Operator::UPLUS} '+' |
---|
572 | ; |
---|
573 | |
---|
574 | OperatorUnMinus returns Operator::UMINUS : |
---|
575 | {Operator::UMINUS} '-' |
---|
576 | ; |
---|
577 | |
---|
578 | OperatorAddEW returns Operator::ADD_EW : |
---|
579 | {Operator::ADD_EW} '.+' |
---|
580 | ; |
---|
581 | |
---|
582 | OperatorSubEW returns Operator::SUB_EW : |
---|
583 | {Operator::SUB_EW} '.-' |
---|
584 | ; |
---|
585 | |
---|
586 | OperatorMulEW returns Operator::MUL_EW : |
---|
587 | {Operator::MUL_EW} '.*' |
---|
588 | ; |
---|
589 | |
---|
590 | OperatorDivEW returns Operator::DIV_EW : |
---|
591 | {Operator::DIV_EW} './' |
---|
592 | ; |
---|
593 | |
---|
594 | OperatorPowEW returns Operator::POW_EW : |
---|
595 | {Operator::POW_EW} '.^' |
---|
596 | ; |
---|
597 | |
---|
598 | OperatorUnPlusEW returns Operator::UPLUS_EW : |
---|
599 | {Operator::UPLUS_EW} '.+' |
---|
600 | ; |
---|
601 | |
---|
602 | OperatorUnMinusEW returns Operator::UMINUS_EW : |
---|
603 | {Operator::UMINUS_EW} '.-' |
---|
604 | ; |
---|
605 | |
---|
606 | OperatorAnd returns Operator::AND : |
---|
607 | {Operator::AND} 'and' |
---|
608 | ; |
---|
609 | |
---|
610 | OperatorOr returns Operator::OR : |
---|
611 | {Operator::OR} 'or' |
---|
612 | ; |
---|
613 | |
---|
614 | OperatorNot returns Operator::NOT : |
---|
615 | {Operator::NOT} 'not' |
---|
616 | ; |
---|
617 | |
---|
618 | OperatorLess returns Operator::LESS : |
---|
619 | {Operator::LESS} '<' |
---|
620 | ; |
---|
621 | |
---|
622 | OperatorLessEq returns Operator::LESSEQ : |
---|
623 | {Operator::LESSEQ} '<=' |
---|
624 | ; |
---|
625 | OperatorGreater returns Operator::GREATER : |
---|
626 | {Operator::GREATER} '>' |
---|
627 | ; |
---|
628 | |
---|
629 | OperatorGreaterEq returns Operator::GREATEREQ : |
---|
630 | {Operator::GREATEREQ} '>=' |
---|
631 | ; |
---|
632 | OperatorEqual returns Operator::EQUAL : |
---|
633 | {Operator::EQUAL} '==' |
---|
634 | ; |
---|
635 | |
---|
636 | OperatorNotEqual returns Operator::NEQUAL : |
---|
637 | {Operator::NEQUAL} ('><'|'!=') |
---|
638 | ; |
---|
639 | |
---|
640 | Subscript returns Subscript::uSubscript : |
---|
641 | {Subscript::NOSUB} ':' |
---|
642 | |{Subscript::SUBSCRIPT} subScript=Expression |
---|
643 | ; |
---|
644 | |
---|
645 | ComponentRef returns ComponentRef::uComponentRef : |
---|
646 | ComponentReferenceQualified |
---|
647 | |{ComponentRef::CREF_IDENT} |
---|
648 | name=IDENT ('[' subscripts+=Subscript (',' subscripts+=Subscript)* ']')? |
---|
649 | // {WILD} |
---|
650 | ; |
---|
651 | |
---|
652 | ComponentReferenceQualified returns ComponentRef::uComponentRef : |
---|
653 | {ComponentRef::CREF_QUAL} |
---|
654 | name=IDENT ('[' subscripts+=Subscript (',' subscripts+=Subscript)* ']')? |
---|
655 | '.' componentRef=ComponentRef |
---|
656 | ; |
---|
657 | |
---|
658 | /* |
---|
659 | 1) FIXME Fully-qualified path FULLYQUALIFIED |
---|
660 | 2) |
---|
661 | */ |
---|
662 | |
---|
663 | Path returns Path::uPath : |
---|
664 | {Path::QUALIFIED} name=IDENT ('.' path=Path|'.*') |
---|
665 | |{Path::IDENT} name=IDENT |
---|
666 | ; |
---|
667 | |
---|
668 | //PathStar returns uPath : |
---|
669 | |
---|
670 | Restriction returns Restriction::uRestriction : |
---|
671 | {Restriction::R_CLASS} 'class' |
---|
672 | |{Restriction::R_MODEL} 'model' |
---|
673 | |{Restriction::R_RECORD} 'record' |
---|
674 | |{Restriction::R_BLOCK} 'block' |
---|
675 | |{Restriction::R_CONNECTOR} 'connector' |
---|
676 | |{Restriction::R_EXP_CONNECTOR} 'expandable' 'connector' |
---|
677 | |{Restriction::R_TYPE} 'type' |
---|
678 | |{Restriction::R_PACKAGE} 'package' |
---|
679 | |{Restriction::R_FUNCTION} 'function' |
---|
680 | |{Restriction::R_ENUMERATION} 'enumeration' |
---|
681 | //|{R_PREDEFINED_INT} 'Integer' |
---|
682 | //|{R_PREDEFINED_REAL} 'Real' |
---|
683 | //|{R_PREDEFINED_STRING} 'String' |
---|
684 | //|{R_PREDEFINED_BOOL} 'Boolean' |
---|
685 | ; |
---|
686 | |
---|
687 | Annotation returns Annotation::uAnnotation: |
---|
688 | {Annotation::ANNOTATION} 'annotation' '(' elementArgs+=ElementArg (',' elementArgs+=ElementArg)* ')' |
---|
689 | ; |
---|
690 | |
---|
691 | // CHECK Had to modifiy the comment argument in the EMF model |
---|
692 | Comment returns Comment::uComment: |
---|
693 | {Comment::COMMENT} (comment=StringComment)? (annotation_=Annotation)? |
---|
694 | ; |
---|
695 | |
---|
696 | StringComment returns Comment::STRING_COMMENT : |
---|
697 | comment=STRING |
---|
698 | ; |
---|
699 | |
---|
700 | ExternalDeclaration returns ExternalDecl::uExternalDecl : |
---|
701 | {ExternalDecl::EXTERNALDECL} (lang=STRING)? ((output_=ComponentRef '=')? funcName=IDENT |
---|
702 | '(' args+=Expression (',' args+=Expression)* ')')? (annotation_=Annotation)? |
---|
703 | ; |
---|
704 | |
---|
705 | /* Not created during parsing |
---|
706 | TimeStamp returns uTimeStamp |
---|
707 | |
---|
708 | ; |
---|
709 | */ |
---|
710 | |
---|
711 | ForIterator returns Iterators::ForIterator : |
---|
712 | tuple=ForIteratorTuple |
---|
713 | ; |
---|
714 | |
---|
715 | ForIterators returns Iterators::ForIterators : |
---|
716 | forIterator+=ForIterator (',' forIterator+=ForIterator)* |
---|
717 | ; |
---|
718 | |
---|
719 | ForIteratorTuple returns Iterators::tuple_ForIterator : |
---|
720 | Ident=IDENT 'in' Exp=Expression |
---|
721 | ; |
---|
722 | |
---|
723 | TypeSpecification returns TypeSpec::uTypeSpec : |
---|
724 | {TypeSpec::TPATH} path=Path (arrayDim=ArrayDim)? |
---|
725 | //|{TCOMPLEX} path=Path '<' typeSpecs+=TypeSpecification |
---|
726 | //(',' typeSpecs+=TypeSpecification)* '>' |
---|
727 | ; |
---|
728 | |
---|
729 | |
---|
730 | /*------------------------------------------------------------------ |
---|
731 | * LEXER RULES |
---|
732 | *------------------------------------------------------------------*/ |
---|
733 | |
---|
734 | |
---|
735 | |
---|
736 | /********************************* |
---|
737 | 2.3 Strings, numbers, etc. |
---|
738 | **********************************/ |
---|
739 | |
---|
740 | terminal ML_COMMENT : '/*' -> '*/'; |
---|
741 | terminal SL_COMMENT : '//' !('\n'|'\r')* ('\r'? '\n')?; |
---|
742 | terminal STRING : |
---|
743 | '"' ( '\\' ('b'|'t'|'n'|'f'|'r'|'"'|'\''|'\\') | !('\\'|'"') )* '"' |
---|
744 | //|"'" ( '\\' ('b'|'t'|'n'|'f'|'r'|'"'|"'"|'\\') | !('\\'|"'") )* "'" |
---|
745 | ; |
---|
746 | terminal WS : (' '|'\t'|'\r'|'\n')+; |
---|
747 | |
---|
748 | terminal UNSIGNED_REAL returns ecore::EDouble: |
---|
749 | (('0'..'9')+ '.' ('0'..'9')* (('E'|'e') ('+'|'-')? ('0'..'9')+)? ) |
---|
750 | |(('0'..'9')+ ('E'|'e') ('+'|'-')? ('0'..'9')+) |
---|
751 | ; |
---|
752 | |
---|
753 | terminal UNSIGNED_INTEGER returns ecore::EInt: |
---|
754 | ('0'..'9')+ |
---|
755 | ; |
---|
756 | |
---|
757 | terminal BOOL_VAL returns ecore::EBoolean : |
---|
758 | 'true' | 'false' |
---|
759 | ; |
---|
760 | |
---|
761 | terminal IDENT : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*; |
---|
762 | |
---|
763 | /********************************* |
---|
764 | 2.2 Operators |
---|
765 | **********************************/ |
---|
766 | |
---|
767 | /* |
---|
768 | terminal DOT : '.' ; |
---|
769 | terminal LPAR : '(' ; |
---|
770 | terminal RPAR : ')' ; |
---|
771 | terminal LBRACK : '[' ; |
---|
772 | terminal RBRACK : ']' ; |
---|
773 | terminal LBRACE : '{' ; |
---|
774 | terminal RBRACE : '}' ; |
---|
775 | terminal EQUALS : '=' ; |
---|
776 | terminal ASSIGN : ':=' ; |
---|
777 | terminal COMMA : ',' ; |
---|
778 | terminal COLON : ':' ; |
---|
779 | terminal SEMICOLON : ';' ; |
---|
780 | */ |
---|
781 | /* elementwise operators */ |
---|
782 | |
---|
783 | //terminal PLUS_EW : '.+' ; /* Modelica 3.0 */ |
---|
784 | //terminal MINUS_EW : '.-' ; /* Modelica 3.0 */ |
---|
785 | //terminal STAR_EW : '.*' ; /* Modelica 3.0 */ |
---|
786 | //terminal SLASH_EW : './' ; /* Modelica 3.0 */ |
---|
787 | //terminal POWER_EW : '.^' ; /* Modelica 3.0 */ |
---|
788 | |
---|
789 | /* |
---|
790 | terminal STAR : '*'('.')? ; |
---|
791 | terminal MINUS : '-'('.')? ; |
---|
792 | terminal PLUS : '+'('.'|'&')? ; |
---|
793 | terminal LESS : '<'('.')? ; |
---|
794 | terminal LESSEQ : '<='('.')? ; |
---|
795 | terminal LESSGT : '!='('.')?|'<>'('.')? ; |
---|
796 | terminal GREATER : '>'('.')? ; |
---|
797 | terminal GREATEREQ : '>='('.')? ; |
---|
798 | terminal EQEQ : '=='('.'|'&')? ; |
---|
799 | terminal POWER : '^'('.')? ; |
---|
800 | terminal SLASH : '/'('.')? ; |
---|
801 | */ |
---|
802 | terminal ANY_OTHER: .; |
---|