Skip to content

Commit a98b47a

Browse files
committed
2004-05-14
a little txt file with the 2.1 Modelica grammar very useful for fast referencing git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@1175 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 24d5c2a commit a98b47a

File tree

1 file changed

+278
-0
lines changed

1 file changed

+278
-0
lines changed

xml/grammar/modelica-2.1.grammar.txt

Lines changed: 278 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,278 @@
1+
stored_definition:
2+
[ within [ name ] ";" ]
3+
{ [ final ] class_definition ";" }
4+
5+
class_definition :
6+
[ encapsulated ]
7+
[ partial ]
8+
( class | model | record | block | connector | type | package | function ) class_specifier
9+
10+
class_specifier :
11+
IDENT string_comment composition end IDENT
12+
| IDENT "=" base_prefix name [ array_subscripts ]
13+
[ class_modification ] comment
14+
| IDENT "=" enumeration "(" ( [enum_list] | ":" ) ")" comment
15+
| extends IDENT [ class_modification ] string_comment composition
16+
end IDENT
17+
18+
base_prefix : type_prefix
19+
20+
enum_list : enumeration_literal { "," enumeration_literal}
21+
22+
enumeration_literal : IDENT comment
23+
24+
composition :
25+
element_list
26+
{ public element_list |
27+
protected element_list |
28+
equation_clause |
29+
algorithm_clause
30+
}
31+
[ external [ language_specification ]
32+
[ external_function_call ] [ annotation ";" ]
33+
[ annotation ";" ] ]
34+
35+
language_specification : STRING
36+
37+
external_function_call :
38+
[ component_reference "=" ]
39+
IDENT "(" [ expression { "," expression } ] ")"
40+
41+
element_list :
42+
{ element ";" | annotation ";" }
43+
element :
44+
import_clause |
45+
extends_clause |
46+
[ redeclare ]
47+
[ final ]
48+
[ inner | outer ]
49+
( ( class_definition | component_clause) |
50+
replaceable ( class_definition | component_clause)
51+
[constraining_clause comment])
52+
53+
import_clause :
54+
import ( IDENT "=" name | name ["." "*"] ) comment
55+
56+
extends_clause :
57+
extends name [ class_modification ] [annotation]
58+
59+
constraining_clause :
60+
extends name [ class_modification ]
61+
62+
component_clause:
63+
type_prefix type_specifier [ array_subscripts ] component_list
64+
65+
type_prefix :
66+
[ flow ]
67+
[ discrete | parameter | constant ] [ input | output ]
68+
69+
type_specifier :
70+
name
71+
72+
component_list :
73+
component_declaration { "," component_declaration }
74+
75+
component_declaration :
76+
declaration comment
77+
78+
declaration :
79+
IDENT [ array_subscripts ] [ modification ]
80+
81+
modification :
82+
class_modification [ "=" expression ]
83+
| "=" expression
84+
| ":=" expression
85+
86+
class_modification :
87+
"(" [ argument_list ] ")"
88+
89+
argument_list :
90+
argument { "," argument }
91+
92+
argument :
93+
element_modification
94+
| element_redeclaration
95+
96+
element_modification :
97+
[ each ] [ final ] component_reference [ modification ] string_comment
98+
element_redeclaration :
99+
redeclare [ each ] [ final ]
100+
( ( class_definition | component_clause1) |
101+
replaceable ( class_definition | component_clause1)
102+
[constraining_clause])
103+
104+
component_clause1 :
105+
type_prefix type_specifier component_declaration
106+
107+
equation_clause :
108+
[ initial ] equation { equation ";" | annotation ";" }
109+
110+
algorithm_clause :
111+
[ initial ] algorithm { algorithm ";" | annotation ";" }
112+
113+
equation :
114+
( simple_expression "=" expression
115+
| conditional_equation_e
116+
| for_clause_e
117+
| connect_clause
118+
| when_clause_e
119+
| IDENT function_call )
120+
comment
121+
122+
algorithm :
123+
( component_reference ( ":=" expression | function_call )
124+
| "(" output_expression_list ")" ":=" component_reference function_call
125+
| break
126+
| return
127+
| conditional_equation_a
128+
| for_clause_a
129+
| while_clause
130+
| when_clause_a )
131+
comment
132+
133+
conditional_equation_e :
134+
if expression then
135+
{ equation ";" }
136+
{ elseif expression then
137+
{ equation ";" }
138+
}
139+
[ else
140+
{ equation ";" }
141+
]
142+
end if
143+
144+
conditional_equation_a :
145+
if expression then
146+
{ algorithm ";" }
147+
{ elseif expression then
148+
{ algorithm ";" }
149+
}
150+
[ else
151+
{ algorithm ";" }
152+
]
153+
end if
154+
155+
for_clause_e :
156+
for for_indices loop
157+
{ equation ";" }
158+
end for
159+
160+
for_clause_a :
161+
for for_indices loop
162+
{ algorithm ";" }
163+
end for
164+
165+
for_indices :
166+
for_index {"," for_index}
167+
168+
for_index:
169+
IDENT [ in expression ]
170+
171+
while_clause :
172+
while expression loop
173+
{ algorithm ";" }
174+
end while
175+
176+
when_clause_e :
177+
when expression then
178+
{ equation ";" }
179+
{ elsewhen expression then
180+
{ equation ";" } }
181+
end when
182+
183+
when_clause_a :
184+
when expression then
185+
{ algorithm ";" }
186+
{ elsewhen expression then
187+
{ algorithm ";" } }
188+
end when
189+
190+
connect_clause :
191+
connect "(" component_reference "," component_reference ")"
192+
193+
expression :
194+
simple_expression
195+
| if expression then expression { elseif expression then expression } else
196+
expression
197+
198+
simple_expression :
199+
logical_expression [ ":" logical_expression [ ":" logical_expression ] ]
200+
201+
logical_expression :
202+
logical_term { or logical_term }
203+
204+
logical_term :
205+
logical_factor { and logical_factor }
206+
207+
logical_factor :
208+
[ not ] relation
209+
210+
relation :
211+
arithmetic_expression [ rel_op arithmetic_expression ]
212+
213+
rel_op :
214+
"<" | "<=" | ">" | ">=" | "==" | "<>"
215+
216+
arithmetic_expression :
217+
[ add_op ] term { add_op term }
218+
219+
add_op :
220+
"+" | "-"
221+
222+
term :
223+
factor { mul_op factor }
224+
225+
mul_op :
226+
"*" | "/"
227+
228+
factor :
229+
primary [ "^" primary ]
230+
231+
primary :
232+
UNSIGNED_NUMBER
233+
| STRING
234+
| false
235+
| true
236+
| component_reference [ function_call ]
237+
| "(" output_expression_list ")"
238+
| "[" expression_list { ";" expression_list } "]"
239+
| "{" function_arguments "}"
240+
| end
241+
242+
name :
243+
IDENT [ "." name ]
244+
245+
component_reference :
246+
IDENT [ array_subscripts ] [ "." component_reference ]
247+
248+
function_call :
249+
"(" [ function_arguments ] ")"
250+
251+
function_arguments :
252+
expression [ "," function_arguments | for for_indices ]
253+
| named_arguments
254+
255+
named_arguments: named_argument [ "," named_arguments ]
256+
257+
named_argument: IDENT "=" expression
258+
259+
output_expression_list:
260+
[ expression ] { "," [ expression ] }
261+
262+
expression_list :
263+
expression { "," expression }
264+
265+
array_subscripts :
266+
"[" subscript { "," subscript } "]"
267+
268+
subscript :
269+
":" | expression
270+
271+
comment :
272+
string_comment [ annotation ]
273+
274+
string_comment :
275+
[ STRING { "+" STRING } ]
276+
277+
annotation :
278+
annotation class_modification

0 commit comments

Comments
 (0)