-
Notifications
You must be signed in to change notification settings - Fork 299
/
dae.rml
296 lines (213 loc) · 5.61 KB
/
dae.rml
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
(**
** file: dae.rml
** description: DAE management and output
**
** RCS: $Id$
**
** This file is not really mine. It will be rewritten later.
**)
(** - Module header *)
module DAE:
with "absyn.rml"
with "dump.rml"
with "exp.rml"
with "explode.rml"
with "algorithm.rml"
type Ident = string
datatype VarKind = VARIABLE | DISCRETE | PARAM | CONST
datatype Type = REAL | INT | BOOL | STRING
datatype Element = VAR of Exp.ComponentRef * VarKind * Type
| EQUATION of Exp.Exp
| ALGORITHM of Algorithm.Algorithm
| COMP of Ident * DAElist
datatype DAElist = DAE of Element list
relation dump: DAElist => ()
end
(** - Relations
**
** The only relations in this module are for printing, and are not
** included in the report.
**)
(*!ignorecode*)
(** relation: dump
**
** This relation prints the DAE in the standard outpur format.
**)
relation dump: DAElist => () =
rule print "fclass " & print n & print "\n" &
dump(l) &
print "end " & print n & print ";\n"
-----------------------------------
dump DAE([COMP(n,l)])
rule dump_vars l &
print "equation\n" &
dump_equations l &
dump_algorithms l
-----------------
dump DAE(l)
end
relation dump_kind =
rule print " constant "
--------------------
dump_kind CONST
rule print " parameter "
--------------------
dump_kind PARAM
rule print " discrete "
--------------------
dump_kind DISCRETE
rule print " "
--------------------
dump_kind VARIABLE
end
relation dump_type =
rule print "Integer "
----------------
dump_type INT
rule print "Real "
----------------
dump_type REAL
rule print "Boolean "
----------------
dump_type BOOL
rule print "String "
----------------
dump_type STRING
end
relation dump_comp: DAEcomp => () =
rule dump_kind kind & dump_type typ &
Exp.print_component_ref id & print "\n"
--------------------------------------
dump_comp(VAR(id, kind, typ))
rule print " " & Exp.print_exp eq & print "\n"
--------------------------------------
dump_comp(EQUATION(eq))
rule print "{ begin " & print id & print " }\n" &
dump contents &
print "{ end " & print id & print " }\n"
--------------------------------------
dump_comp ( COMP(id, contents))
end
relation dump_var : DAEcomp => () =
rule dump_kind kind & dump_type typ &
Exp.print_component_ref id & print ";\n"
--------------------------------------
dump_var(VAR(id, kind, typ))
axiom dump_var _
end
relation dump_equation : DAEcomp => () =
rule print " " & Exp.print_exp eq & print ";\n"
--------------------------------------
dump_equation(EQUATION(eq))
axiom dump_equation _
end
relation dump_algorithm : DAEcomp => () =
rule print "algorithm\n" &
Dump.print_list(stmts, pp_statement, "")
----------------------------------------------
dump_algorithm ALGORITHM(Algorithm.ALGORITHM(stmts))
axiom dump_algorithm _
end
relation dump_vars: DAEcomp list => () =
axiom dump_vars []
rule dump_var first &
dump_vars rest
-------------------
dump_vars first :: rest
end
relation dump_equations: DAEcomp list => () =
axiom dump_equations []
rule dump_equation first &
dump_equations rest
-------------------
dump_equations first :: rest
end
relation dump_algorithms: DAEcomp list => () =
axiom dump_algorithms []
rule dump_algorithm first &
dump_algorithms rest
-------------------
dump_algorithms first :: rest
end
(** relation: pp_statement
**
** Prettyprint an algorithm statement
**)
relation pp_statement : Algorithm.Statement => () =
rule pp_stmt (alg,2)
--------------
pp_statement alg
end
relation pp_stmt : (Algorithm.Statement, int) => () =
rule indent i &
Exp.print_component_ref c &
print " := " &
Exp.print_exp e &
print ";\n"
----------
pp_stmt (Algorithm.ASSIGN(c,e), i)
rule indent i &
print "if " & Exp.print_exp e & print " then\n" &
int_add(i,2) => i' &
pp_stmt_list (then, i') &
pp_else (else, i) &
indent i & print "end if;\n"
-------------------
pp_stmt (Algorithm.IF(e,then,else), i)
rule indent i &
print "for " & print id & print " in " &
Exp.print_exp e & print " loop\n" &
int_add(i,2) => i' &
pp_stmt_list (stmts, i') &
indent i &
print "end for;\n"
-------------------
pp_stmt (Algorithm.FOR(id,e,stmts), i)
rule indent i &
print "while " & Exp.print_exp e & print " loop\n" &
int_add(i,2) => i' &
pp_stmt_list (stmts, i') &
indent i &
print "end while;\n"
-------------------
pp_stmt (Algorithm.WHILE(e,stmts), i)
rule indent i &
print "when " & Exp.print_exp e & print " do\n" &
int_add(i,2) => i' &
pp_stmt_list (stmts, i') &
indent i &
print "end when;\n"
-------------------
pp_stmt (Algorithm.WHEN(e,stmts), i)
rule indent i & print "**ALGORITHM**;\n"
----------------------------------
pp_stmt (_,i)
end
relation pp_stmt_list : (Algorithm.Statement list, int) => () =
axiom pp_stmt_list ([],_)
rule pp_stmt (stmt,i) & pp_stmt_list(stmts,i)
--------------------------------
pp_stmt_list (stmt::stmts,i)
end
relation pp_else : (Algorithm.Else, int) => () =
axiom pp_else (Algorithm.NOELSE, _)
rule indent i &
print "elseif " & Exp.print_exp e & print " then\n" &
int_add(i,2) => i' &
pp_stmt_list (then, i') &
pp_else (else, i)
-----------------
pp_else (Algorithm.ELSEIF(e,then,else), i)
rule indent i &
print "else\n" &
int_add(i,2) => i' &
pp_stmt_list (stmts, i')
------------------------
pp_else (Algorithm.ELSE(stmts), i)
end
relation indent : int => () =
axiom indent 0
rule print " " & int_sub(i,1) => i' & indent i'
------------------------------------------
indent i
end