-
Notifications
You must be signed in to change notification settings - Fork 0
/
snick_pprint.ml.bak.ml
436 lines (400 loc) · 24.5 KB
/
snick_pprint.ml.bak.ml
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
(*
** File: snick_pprint.ml
** Description: Pretty-printer converts from snick source code to well-formed style.
** Last Modified:
**
** Group name: Mainframe
**
** Member names | usernames
** Xianzhuo REN | xianzhuor
** Haoyu LIN | haoyul3
** Zequn MA | zequnm
*)
open Snick_ast
open Format
(* Print program as list of procedures. *)
let rec print_program fmtr prog = print_procs fmtr prog
(* Print list of procedures. *)
and print_procs fmtr = function
| [] -> ()
| x::[] -> fprintf fmtr "%a@," print_proc x
| x::xs -> fprintf fmtr "%a@,%a" print_proc x print_procs xs
(* Print a single procedure. *)
and print_proc fmtr (header, body) =
fprintf fmtr "@[<v>proc %a@;<0 4>@[<v>%a@]@,end@]@." print_proc_header header print_proc_body body
(* Print procedure header. *)
and print_proc_header fmtr (ident, params) =
fprintf fmtr "%s (%a)" ident print_params params
(* Print the list of parameters in header. *)
and print_params fmtr = function
| [] -> ()
| x :: [] -> fprintf fmtr "%a" print_param x
| x :: xs -> fprintf fmtr "%a, %a" print_param x print_params xs
(* Print a single procedure parameter. *)
and print_param fmtr (indicator, param_type, ident) =
fprintf fmtr "%a %a %s" print_param_indc indicator print_type param_type ident
(* Print the indicator of a procedure parameter. *)
and print_param_indc fmtr = function
| Val -> fprintf fmtr "%s" "val"
| Ref -> fprintf fmtr "%s" "ref"
(* Print the type of a procedure parameter. *)
and print_type fmtr = function
| Bool -> fprintf fmtr "%s" "bool"
| Int -> fprintf fmtr "%s" "int"
| Float -> fprintf fmtr "%s" "float"
(* Print procedure body as a list of declarations followed by a list of statements. *)
and print_proc_body fmtr prog_body =
fprintf fmtr "%a@,%a" print_decls prog_body.decls print_stmts prog_body.stmts
(* Print the list of declarations. *)
and print_decls fmtr = function
| [] -> ()
| x :: [] -> fprintf fmtr "%a@," print_decl x
| x :: xs -> fprintf fmtr "%a@,%a" print_decl x print_decls xs
(* Print the list of statements. *)
and print_stmts fmtr = function
| [] -> ()
| x :: [] -> fprintf fmtr "%a" print_stmt x
| x :: xs -> fprintf fmtr "%a@,%a" print_stmt x print_stmts xs
(* Print a single declaration. *)
and print_decl fmtr (var_type, variable) =
fprintf fmtr "%a %a;" print_type var_type print_var variable
and print_var fmtr = function
| Single_variable ident -> fprintf fmtr "%s" ident
| Array_variable (ident, itvls) -> fprintf fmtr "%s[%a]" ident print_itvls itvls
and print_itvls fmtr = function
| [] -> ()
| x::[] -> fprintf fmtr "%a" print_itvl x
| x::xs -> fprintf fmtr "%a,%a" print_itvl x print_itvls xs
and print_itvl fmtr (st_pnt, end_pnt) =
fprintf fmtr "%d..%d" st_pnt end_pnt
and print_stmt fmtr = function
| Atom_stmt atom_stmt -> fprintf fmtr "%a" print_atom_stmt atom_stmt
| Comps_stmt comps_stmt -> fprintf fmtr "%a" print_comps_stmt comps_stmt
and print_atom_stmt fmtr = function
| Assign (elem, expr) -> fprintf fmtr "%a := %a;" print_elem elem print_expr expr
| Read elem -> fprintf fmtr "read %a;" print_elem elem
| Write expr -> fprintf fmtr "write %a;" print_expr expr
| Call (ident, exprs) -> fprintf fmtr "%s(%a);" ident print_exprs exprs
and print_comps_stmt fmtr = function
| If_then (expr, stmts) -> fprintf fmtr "if %a then@;<0 4>@[<v>%a@]@,fi" print_expr expr print_stmts stmts
| If_then_else (expr, then_stmts, else_stmts) -> fprintf fmtr "if %a then@;<0 4>@[<v>%a@]@,else@;<0 4>@[<v>%a@]@,fi" print_expr expr print_stmts then_stmts print_stmts else_stmts
| While (expr, stmts) -> fprintf fmtr "while %a do@;<0 4>@[<v>%a@]@,od" print_expr expr print_stmts stmts
and print_elem fmtr = function
| Single_elem ident -> fprintf fmtr "%s" ident
| Array_elem (ident, idxs) -> fprintf fmtr "%s[%a]" ident print_idxs idxs
and print_idxs fmtr = function
| [] -> ()
| x::[] -> fprintf fmtr "%a" print_idx x
| x::xs -> fprintf fmtr "%a,%a" print_idx x print_idxs xs
and print_idx fmtr = fprintf fmtr "%d"
and print_expr fmtr = function
| Eelem elem -> fprintf fmtr "%a" print_elem elem
| Ebool bool_const -> fprintf fmtr "%B" bool_const
| Eint int_const -> fprintf fmtr "%d" int_const
| Efloat float_const -> fprintf fmtr "%f" float_const
| Estring string_const -> fprintf fmtr "%s" string_const
| Eparen expr -> fprintf fmtr "%a" print_expr (strip_paren expr)
| Ebinop bin_expr -> fprintf fmtr "%a" print_binop bin_expr
| Eunop un_expr -> fprintf fmtr "%a" print_unop un_expr
and print_exprs fmtr = function
| [] -> ()
| x::[] -> fprintf fmtr "%a" print_expr x
| x::xs -> fprintf fmtr "%a, %a" print_expr x print_exprs xs
and print_binop fmtr (lexpr, binop, rexpr) = match binop with
| Op_add -> fprintf fmtr "%a" print_low_expr (lexpr, "+", rexpr)
| Op_sub -> fprintf fmtr "%a" print_low_expr (lexpr, "-", rexpr)
| Op_mul -> fprintf fmtr "%a" print_hgh_expr (lexpr, "*", rexpr)
| Op_div -> fprintf fmtr "%a" print_hgh_expr (lexpr, "/", rexpr)
| Op_eq -> fprintf fmtr "%a" print_eq_expr (lexpr, rexpr)
| Op_ne -> fprintf fmtr "%a" print_ne_expr (lexpr, rexpr)
| Op_lt -> fprintf fmtr "%a" print_comp_expr (lexpr, "<", rexpr)
| Op_gt -> fprintf fmtr "%a" print_comp_expr (lexpr, ">", rexpr)
| Op_le -> fprintf fmtr "%a" print_comp_expr (lexpr, "<=", rexpr)
| Op_ge -> fprintf fmtr "%a" print_comp_expr (lexpr, ">=", rexpr)
| Op_and -> fprintf fmtr "%a" print_and_expr (lexpr, rexpr)
| Op_or -> fprintf fmtr "%a" print_or_expr (lexpr, rexpr)
and print_unop fmtr (unop, expr) = match unop with
| Op_not -> fprintf fmtr "%a" print_not_expr expr
| Op_minus -> fprintf fmtr "%a" print_minus_expr expr
and print_low_expr fmtr = function
| (lexpr, optr, Eparen rexpr_inside) ->
begin
let lexpr_strip = strip_paren lexpr
and rexpr_inside_strip = strip_paren rexpr_inside
in match rexpr_inside_strip with
| Ebinop (_, Op_mul, _) -> fprintf fmtr "%a %s %a" print_expr lexpr_strip optr print_expr rexpr_inside_strip
| Ebinop (_, Op_div, _) -> fprintf fmtr "%a %s %a" print_expr lexpr_strip optr print_expr rexpr_inside_strip
| Eunop (Op_minus, _) -> fprintf fmtr "%a %s %a" print_expr lexpr_strip optr print_expr rexpr_inside_strip
| _ -> fprintf fmtr "%a %s (%a)" print_expr lexpr_strip optr print_expr rexpr_inside_strip
end
| (lexpr, optr, rexpr) ->
let lexpr_strip = strip_paren lexpr
in fprintf fmtr "%a %s %a" print_expr lexpr_strip optr print_expr rexpr
and print_hgh_expr fmtr = function
| (Eparen lexpr_inside, optr, Eparen rexpr_inside) ->
begin
let lexpr_inside_strip = strip_paren lexpr_inside
and rexpr_inside_strip = strip_paren rexpr_inside
in match lexpr_inside_strip with
| Ebinop (_, Op_mul, _) ->
begin
match rexpr_inside_strip with
| Eunop (Op_minus, _) -> fprintf fmtr "%a %s %a" print_expr lexpr_inside_strip optr print_expr rexpr_inside_strip
| _ -> fprintf fmtr "%a %s (%a)" print_expr lexpr_inside_strip optr print_expr rexpr_inside_strip
end
| Ebinop (_, Op_div, _) ->
begin
match rexpr_inside_strip with
| Eunop (Op_minus, _) -> fprintf fmtr "%a %s %a" print_expr lexpr_inside_strip optr print_expr rexpr_inside_strip
| _ -> fprintf fmtr "%a %s (%a)" print_expr lexpr_inside_strip optr print_expr rexpr_inside_strip
end
| Eunop (Op_minus, _) ->
begin
match rexpr_inside_strip with
| Eunop (Op_minus, _) -> fprintf fmtr "%a %s %a" print_expr lexpr_inside_strip optr print_expr rexpr_inside_strip
| _ -> fprintf fmtr "%a %s (%a)" print_expr lexpr_inside_strip optr print_expr rexpr_inside_strip
end
| _ ->
begin
match rexpr_inside_strip with
| Eunop (Op_minus, _) -> fprintf fmtr "(%a) %s %a" print_expr lexpr_inside_strip optr print_expr rexpr_inside_strip
| _ -> fprintf fmtr "(%a) %s (%a)" print_expr lexpr_inside_strip optr print_expr rexpr_inside_strip
end
end
| (Eparen lexpr_inside, optr, rexpr) ->
begin
let lexpr_inside_strip = strip_paren lexpr_inside
in match lexpr_inside_strip with
| Ebinop (_, Op_mul, _) -> fprintf fmtr "%a %s %a" print_expr lexpr_inside_strip optr print_expr rexpr
| Ebinop (_, Op_div, _) -> fprintf fmtr "%a %s %a" print_expr lexpr_inside_strip optr print_expr rexpr
| Eunop (Op_minus, _) -> fprintf fmtr "%a %s %a" print_expr lexpr_inside_strip optr print_expr rexpr
| _ -> fprintf fmtr "(%a) %s %a" print_expr lexpr_inside_strip optr print_expr rexpr
end
| (lexpr, optr, Eparen rexpr_inside) ->
begin
let rexpr_inside_strip = strip_paren rexpr_inside
in match rexpr_inside_strip with
| Eunop (Op_minus, _) -> fprintf fmtr "%a %s %a" print_expr lexpr optr print_expr rexpr_inside_strip
| _ -> fprintf fmtr "%a %s (%a)" print_expr lexpr optr print_expr rexpr_inside_strip
end
| (lexpr, optr, rexpr) -> fprintf fmtr "%a %s %a" print_expr lexpr optr print_expr rexpr
and print_eq_expr fmtr = function
| (Eparen lexpr_inside, Eparen rexpr_inside) ->
begin
let
lexpr_inside_strip = strip_paren lexpr_inside
and
rexpr_inside_strip = strip_paren rexpr_inside
in
match lexpr_inside_strip with
| Ebinop (_, Op_and, _) ->
begin
match rexpr_inside_strip with
| Ebinop (_, Op_add, _) -> fprintf fmtr "(%a) = %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Ebinop (_, Op_sub, _) -> fprintf fmtr "(%a) = %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Ebinop (_, Op_mul, _) -> fprintf fmtr "(%a) = %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Ebinop (_, Op_div, _) -> fprintf fmtr "(%a) = %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Eunop (Op_minus, _) -> fprintf fmtr "(%a) = %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| _ -> fprintf fmtr "(%a) = (%a)" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
end
| Ebinop (_, Op_or, _) ->
begin
match rexpr_inside_strip with
| Ebinop (_, Op_add, _) -> fprintf fmtr "(%a) = %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Ebinop (_, Op_sub, _) -> fprintf fmtr "(%a) = %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Ebinop (_, Op_mul, _) -> fprintf fmtr "(%a) = %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Ebinop (_, Op_div, _) -> fprintf fmtr "(%a) = %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Eunop (Op_minus, _) -> fprintf fmtr "(%a) = %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| _ -> fprintf fmtr "(%a) = (%a)" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
end
| Eunop (Op_not, _) ->
begin
match rexpr_inside_strip with
| Ebinop (_, Op_add, _) -> fprintf fmtr "(%a) = %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Ebinop (_, Op_sub, _) -> fprintf fmtr "(%a) = %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Ebinop (_, Op_mul, _) -> fprintf fmtr "(%a) = %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Ebinop (_, Op_div, _) -> fprintf fmtr "(%a) = %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Eunop (Op_minus, _) -> fprintf fmtr "(%a) = %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| _ -> fprintf fmtr "(%a) = (%a)" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
end
| _ ->
begin
match rexpr_inside_strip with
| Ebinop (_, Op_add, _) -> fprintf fmtr "%a = %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Ebinop (_, Op_sub, _) -> fprintf fmtr "%a = %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Ebinop (_, Op_mul, _) -> fprintf fmtr "%a = %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Ebinop (_, Op_div, _) -> fprintf fmtr "%a = %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Eunop (Op_minus, _) -> fprintf fmtr "%a = %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| _ -> fprintf fmtr "%a = (%a)" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
end
end
| (Eparen lexpr_inside, rexpr) ->
begin
let
lexpr_inside_strip = strip_paren lexpr_inside
in
match lexpr_inside_strip with
| Ebinop (_, Op_or, _) -> fprintf fmtr "(%a) = %a" print_expr lexpr_inside_strip print_expr rexpr
| Ebinop (_, Op_and, _) -> fprintf fmtr "(%a) = %a" print_expr lexpr_inside_strip print_expr rexpr
| Eunop (Op_not, _) -> fprintf fmtr "(%a) = %a" print_expr lexpr_inside_strip print_expr rexpr
| _ -> fprintf fmtr "%a = %a" print_expr lexpr_inside_strip print_expr rexpr
end
| (lexpr, Eparen rexpr_inside) ->
begin
let
rexpr_inside_strip = strip_paren rexpr_inside
in
match rexpr_inside_strip with
| Ebinop (_, Op_add, _) -> fprintf fmtr "%a = %a" print_expr lexpr print_expr rexpr_inside_strip
| Ebinop (_, Op_sub, _) -> fprintf fmtr "%a = %a" print_expr lexpr print_expr rexpr_inside_strip
| Ebinop (_, Op_mul, _) -> fprintf fmtr "%a = %a" print_expr lexpr print_expr rexpr_inside_strip
| Ebinop (_, Op_div, _) -> fprintf fmtr "%a = %a" print_expr lexpr print_expr rexpr_inside_strip
| Eunop (Op_minus, _) -> fprintf fmtr "%a = %a" print_expr lexpr print_expr rexpr_inside_strip
| _ -> fprintf fmtr "%a = (%a)" print_expr lexpr print_expr rexpr_inside_strip
end
| (lexpr, rexpr) -> fprintf fmtr "%a = %a" print_expr lexpr print_expr rexpr
and print_ne_expr fmtr = function
| (Eparen lexpr_inside, Eparen rexpr_inside) ->
begin
let
lexpr_inside_strip = strip_paren lexpr_inside
and
rexpr_inside_strip = strip_paren rexpr_inside
in
match lexpr_inside_strip with
| Ebinop (_, Op_and, _) ->
begin
match rexpr_inside_strip with
| Ebinop (_, Op_add, _) -> fprintf fmtr "(%a) != %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Ebinop (_, Op_sub, _) -> fprintf fmtr "(%a) != %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Ebinop (_, Op_mul, _) -> fprintf fmtr "(%a) != %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Ebinop (_, Op_div, _) -> fprintf fmtr "(%a) != %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Eunop (Op_minus, _) -> fprintf fmtr "(%a) != %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| _ -> fprintf fmtr "(%a) != (%a)" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
end
| Ebinop (_, Op_or, _) ->
begin
match rexpr_inside_strip with
| Ebinop (_, Op_add, _) -> fprintf fmtr "(%a) != %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Ebinop (_, Op_sub, _) -> fprintf fmtr "(%a) != %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Ebinop (_, Op_mul, _) -> fprintf fmtr "(%a) != %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Ebinop (_, Op_div, _) -> fprintf fmtr "(%a) != %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Eunop (Op_minus, _) -> fprintf fmtr "(%a) != %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| _ -> fprintf fmtr "(%a) != (%a)" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
end
| Eunop (Op_not, _) ->
begin
match rexpr_inside_strip with
| Ebinop (_, Op_add, _) -> fprintf fmtr "(%a) != %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Ebinop (_, Op_sub, _) -> fprintf fmtr "(%a) != %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Ebinop (_, Op_mul, _) -> fprintf fmtr "(%a) != %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Ebinop (_, Op_div, _) -> fprintf fmtr "(%a) != %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Eunop (Op_minus, _) -> fprintf fmtr "(%a) != %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| _ -> fprintf fmtr "(%a) != (%a)" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
end
| _ ->
begin
match rexpr_inside_strip with
| Ebinop (_, Op_add, _) -> fprintf fmtr "%a != %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Ebinop (_, Op_sub, _) -> fprintf fmtr "%a != %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Ebinop (_, Op_mul, _) -> fprintf fmtr "%a != %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Ebinop (_, Op_div, _) -> fprintf fmtr "%a != %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Eunop (Op_minus, _) -> fprintf fmtr "%a != %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| _ -> fprintf fmtr "%a != (%a)" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
end
end
| (Eparen lexpr_inside, rexpr) ->
begin
let lexpr_inside_strip = strip_paren lexpr_inside
in match lexpr_inside_strip with
| Ebinop (_, Op_or, _) -> fprintf fmtr "(%a) != %a" print_expr lexpr_inside_strip print_expr rexpr
| Ebinop (_, Op_and, _) -> fprintf fmtr "(%a) != %a" print_expr lexpr_inside_strip print_expr rexpr
| Eunop (Op_not, _) -> fprintf fmtr "(%a) != %a" print_expr lexpr_inside_strip print_expr rexpr
| _ -> fprintf fmtr "%a != %a" print_expr lexpr_inside_strip print_expr rexpr
end
| (lexpr, Eparen rexpr_inside) ->
begin
let rexpr_inside_strip = strip_paren rexpr_inside
in match rexpr_inside_strip with
| Ebinop (_, Op_add, _) -> fprintf fmtr "%a != %a" print_expr lexpr print_expr rexpr_inside_strip
| Ebinop (_, Op_sub, _) -> fprintf fmtr "%a != %a" print_expr lexpr print_expr rexpr_inside_strip
| Ebinop (_, Op_mul, _) -> fprintf fmtr "%a != %a" print_expr lexpr print_expr rexpr_inside_strip
| Ebinop (_, Op_div, _) -> fprintf fmtr "%a != %a" print_expr lexpr print_expr rexpr_inside_strip
| Eunop (Op_minus, _) -> fprintf fmtr "%a != %a" print_expr lexpr print_expr rexpr_inside_strip
| _ -> fprintf fmtr "%a != (%a)" print_expr lexpr print_expr rexpr_inside_strip
end
| (lexpr, rexpr) -> fprintf fmtr "%a != %a" print_expr lexpr print_expr rexpr
and print_comp_expr fmtr (lexpr, comp, rexpr) =
let lexpr_strip = strip_paren lexpr and rexpr_strip = strip_paren rexpr
in fprintf fmtr "%a %s %a" print_expr lexpr_strip comp print_expr rexpr_strip
and print_and_expr fmtr = function
| (Eparen lexpr_inside, Eparen rexpr_inside) ->
begin
let lexpr_inside_strip = strip_paren lexpr_inside
and rexpr_inside_strip = strip_paren rexpr_inside
in match lexpr_inside_strip with
| Ebinop (_, Op_or, _) ->
begin
match rexpr_inside_strip with
| Ebinop (_, Op_and, _) -> fprintf fmtr "(%a) and (%a)" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Ebinop (_, Op_or, _) -> fprintf fmtr "(%a) and (%a)" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| _ -> fprintf fmtr "(%a) and %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
end
| _ ->
begin
match rexpr_inside_strip with
| Ebinop (_, Op_and, _) -> fprintf fmtr "%a and (%a)" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| Ebinop (_, Op_or, _) -> fprintf fmtr "%a and (%a)" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
| _ -> fprintf fmtr "%a and %a" print_expr lexpr_inside_strip print_expr rexpr_inside_strip
end
end
| (Eparen lexpr_inside, rexpr) ->
begin
let lexpr_inside_strip = strip_paren lexpr_inside
in match lexpr_inside_strip with
| Ebinop (_, Op_or, _) -> fprintf fmtr "(%a) and %a" print_expr lexpr_inside_strip print_expr rexpr
| _ -> fprintf fmtr "%a and %a" print_expr lexpr_inside_strip print_expr rexpr
end
| (lexpr, Eparen rexpr_inside) ->
begin
let rexpr_inside_strip = strip_paren rexpr_inside
in match rexpr_inside_strip with
| Ebinop (_, Op_and, _) -> fprintf fmtr "%a and (%a)" print_expr lexpr print_expr rexpr_inside_strip
| Ebinop (_, Op_or, _) -> fprintf fmtr "%a and (%a)" print_expr lexpr print_expr rexpr_inside_strip
| _ -> fprintf fmtr "%a and %a" print_expr lexpr print_expr rexpr_inside_strip
end
| (lexpr, rexpr) -> fprintf fmtr "%a and %a" print_expr lexpr print_expr rexpr
and print_or_expr fmtr = function
| (lexpr, Eparen rexpr_inside) ->
begin
let lexpr_strip = strip_paren lexpr
and rexpr_inside_strip = strip_paren rexpr_inside
in match rexpr_inside_strip with
| Ebinop (_, Op_or, _) -> fprintf fmtr "%a or (%a)" print_expr lexpr_strip print_expr rexpr_inside_strip
| _ -> fprintf fmtr "%a or %a" print_expr lexpr_strip print_expr rexpr_inside_strip
end
| (lexpr, rexpr) ->
let lexpr_strip = strip_paren lexpr
in fprintf fmtr "%a or %a" print_expr lexpr_strip print_expr rexpr
and print_not_expr fmtr = function
| Eparen expr_inside ->
begin
let expr_inside_strip = strip_paren expr_inside
in match expr_inside_strip with
| Ebinop (_, Op_and, _) -> fprintf fmtr "%s (%a)" "not" print_expr expr_inside_strip
| Ebinop (_, Op_or, _) -> fprintf fmtr "%s (%a)" "not" print_expr expr_inside_strip
| _ -> fprintf fmtr "%s %a" "not" print_expr expr_inside_strip
end
| expr -> fprintf fmtr "%s %a" "not" print_expr expr
and print_minus_expr fmtr = function
| Eparen expr_inside ->
begin
let expr_inside_strip = strip_paren expr_inside
in match expr_inside_strip with
| Eunop (Op_minus, _) -> fprintf fmtr "%s %a" "-" print_expr expr_inside_strip
| _ -> fprintf fmtr "%s (%a)" "-" print_expr expr_inside_strip
end
| expr -> fprintf fmtr "%s %a" "-" print_expr expr
and strip_paren expr = match expr with
| Eparen paren_expr -> strip_paren paren_expr
| _ -> expr