EmbeddedMontiArc.mc4 5.98 KB
Newer Older
Bernhard Rumpe's avatar
BR-sy    
Bernhard Rumpe committed
1
/* (c) https://github.com/MontiCore/monticore */
vonWenckstern's avatar
vonWenckstern committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

package de.monticore.lang.embeddedmontiarc;

/**
 * Grammar for EmbeddedMontiArc.
 *
 */
grammar EmbeddedMontiArc extends de.monticore.lang.monticar.Common2 {

  /** ASTEMACompilationUnit represents the complete component
   * @attribute package          The package declaration of this component
   * @attribute importStatements List of imported elements
   * @attribute Component the root component of the component
   */
  EMACompilationUnit =
    ("package" package:(Name& || ".")+ ";")?
    (ImportStatement )*
    Component;


  /* ======================================================*/
  /* ===== Modified but based on old ARCD Grammar =========*/
  /* ======================================================*/

  /**
  * A component may contain arbitrary many Elements. 
  * This interface may be used as an extension point to 
  * enrich components with further elements.
  */
  interface Element;


  /**
  * A component is a unit of computation or a data store.  
  * The size of a component may scale from a single 
  * procedure to a whole application. A component may be 
  * either decomposed to subcomponents or is atomic. 
  *
  * @attribute name type name of this component
  * @attribute head is used to set generic types, a  
  *   configuration and a parent component
  * @attribute instanceName if this optional name is given, 
  *   a subcomponent is automatically created that 
  *   instantiates this inner component type. This is only 
  *   allowed for inner component definitions. 
  * @attribute body contains the architectural elements 
  *   inherited by this component
  * A components head is used to define generic type 
  * parameters that may be used as port types in the 
  * component, to define configuration parameters that may 
  * be used to configure the component, and to set the  
  * parent component of this component.
  *
  * @attribute genericTypeParameters a list of type  
  *   parameters that may be used as port types in the 
  *   component
  * @attribute parameters a list of Parameters that 
  *   define a configurable component. If a configurable
  *   component is referenced, these parameters have to be 
  *   set.
  * @attribute superComponent the type of the super 
  *   component
  */
  
  symbol scope Component implements Element =
vonWenckstern's avatar
vonWenckstern committed
67
68
69
    "component" (["interface"])? Name
    //("component" | ["component_interface"]) Name
	genericTypeParameters:TypeParameters2?
vonWenckstern's avatar
vonWenckstern committed
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
    (  "("  (Parameter || ",")+  ")" )?
    ("implements" superComponent:ReferenceType)?
    body:ComponentBody;


  /**
  * The body contains architectural elements of 
  * this component.
  *
  * @attribute elements list of architectural elements
  */
  ComponentBody =
    ("{"
      Element*
    "}" );
    
  /**
  * An Interface defines an interface of a component 
  * containing in- and outgoing ports.
  * @attribute ports a list of ports that are contained in 
  *   this interface
  */
  Interface implements Element =
     ("port"|"ports")
    ports:(Port || ",")+ ";" ;

 /**a
  * An incoming port is used to receive messages, an 
  * outgoing port is used to send messages of a specific 
  * type. Ports can now also be specified as an array.
  *
  * @attribute incoming true, if this is an incoming port
  * @attribute outgoing true, if this is an outgoing port
  * @attribute type the message type of this port
  * @attribute name an optional name of this port
  */
  /**might support auto type adding based on last previous type
   * declaration later on
   */
   Port =
          AdaptableKeyword? (incoming:["in"] | outgoing:["out"])
          Type (Name? | Name ( "[" UnitNumberResolution "]" )?) ;


  /**
    * A subcomponent is used to create one or more instances
    *  of another component. This way the hierarchical
    * structure of a component is defined.
    * @attribute type the type of the instantiated component
    * @attribute arguments list of configuration parameters
    *   that are to be set, if the instantiated component is
    *   configurable.
    * @attribute instances list of instances that should be
    *   created
    */
    SubComponent implements Element =
       "instance"
      type:ReferenceType
      ("(" arguments:(Expression || ",")+ ")" )?
Malte Heithoff's avatar
Malte Heithoff committed
129
      ("{" (PortInitialValueOrGuess || ",")+ "}")?
130
      instances:(SubComponentInstance || ",")+ ";" ;
vonWenckstern's avatar
vonWenckstern committed
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146


  /**
  * A subcomponent instance binds the name of an instance
  * with an optional list of simple connectors used to
  * connect this instance with other subcomponents/ports.
  * It does also support component arrays.
  * Simple connectors directly connect outgoing ports of the
  * corresponding subcomponent declaration with one or more target ports.
  *
  * @attribute name the name of this instance
  * @attribute connectors list of simple connectors
  */
  // TODO better/more intuitive name? e.g. "refConnector" (not really good...)
  SubComponentInstance =
    Name
147
148
    ("[" UnitNumberResolution "]")?;

Malte Heithoff's avatar
Malte Heithoff committed
149
150
  PortInitialValueOrGuess =
    Name ( "[" UnitNumberResolution "]" )? (guess:["~"])? "=" Expression;
vonWenckstern's avatar
vonWenckstern committed
151

152
153
154
155
156
157
158
159
160
161
162
  /**
    * port1
	* port1[2]
	* port1[:]
	* sub1.port1
	* sub1[2].port1[3]
	* sub1.*
	* sub1[2].*
  */
  QualifiedNameWithArrayAndStar = QualifiedNameWithArray DotStar?;
  DotStar = "." {noSpace()}? "*";
vonWenckstern's avatar
vonWenckstern committed
163
164
165
166
167
168
169
170
171
172
  /**
  * A connector connects one source port with one or many
  * target ports.
  *
  * @attribute source source port or component instance
  *   name
  * @attribute targets a list of target ports or component
  *   instance names
  */
  Connector implements Element=
173
174
175
176
     "connect" (source:QualifiedNameWithArrayAndStar | 
	            boolLiteral:BooleanLiteral | 
				stringLiteral:StringLiteral| 
				UnitNumberResolution) "->"
vonWenckstern's avatar
vonWenckstern committed
177
178
    targets:ConnectorTargets ";" ;

179
180
   ConnectorTargets = ["#"] | // route symbol terminates inputs
                      (QualifiedNameWithArrayAndStar || ","  )+;
181
182
183
  
  // autoconnect and autoinstantiate is removed
  // for autoconnect use "connect this.* -> sub1.*;" to connect all inports of the parent component to the inports of the sub1 subcomponent having the same name 
vonWenckstern's avatar
vonWenckstern committed
184
}