forked from modelica/ModelicaSpecification
/
Parser_equations.g
111 lines (94 loc) · 1.76 KB
/
Parser_equations.g
1
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
67
68
69
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
parser grammar Parser_equations;
// Equations
start_rule: equation_section;
equation_section :
'initial'? 'equation' ( equation ';' )*
;
algorithm_section :
'initial'? 'algorithm' ( statement ';' )*
;
equation :
(
// TODO: Ambiguity
simple_expression ( '=' expression )?
| if_equation
| for_equation
| connect_clause
| when_equation
// TODO: Ambiguity
// | component_reference function_call_args
) comment
;
statement :
( component_reference ( ':=' expression | function_call_args )
| '(' output_expression_list ')' ':=' component_reference function_call_args
| 'break'
| 'return'
| if_statement
| for_statement
| while_statement
| when_statement )
comment
;
if_equation :
'if' expression 'then'
( equation ';' )*
( 'elseif' expression 'then'
( equation ';' )*
)*
( 'else'
( equation ';' )*
)?
'end' 'if'
;
if_statement :
'if' expression 'then'
( statement ';' )*
( 'elseif' expression 'then'
( statement ';' )*
)*
( 'else'
( statement ';' )*
)?
'end' 'if'
;
for_equation :
'for' for_indices 'loop'
( equation ';' )*
'end' 'for'
;
for_statement :
'for' for_indices 'loop'
( statement ';' )*
'end' 'for'
;
for_indices :
for_index ( ',' for_index )*
;
for_index :
IDENT ( 'in' expression )?
;
while_statement :
'while' expression 'loop'
( statement ';' )*
'end' 'while'
;
when_equation :
'when' expression 'then'
( equation ';' )*
( 'elsewhen' expression 'then'
( equation ';' )*
)*
'end' 'when'
;
when_statement :
'when' expression 'then'
( statement ';' )*
( 'elsewhen' expression 'then'
( statement ';' )*
)*
'end' 'when'
;
connect_clause :
'connect' '(' component_reference ',' component_reference ')'
;