source: branches/xtext-MDT/org.modelica.xtext.core/src/org/modelica/xtext/ModelicaAST.xtext @ 548

Last change on this file since 548 was 548, checked in by nasko, 15 years ago

added ecore models for elements, graphical annotation and GUI

File size: 25.8 KB
Line 
1grammar org.modelica.xtext.ModelicaAST hidden(WS, ML_COMMENT, SL_COMMENT)
2
3import "http://www.eclipse.org/emf/2002/Ecore" as ecore
4import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Program" as Program
5import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Within" as Within
6import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Class" as Class
7import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//ClassDef" as ClassDef
8import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//EnumDef" as EnumDef
9import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//EnumLiteral" as EnumLiteral
10import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//ClassPart" as ClassPart
11import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//ElementItem" as ElementItem
12import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Element" as Element
13import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//ConstrainClass" as ConstrainClass
14import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//ElementSpec" as ElementSpec
15import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//InnerOuter" as InnerOuter
16import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Import" as Import
17import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//ComponentItem" as ComponentItem
18import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//ComponentCondition" as ComponentCondition
19import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Component" as Component
20import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//EquationItem" as EquationItem
21import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//AlgorithmItem" as AlgorithmItem
22import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Equation" as Equation
23import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//AlgorithmStatement" as AlgorithmStatement
24import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Modifications" as Modifications
25import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//ElementArg" as ElementArg
26import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//RedeclareKeywords" as RedeclareKeywords
27import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Each" as Each
28import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//ElementAttributes" as ElementAttributes
29import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Variability" as Variability
30import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Direction" as Direction
31import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//ArrayDim" as ArrayDim
32import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Exp" as Exp
33import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//FunctionArgs" as FunctionArgs
34import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//NamedArg" as NamedArg
35import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Operator" as Operator
36import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Subscript" as Subscript
37import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//ComponentRef" as ComponentRef
38import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Path" as Path
39import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Restriction" as Restriction
40import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Annotation" as Annotation
41import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Comment" as Comment
42import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//ExternalDecl" as ExternalDecl
43import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//TimeStamp" as TimeStamp
44import "platform:/resource/org.modelica.emf/model/OpenModelicaAbstactSyntax.ecore#//Iterators" as Iterators
45import "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
61StorageUnit returns Program::PROGRAM :
62    withinClause=WithinClause
63    (classes+=Class ';')*
64    ;
65
66WithinClause returns Within::uWithin :
67    {Within::WITHIN} 'within' (path=Path)? ';'
68    | {Within::TOP}
69    ;
70
71Class 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
77InnerClass returns Class::uClass :
78    {Class::CLASS}
79    encapsulatedPrefix?=('encapsulated')? partialPrefix?=('partial')?
80    restriction=Restriction (name=IDENT body=ClassDefinition | 'extends' body=ClassDefinitionExtends)
81    ;
82
83ClassDefinition returns ClassDef::uClassDef :
84    ClassDefinitionDerived
85    | ClassDefinitionEnum
86    | ClassDefinitionOverload
87    | ClassDefinitionPartialDer
88    | ClassDefinitionParts
89    ;
90   
91ClassDefinitionDerived returns ClassDef::DERIVED :
92    '=' attributes=ElementAttributes typeSpec=TypeSpecification
93    ('(' arguments+=ElementArg (',' arguments+=ElementArg)* ')')?  comment=Comment
94    ;
95
96ClassDefinitionEnum returns ClassDef::ENUMERATION :
97    '=' 'enumeration' '(' enumLiterals=EnumerationDefinition ')' comment=Comment
98    ;
99
100ClassDefinitionOverload returns ClassDef::OVERLOAD :
101    '=' 'overload' '(' functionNames+=Path (',' functionNames+=Path)* ')' comment=Comment
102    ;
103
104// CHECK Comment?
105ClassDefinitionPartialDer returns ClassDef::PDER :
106    '=' 'der' '(' functionName=Path (',' vars+=IDENT)+ ')'
107    ;
108// CHECK Comment or StringComment
109ClassDefinitionExtends 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
117ClassDefinitionParts returns ClassDef::PARTS :
118    comment=StringComment? (classParts+=ClassPartInitial)?
119    (classParts+=ClassPart)* (classParts+=ClassPartExternal)?
120    'end' nameEnd=IDENT
121    ;
122EnumerationDefinition returns EnumDef::uEnumDef :
123    {EnumDef::ENUMLITERALS} enumLiterals+=EnumLiteral (',' enumLiterals+=EnumLiteral)*
124    | {EnumDef::ENUM_COLON} ':'
125    ;
126
127EnumLiteral returns EnumLiteral::uEnumLiteral :
128    {EnumLiteral::ENUMLITERAL} literal=IDENT comment=Comment
129    ;
130   
131ClassPart 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
140ClassPartInitial returns ClassPart::uClassPart :
141    {ClassPart::PUBLIC} (contents+=ElementItem)+
142    ;
143   
144ClassPartExternal returns ClassPart::uClassPart :
145    {ClassPart::EXTERNAL} 'external' externalDecl=ExternalDeclaration ';'
146    (annotationNode=Annotation ';')?
147    ;
148
149ElementItem 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   
163Element 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/*
173ConstrainClass returns uConstrainClass :
174    {CONSTRAINCLASS} elementSpec=ElementSpecification comment=Comment
175    ;
176*/
177
178
179ElementSpecification returns ElementSpec::uElementSpec :
180    ElementSpecificationImport
181    |ElementSpecificationExtends
182    |ElementSpecificationClassDefinition
183    |ElementSpecificationComponents
184    ;
185
186ElementSpecificationImport returns ElementSpec::uElementSpec :
187    {ElementSpec::IMPORT} 'import' import_=Import comment=Comment
188    ;
189
190ElementSpecificationExtends returns ElementSpec::uElementSpec :
191    {ElementSpec::EXTENDS} 'extends' path=Path ( '('
192    elementArg+=ElementArg (',' elementArg+=ElementArg)* ')' )? annotationOpt=Annotation?
193    ;
194
195/* FIXME check the 'replaceable' */
196ElementSpecificationClassDefinition returns ElementSpec::uElementSpec :
197    {ElementSpec::CLASSDEF} /*replaceable_?=('replaceable')?*/ class_=InnerClass
198    ;
199   
200ElementSpecificationComponents returns ElementSpec::uElementSpec :
201    {ElementSpec::COMPONENTS} attributes=ElementAttributes typeSpec=TypeSpecification
202    components+=ComponentItem (',' components+=ComponentItem)*
203    ;
204       
205InnerOuter 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
216Import returns Import::uImport :
217    {Import::NAMED_IMPORT} name=IDENT '=' path=Path
218    |{Import::QUAL_IMPORT} path=Path
219    //|{UNQUAL_IMPORT} path=Path
220    ;
221
222ComponentItem returns ComponentItem::uComponentItem :
223    {ComponentItem::COMPONENTITEM} component=Component condition=ComponentCondition? comment=Comment
224    ;
225
226ComponentCondition returns ComponentCondition::ComponentCondition :
227    'if' condition=Expression
228    ;
229
230Component returns Component::uComponent :
231    {Component::COMPONENT} name=IDENT arrayDim=ArrayDim? modification=Modification?
232    ;
233
234EquationItem returns EquationItem::uEquationItem :
235    {EquationItem::EQUATIONITEM} equation_=Equation comment=Comment ';'
236    | {EquationItem::EQUATIONITEMANN} annotation_=Annotation ';'
237    ;
238
239AlgorithmItem returns AlgorithmItem::uAlgorithmItem :
240    {AlgorithmItem::ALGORITHMITEM} algorithm_=AlgorithmStatement comment=Comment ';'
241    | {AlgorithmItem::ALGORITHMITEMANN} annotation_=Annotation ';'
242    ;
243
244Equation returns Equation::uEquation :
245    EquationIf | EquationEquals | EquationConnect | EquationFor | EquationWhenEq
246    | EquationNoRetCall  //FIXME what is this doing?
247    //|EqFailure
248    ;
249   
250EquationIf returns Equation::EQ_IF :
251    'if' ifExp=Expression 'then' (equationTrueItems+=EquationItem)*
252    (elseIfBranches+=ElseIfBranch)*
253    ('else' (equationElseItems+=EquationItem)*)?
254    'end' 'if'
255    ;
256
257ElseIfBranch returns Equation::tuple_ElseIfBranch :
258    'elseif' exp=Expression 'then' (equationItem+=EquationItem)*
259    ;
260   
261EquationEquals returns Equation::EQ_EQUALS :
262    leftSide=ExprRange '=' rightSide=Expression
263    ;
264EquationNoRetCall returns Equation::EQ_NORETCALL :
265    functionName=ComponentRef '(' functionArgs=FunctionArguments? ')'
266    ;
267
268EquationConnect returns Equation::EQ_CONNECT :
269    'connect' '(' connector1=ComponentRef ',' connector2=ComponentRef ')'
270    ;
271
272EquationFor returns Equation::EQ_FOR :
273    'for' iterators=ForIterators 'loop' (forEquations+=EquationItem)* 'end' 'for'
274    ;
275
276EquationWhenEq returns Equation::EQ_WHEN_E :
277    'when' whenExp=Expression 'then' (whenEquations+=EquationItem)*
278    (elseWhenEquations+=ElseWhenEquationBranch)*
279    'end' 'when'
280    ;
281
282ElseWhenEquationBranch returns Equation::tuple_ElseWhenEquation :
283    'elsewhen' exp=Expression 'then' (equationItem+=EquationItem)*
284    ;   
285
286AlgorithmStatement returns AlgorithmStatement::uAlgorithmStatement :
287    AlgorithmIf | AlgorithmAssign | AlgorithmFor | AlgorithmWhen
288    |AlgorithmNoRetCall
289    | AlgorithmReturn | AlgorithmWhile | AlgorithmBreak
290    ;
291
292AlgorithmIf returns AlgorithmStatement::ALG_IF:
293    'if' ifExp=Expression 'then' (trueBranch+=AlgorithmItem)*
294    (elseIfAlgorithmBranch+=ElseIfAlgorithmBranch)*
295    ('else' (elseBranch+=AlgorithmItem)*)?
296    'end' 'if'
297    ;
298
299ElseIfAlgorithmBranch returns AlgorithmStatement::tuple_ElseIfAlgorithmBranch :
300    'elseif' exp=Expression 'then' (algorithmItem+=AlgorithmItem)*
301    ;
302
303AlgorithmAssign returns AlgorithmStatement::ALG_ASSIGN:
304    assignComponent=ExprRange ':=' value=Expression
305    ;
306AlgorithmNoRetCall returns AlgorithmStatement::ALG_NORETCALL :
307    functionCall=ComponentRef '(' functionArgs=FunctionArguments? ')'
308    ;
309
310AlgorithmFor returns AlgorithmStatement::ALG_FOR :
311    'for' iterators=ForIterators 'loop' (forBody+=AlgorithmItem)* 'end' 'for'
312    ;
313
314AlgorithmWhen returns AlgorithmStatement::ALG_WHEN_A :
315    'when' boolExpr=Expression 'then' (whenBody+=AlgorithmItem)
316    (elseWhenAlgorithmBranch+=ElseWhenAlgorithmBranch)*
317    'end' 'when'
318    ;
319
320ElseWhenAlgorithmBranch returns AlgorithmStatement::tuple_ElseWhenAlgorithmBranch :
321    'elsewhen' exp=Expression 'then' (algorithmItem+=AlgorithmItem)*
322    ;   
323
324AlgorithmReturn returns AlgorithmStatement::ALG_RETURN :
325    {AlgorithmStatement::ALG_RETURN} 'return'
326    ;
327
328AlgorithmWhile returns AlgorithmStatement::ALG_WHILE :
329    {AlgorithmStatement::ALG_WHILE} 'while' boolExpr=Expression 'loop' (whileBody+=AlgorithmItem)* 'end' 'while'
330    ;
331
332AlgorithmBreak returns AlgorithmStatement::ALG_BREAK :
333    {AlgorithmStatement::ALG_BREAK} 'break'
334    ;
335
336Modification returns Modifications::uModification :
337    {Modifications::CLASSMOD}   (
338    '(' elementArgList+=ElementArg (',' elementArgList+=ElementArg)* ')' ('=' expOption=Expression)?
339    | ('='|':=') expOption=Expression)
340    ;
341   
342// TODO componentRef? constrain part
343ElementArg 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
355ElementSpecificationComponents1 returns ElementSpec::uElementSpec :
356    {ElementSpec::COMPONENTS} attributes=ElementAttributes typeSpec=TypeSpecification
357    components+=ComponentItem ';'
358    ;
359   
360ReplaceableKeyword returns RedeclareKeywords::uRedeclareKeywords :
361    {RedeclareKeywords::REPLACEABLE} 'replaceable'
362    ;
363
364RedeclareKeyword returns RedeclareKeywords::uRedeclareKeywords :
365    {RedeclareKeywords::REDECLARE} 'redeclare'
366    ;
367
368RedeclareReplaceableKeyword returns RedeclareKeywords::uRedeclareKeywords :
369    {RedeclareKeywords::REDECLARE_REPLACEABLE} 'redeclare' 'replaceable'
370    ;
371
372
373Each returns Each::uEach :
374    {Each::EACH} 'each'
375    |{Each::NON_EACH}
376    ;
377
378ElementAttributes returns ElementAttributes::uElementAttributes  :
379    {ElementAttributes::ATTR} (flowPrefix?='flow'|streamPrefix?='stream')?
380    variability=Variability direction=Direction arrayDim=ArrayDim?
381    ;
382
383Variability returns Variability::uVariability :
384    {Variability::CONST} 'constant'
385    |{Variability::PARAM} 'parameter'
386    |{Variability::DISCRETE} 'discrete'
387    |{Variability::VAR}
388    ;
389   
390Direction returns Direction::uDirection :
391    {Direction::INPUT} 'input'
392    |{Direction::OUTPUT} 'output'
393    |{Direction::BIDIR}
394    ;   
395   
396ArrayDim returns ArrayDim::ArrayDim :
397    {ArrayDim::ArrayDim} '[' subscripts+=Subscript (',' subscripts+=Subscript)* ']'
398    ;   
399
400Expression returns Exp::uExp :
401    ExprIf | ExprRange
402    ;
403   
404ExprIf returns Exp::uExp :
405    {Exp::IFEXP} 'if' ifExp=Expression 'then' trueBranch=Expression
406    (elseIfBranch+=ExprElseIfBranchTuple)*
407    ('else' elseBranch=Expression)
408    ;
409
410ExprElseIfBranchTuple returns Exp::tuple_ElseIfBranch :
411    'elseif' exp1=Expression 'then' exp2=Expression
412    ;
413
414ExprRange returns Exp::uExp :
415    ExprLogical ({Exp::RANGE.start=current} ':' step=ExprLogical (':' stop=ExprLogical)? )?
416    ;
417   
418ExprLogical returns Exp::uExp :
419    ExprLogicalTerm ({Exp::LBINARY.exp1=current} op=OperatorOr exp2=ExprLogical)?
420    ;
421   
422ExprLogicalTerm returns Exp::uExp :
423    ExprLogicalFactor ({Exp::LBINARY.exp1=current}  op=OperatorAnd exp2=ExprLogicalTerm)?
424    ;
425   
426ExprLogicalFactor returns Exp::uExp :
427    ExprRelation |
428    {Exp::LUNARY} op=OperatorNot exp=ExprRelation
429    ;
430
431ExprRelation returns Exp::uExp :
432    ExprArithmetic
433    ({Exp::RELATION.exp1=current}  op=( OperatorLess | OperatorLessEq | OperatorGreater | OperatorGreaterEq
434        | OperatorEqual | OperatorNotEqual ) exp2=ExprArithmetic)?
435    ;
436
437ExprArithmetic returns Exp::uExp :
438    ExprUnaryArithmetic
439    ({Exp::BINARY.exp1=current} op=(OperatorAdd | OperatorSub | OperatorAddEW | OperatorSubEW) exp2=ExprArithmetic2)?
440    ;
441
442ExprArithmetic2 returns Exp::uExp :
443    ExprArithmeticTerm
444    ({Exp::BINARY.exp1=current} op=(OperatorAdd | OperatorSub | OperatorAddEW | OperatorSubEW) exp2=ExprArithmetic2)?
445    ;
446
447ExprUnaryArithmetic returns Exp::uExp :
448    ExprArithmeticTerm |
449    {Exp::UNARY} op=(OperatorUnPlus | OperatorUnMinus | OperatorUnPlusEW | OperatorUnMinusEW)
450    exp=ExprArithmeticTerm
451    ;
452
453ExprArithmeticTerm returns Exp::uExp :
454    ExprArithmeticFactor 
455    ( {Exp::BINARY.exp1=current} op=(OperatorMul | OperatorDiv | OperatorMulEW | OperatorDivEW)
456    exp2=ExprArithmeticTerm)?
457    ;
458
459ExprArithmeticFactor returns Exp::uExp :
460    ExprPrimary ({Exp::BINARY.exp1=current} op=(OperatorPow | OperatorPowEW) exp2=ExprPrimary)?
461    ;
462
463ExprPrimary returns Exp::uExp :
464    ExprInt | ExprReal | ExprComponentRefOrCall | ExprString | ExprBool | ExprArray
465    | ExprMatrix
466    | ExprTuple | ExprEnd | ExprDer
467    ;
468   
469ExprInt returns Exp::INTEGER :
470    value=UNSIGNED_INTEGER
471    ;
472
473ExprReal returns Exp::REAL :
474    value=UNSIGNED_REAL
475    ;
476
477ExprComponentRefOrCall returns Exp::uExp :
478    {Exp::CALL_INITIAL} 'initial' '(' ')'
479    | ExprFunctionCall
480    | ExprComponentRef
481    ;
482
483ExprComponentRef returns Exp::uExp :
484    {Exp::CREF} componentReg=ComponentRef
485    ;
486
487ExprFunctionCall returns Exp::uExp :
488    {Exp::CALL} function=ComponentRef '(' functionArgs=FunctionArguments? ')'
489    ;
490   
491ExprString returns Exp::STRING :
492    value=STRING
493    ;
494     
495ExprBool returns Exp::BOOL :
496    value=BOOL_VAL
497    ;
498       
499ExprArray returns Exp::ARRAY :
500    '{' arrayExp+=Expression (',' arrayExp+=Expression)* '}'
501    ;
502
503ExprMatrix returns Exp::MATRIX :
504    '[' matrix+=MatrixRow (';' matrix+=MatrixRow)* ']'
505    ;
506   
507MatrixRow returns Exp::tuple_Matrix :
508    exp+=Expression (',' exp+=Expression)*
509    ;
510   
511ExprTuple returns Exp::TUPLE :
512    {Exp::TUPLE} '(' expressions+=Expression (',' expressions+=Expression)* ')'
513    ;
514   
515ExprEnd returns Exp::END :
516    {Exp::END} 'end'
517    ;
518   
519ExprDer returns Exp::PARTEVALFUNCTION :
520    'der' '(' function_=ComponentRef (',' functionArgs=FunctionArguments)? ')'
521    ;
522   
523
524FunctionArguments returns FunctionArgs::uFunctionArguments :
525    FunctionArgumentsMixed
526    |FunctionArgumentsForIter
527    |FunctionNamedArguments
528    ;
529   
530FunctionArgumentsMixed returns FunctionArgs::uFunctionArguments :
531    {FunctionArgs::FUNCTIONARGS} args+=Expression (',' args+=Expression)* (',' argNames+=NamedArguments)*
532    ;
533
534FunctionArgumentsForIter returns FunctionArgs::uFunctionArguments :
535    {FunctionArgs::FOR_ITER_FARG} exp=Expression 'for' iterators=ForIterator
536    ;
537
538FunctionNamedArguments returns FunctionArgs::uFunctionArguments :
539    {FunctionArgs::FUNCTIONARGS} argNames+=NamedArguments (',' argNames+=NamedArguments)*
540    ;
541       
542NamedArguments returns NamedArg::uNamedArg :
543    {NamedArg::NAMEDARG} argName=IDENT '=' argValue=Expression
544    ;
545
546/*
547    Operators
548*/
549   
550OperatorAdd returns Operator::ADD :
551    {Operator::ADD} '+'
552    ;
553   
554OperatorSub returns Operator::SUB :
555    {Operator::SUB} '-'
556    ;
557   
558OperatorMul returns Operator::MUL :
559    {Operator::MUL} '*'
560    ;
561   
562OperatorDiv returns Operator::DIV :
563    {Operator::DIV} '/'
564    ;
565   
566OperatorPow returns Operator::POW :
567    {Operator::POW} '^'
568    ;
569
570OperatorUnPlus returns Operator::UPLUS :
571    {Operator::UPLUS} '+'
572    ;
573
574OperatorUnMinus returns Operator::UMINUS :
575    {Operator::UMINUS} '-'
576    ;
577
578OperatorAddEW returns Operator::ADD_EW :
579    {Operator::ADD_EW} '.+'
580    ;
581   
582OperatorSubEW returns Operator::SUB_EW :
583    {Operator::SUB_EW} '.-'
584    ;
585   
586OperatorMulEW returns Operator::MUL_EW :
587    {Operator::MUL_EW} '.*'
588    ;
589   
590OperatorDivEW returns Operator::DIV_EW :
591    {Operator::DIV_EW} './'
592    ;
593   
594OperatorPowEW returns Operator::POW_EW :
595    {Operator::POW_EW} '.^'
596    ;
597
598OperatorUnPlusEW returns Operator::UPLUS_EW :
599    {Operator::UPLUS_EW} '.+'
600    ;
601
602OperatorUnMinusEW returns Operator::UMINUS_EW :
603    {Operator::UMINUS_EW} '.-'
604    ;
605
606OperatorAnd returns Operator::AND :
607    {Operator::AND} 'and'
608    ;
609
610OperatorOr returns Operator::OR :
611    {Operator::OR} 'or'
612    ;
613   
614OperatorNot returns Operator::NOT :
615    {Operator::NOT} 'not'
616    ;
617   
618OperatorLess returns Operator::LESS :
619    {Operator::LESS} '<'
620    ;
621   
622OperatorLessEq returns Operator::LESSEQ :
623    {Operator::LESSEQ} '<='
624    ;
625OperatorGreater returns Operator::GREATER :
626    {Operator::GREATER} '>'
627    ;
628   
629OperatorGreaterEq returns Operator::GREATEREQ :
630    {Operator::GREATEREQ} '>='
631    ;
632OperatorEqual returns Operator::EQUAL :
633    {Operator::EQUAL} '=='
634    ;
635   
636OperatorNotEqual returns Operator::NEQUAL :
637    {Operator::NEQUAL} ('><'|'!=')
638    ;
639
640Subscript returns Subscript::uSubscript  :
641    {Subscript::NOSUB} ':'
642    |{Subscript::SUBSCRIPT} subScript=Expression
643     ;
644     
645ComponentRef returns ComponentRef::uComponentRef  :
646    ComponentReferenceQualified
647    |{ComponentRef::CREF_IDENT}
648    name=IDENT ('[' subscripts+=Subscript (',' subscripts+=Subscript)* ']')?
649    //  {WILD} 
650    ;
651
652ComponentReferenceQualified 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   
663Path returns Path::uPath :
664    {Path::QUALIFIED} name=IDENT ('.' path=Path|'.*')
665    |{Path::IDENT} name=IDENT
666    ;
667
668//PathStar returns uPath :
669   
670Restriction 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
687Annotation 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
692Comment returns Comment::uComment:
693    {Comment::COMMENT} (comment=StringComment)? (annotation_=Annotation)?
694    ;
695
696StringComment returns Comment::STRING_COMMENT :
697     comment=STRING
698    ;
699
700ExternalDeclaration 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
706TimeStamp returns uTimeStamp
707
708    ;
709*/
710
711ForIterator returns Iterators::ForIterator :
712    tuple=ForIteratorTuple
713    ;
714
715ForIterators returns Iterators::ForIterators :
716    forIterator+=ForIterator (',' forIterator+=ForIterator)*
717    ;
718
719ForIteratorTuple returns Iterators::tuple_ForIterator :
720    Ident=IDENT 'in' Exp=Expression
721    ;
722   
723TypeSpecification 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
740terminal ML_COMMENT : '/*' -> '*/';
741terminal SL_COMMENT     : '//' !('\n'|'\r')* ('\r'? '\n')?;
742terminal STRING :
743            '"' ( '\\' ('b'|'t'|'n'|'f'|'r'|'"'|'\''|'\\') | !('\\'|'"') )* '"'
744            //|"'" ( '\\' ('b'|'t'|'n'|'f'|'r'|'"'|"'"|'\\') | !('\\'|"'") )* "'"
745        ;
746terminal WS         : (' '|'\t'|'\r'|'\n')+;
747
748terminal UNSIGNED_REAL returns ecore::EDouble:
749    (('0'..'9')+ '.' ('0'..'9')* (('E'|'e') ('+'|'-')? ('0'..'9')+)? )
750    |(('0'..'9')+ ('E'|'e') ('+'|'-')? ('0'..'9')+)
751    ;
752
753terminal UNSIGNED_INTEGER returns ecore::EInt:
754    ('0'..'9')+
755    ;
756
757terminal BOOL_VAL returns ecore::EBoolean :
758    'true' | 'false'
759    ;
760
761terminal IDENT : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;
762
763/*********************************
764    2.2 Operators
765**********************************/
766 
767/*
768terminal    DOT     : '.'           ; 
769terminal    LPAR        : '('       ;
770terminal    RPAR        : ')'       ;
771terminal    LBRACK  : '['       ;
772terminal    RBRACK  : ']'       ;
773terminal    LBRACE  : '{'       ;
774terminal    RBRACE  : '}'       ;
775terminal    EQUALS  : '='       ;
776terminal    ASSIGN  : ':='      ;
777terminal    COMMA       : ','       ;
778terminal    COLON       : ':'       ;
779terminal    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/* 
790terminal STAR       : '*'('.')?                 ;
791terminal MINUS      : '-'('.')?                 ;
792terminal PLUS       : '+'('.'|'&')?             ;
793terminal LESS       : '<'('.')?                 ;
794terminal LESSEQ     : '<='('.')?                ;
795terminal LESSGT     : '!='('.')?|'<>'('.')?     ;
796terminal GREATER        : '>'('.')?                 ;
797terminal GREATEREQ  : '>='('.')?                ;
798terminal EQEQ       : '=='('.'|'&')?            ;
799terminal POWER      : '^'('.')?                 ;
800terminal SLASH      : '/'('.')?                 ;
801*/
802terminal ANY_OTHER: .;
Note: See TracBrowser for help on using the repository browser.