-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup.ml
1256 lines (1133 loc) · 60.6 KB
/
backup.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
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
type const = I of int | B of string | E of string | S of string | N of string | P of string
type dataType = Pushs of const| Pushi of const| Pushb of const| Pushn of const | Push of const |Add| Sub | Mul |
Div | Rem | Neg | Swap | Pop | Cat| And| Or| Not| Equal| LessThan| Bind| If| Let| End |Quit;;
let interpreter ( (input : string), (output : string )) : unit =
let invalidList = ['~';'!';'@';'#';'$';'%';'^';'&';'*';'(';')';'-';'+';'=';'\\';'|';'}';']';'{';'[';':';';';'\"';'<';'>';'/';'?';'\ ';',';'.'] in
let ic = open_in input in
let rec loop_read acc =
try
let l = input_line ic in
loop_read (l::acc)
with
| End_of_file -> List.rev acc in
(* let oc = open_out output in
let file_write string_val = Printf.fprintf oc "%s\n" string_val in *)
let ls_str = loop_read [] in
let rec convertFunction p: string list list =
match p with
[] -> [[]]
| hd::tl -> (String.split_on_char ' ' hd) :: convertFunction(tl)
in
let listOfList = convertFunction ls_str in
let strip_both_chars str =
match String.length str with
| 0 | 1 | 2 -> ""
| len -> String.sub str 1 (len - 2)
in
let strip_last_char str =
if str = "" then "" else
String.sub str 0 ((String.length str) - 1)
in
let rec listToString2 (p:string list) (y:string list): string list =
match p with
[] -> y
|hd::tl -> (match hd with
"pushs" -> listToString2 tl y
| "pushn" -> listToString2 tl y
|_-> listToString2 tl (hd::y)
)
in
let rec listToString3 (p:string list) (y:string) : string =
match p with
[]->y
|hd::tl -> listToString3 tl (hd^" "^y)
in
let substringCheck s1 s2 =
try
let len = String.length s2 in
for i = 0 to String.length s1 - len do
if String.sub s1 i len = s2 then raise Exit
done;
false
with Exit -> true
in
let rec validCheck (x:string) (y:int): bool=
if y = String.length(x) then true
else if String.get x y = '_' then
validCheck x (y+1)
else if String.get x y = 'a' || String.get x y = 'A' ||
String.get x y = 'b' || String.get x y = 'B'
|| String.get x y = 'c'|| String.get x y = 'C'
|| String.get x y = 'd'|| String.get x y = 'D'
|| String.get x y = 'e'|| String.get x y = 'E'
|| String.get x y = 'f'|| String.get x y = 'F'
|| String.get x y = 'g'|| String.get x y = 'G'
|| String.get x y = 'h'|| String.get x y = 'H'
|| String.get x y = 'i'|| String.get x y = 'I'
|| String.get x y = 'j'|| String.get x y = 'J'
|| String.get x y = 'k'|| String.get x y = 'K'
|| String.get x y = 'l'|| String.get x y = 'L'
|| String.get x y = 'm'|| String.get x y = 'M'
|| String.get x y = 'n'|| String.get x y = 'N'
|| String.get x y = 'o'|| String.get x y = 'O'
|| String.get x y = 'p'|| String.get x y = 'P'
|| String.get x y = 'q'|| String.get x y = 'Q'
|| String.get x y = 'r'|| String.get x y = 'R'
|| String.get x y = 's'|| String.get x y = 'S'
|| String.get x y = 't'|| String.get x y = 'T'
|| String.get x y = 'u'|| String.get x y = 'U'
|| String.get x y = 'v'|| String.get x y = 'V'
|| String.get x y = 'w'|| String.get x y = 'W'
|| String.get x y = 'x'|| String.get x y = 'X'
|| String.get x y = 'y'|| String.get x y = 'Y'
|| String.get x y = 'z'|| String.get x y = 'Z'
then true
else false
in
let rec invalidCharCheck (x:string): bool list=
List.map (fun ch -> String.contains x ch) invalidList
in
let rec invalidCharCheck2 (p:bool list): bool =
match p with
[]-> false
|hd::tl -> (match hd with
true->true
|false->invalidCharCheck2 tl
)
in
let rec convertType (p: string list list): dataType list =
match p with
[[]] -> []
| hd::tl -> (match hd with
| hd2::tl2::tl3 -> (match hd2 with
"pushi" -> (try
(Pushi (I (int_of_string tl2))::convertType tl)
with Failure _ -> Pushi (S (":error:"))::convertType tl)
|"pushn" ->
(if not (validCheck(strip_last_char(listToString3(listToString2 hd [])"")) 0) then Pushn (N (":error:"))::convertType tl
else if invalidCharCheck2(invalidCharCheck(strip_last_char(listToString3(listToString2 hd [])""))) then Pushn (N (":error:"))::convertType tl
else Pushn (N (tl2))::convertType tl)
|"pushs" ->
let lengthOfString = String.length((listToString3(listToString2 hd [])""))-2 in
(if not ((String.get((strip_last_char(listToString3(listToString2 hd [])"")))0) ='\"') then Pushs (S (":error:"))::convertType tl
else if not ((String.get((strip_last_char(listToString3(listToString2 hd [])"")))lengthOfString) ='\"') then Pushs (S (":error:"))::convertType tl
else Pushs (S (strip_last_char(strip_both_chars(listToString3(listToString2 hd [])""))))::convertType tl)
|"pushb" -> (if (String.get tl2 0 =':' && String.get tl2 ((String.length tl2)-1) =':'
&& (String.get tl2 1 ='t' || String.get tl2 1 ='f') &&
(String.get tl2 ((String.length tl2)-2) ='e' )&&
(substringCheck tl2 "true" = true || substringCheck tl2 "false" = true)) then Pushb (B (tl2))::convertType tl
else Pushb (S (":error:"))::convertType tl )
|"push" -> (if (String.get tl2 0 =':' && String.get tl2 ((String.length tl2)-1) =':'
&& (String.get tl2 1 ='u') &&
(String.get tl2 ((String.length tl2)-2) ='t')&&
(substringCheck tl2 "unit" = true)) then Pushb (P (tl2))::convertType tl
else Pushb (P (":error:"))::convertType tl )
|_-> []
)
|hd3::tl3 -> (match hd3 with
"pop" -> Pop ::convertType tl
| "add" -> Add ::convertType tl
| "swap"-> Swap::convertType tl
| "mul" -> Mul::convertType tl
| "div" -> Div::convertType tl
| "rem" -> Rem::convertType tl
| "neg" -> Neg::convertType tl
| "sub" -> Sub::convertType tl
| "quit" -> Quit::convertType tl
| "cat" -> Cat::convertType tl
| "and" -> And::convertType tl
| "or" -> Or::convertType tl
| "not" -> Not::convertType tl
| "equal" -> Equal::convertType tl
| "lessThan" ->LessThan::convertType tl
| "bind" -> Bind::convertType tl
| "if" -> If::convertType tl
| "let" -> Let::convertType tl
| "end" -> End::convertType tl
|_->[]
)
|_->[]
)
|_-> []
in
let inputList = convertType listOfList in
let rec bindFunction (a:(string * const) list) (b:string) (c:string) (d:'a list): 'a list =
match a with
hd::tl -> (match hd with
(ht,tl2)->
if ht = b || ht =c then bindFunction tl b c (tl2::d)
else bindFunction tl b c d
)
|[]-> d
in
let rec bindFunction2 (a:(string * const) list) (b:string): const =
match a with
hd::tl -> (match hd with
(ht,tl2)-> if ht = b then tl2 else bindFunction2 tl b )
|[]-> S(":error:")
in
let rec boolFunction (a:(string*const) list) (b:string) : string =
match a with
hd::tl -> (match hd with
(ht,tl2)-> (match ht,tl2 with
ht, B a -> if ht = b && (a =":true:" || a =":false:") then a
else boolFunction tl b
|_-> boolFunction tl b
))
|[]->""
in
let rec remFunction (a:(string*const) list) (b:string) : int =
match a with
hd::tl -> (match hd with
(ht,tl2) -> (match ht,tl2 with
ht,I a-> if ht = b then a else remFunction tl b
|_-> remFunction tl b
))
|[]-> 0
in
let rec checkDup (a:string) (b:(string * const) list): bool =
match b with
hd::tl -> (match hd with
(ht,tl2)-> if ht = a then true else checkDup a tl
)
|[]-> false
in
let rec overwriteFunction (a:string) (b:(string * const) list) (c:const): (string * const) list =
match b with
hd::tl -> (match hd with
(ht,tl2)-> if ht = a then (ht,c)::tl else overwriteFunction a tl c )
|[]-> b
in
let rec overwriteFunction2 (a:string) (b:(string * const) list) (c:string): (string * const) list =
match b with
hd::tl -> (match hd with
(ht,tl2)-> if ht = a then ((c,tl2)::b) else overwriteFunction2 a tl c
)
|[] -> b
in
let rec combineValue (a:string) (b:(string * const) list) (c:int): int =
match b with
hd::tl -> (match hd with
(ht,tl2)-> (match (ht,tl2) with
(aa, I b) -> if aa = a then b+c else combineValue a tl c
|_->combineValue a tl c
))
|[]-> c
in
let rec minusValue (a:string) (b:(string * const) list): int =
match b with
hd::tl->(match hd with
(ht,tl2) -> (match (ht,tl2)with
(aa, I b) -> if aa = a then b else minusValue a tl
|_-> minusValue a tl
))
|[]-> 0
in
let rec printTuple (p:(string * const)list): string =
match p with
hd::tl -> (match hd with
(h,t) -> (match h,t with
h, I a -> print_endline (h^" value: "^string_of_int a); printTuple tl
|h, S a -> print_endline (h^" value: "^ a); printTuple tl
|h, N a -> print_endline (h^" value: "^ a); printTuple tl
|h, P a -> print_endline (h^" value: "^ a); printTuple tl
|h, B a -> print_endline (h^" value: "^ a); printTuple tl
|_-> printTuple tl
))
|[]-> " "
in
let rec mainFunction2 (x:dataType list) (y:const list) (z:(string * const) list) : (const option)*(dataType list)=
match x with
[] -> (None,x)
| hd::tl -> (match hd with
Pushi i-> mainFunction2 tl (i::y) z
| Pushb b-> mainFunction2 tl (b::y) z
| Pushn n -> mainFunction2 tl (n::y) z
| Pushs s-> mainFunction2 tl (s::y) z
| Push p-> (match p with
P a -> mainFunction2 tl (P(a)::y) z
|_-> mainFunction2 tl (S(":error:")::y) z
)
| Pop -> (match y with
| [] -> mainFunction2 tl (S(":error:")::y) z
| hd2::tl222 -> mainFunction2 tl tl222 z
)
| Add ->
(match y with
hd3::tl3::tl4-> (match (hd3,tl3) with
(N x, N y2) -> let temp = (bindFunction z x y2 []) in
if List.length(temp) = 2 then (match temp with
hd44::hd55::tl55 -> (match(hd44,hd55) with
(I a, I b) -> mainFunction2 tl ((I (a+b))::tl4) z
|_-> mainFunction2 tl y z
)
|_-> mainFunction2 tl y z
) else if List.length(temp) = 1 then (match temp with
hd44::tl55 -> (match hd44 with
I a -> mainFunction2 tl (I(a + a)::tl4) z
|_-> mainFunction2 tl y z
)
|_-> mainFunction2 tl y z
)
else (match (hd3,tl3) with
(I a, I b) ->mainFunction2 tl ((I (a+b))::tl4) z
| _-> mainFunction2 tl ((S(":error:"))::y) z
)
| I a, N b -> if checkDup b z then (mainFunction2 tl (I(combineValue b z a)::tl4)z)
else mainFunction2 tl ((S(":error:"))::y) z
| N a, I b -> if checkDup a z then (mainFunction2 tl (I(combineValue a z b)::tl4)z)
else mainFunction2 tl ((S(":error:")::y))z
| I a, I b ->mainFunction2 tl ((I (a+b))::tl4) z
| _-> mainFunction2 tl ((S(":error:"))::y) z
)
| hd4::tl5 -> mainFunction2 tl (S(":error:")::y) z
|_-> mainFunction2 tl (S(":error:")::y) z
)
| Sub ->
(match y with
hd3::tl3::tl4-> (match (hd3,tl3) with
(N x, N y2) -> let temp = (bindFunction z x y2 []) in
if List.length(temp) = 2 then (match (minusValue x z), (minusValue y2 z) with
a, b -> mainFunction2 tl(I(b-a)::tl4) z
) else if List.length(temp) = 1 then (match temp with
hd44::tl55 -> (match hd44 with
I a -> mainFunction2 tl (I(a - a)::tl4) z
|_-> mainFunction2 tl y z
)
|_-> mainFunction2 tl y z
)
else (match (hd3,tl3) with
(I a, I b) ->mainFunction2 tl ((I (b-a))::tl4) z
| _-> mainFunction2 tl ((S(":error:"))::y) z)
| I a, N b -> if checkDup b z && minusValue b z != 0 then (mainFunction2 tl (I((minusValue b z)-a)::tl4)z)
else mainFunction2 tl ((S(":error:"))::y) z
| N a, I b -> if checkDup a z && minusValue a z != 0 then (mainFunction2 tl (I(b-(minusValue a z))::tl4)z)
else mainFunction2 tl ((S(":error:"))::y) z
| I a, I b ->mainFunction2 tl ((I (b-a))::tl4) z
| _-> mainFunction2 tl ((S(":error:"))::y) z
)
| hd4::tl5 -> mainFunction2 tl (S(":error:")::y) z
|_-> mainFunction2 tl (S(":error:")::y) z
)
| Mul -> (match y with
hd3::tl3::tl4-> (match (hd3,tl3) with
(N x, N y2) -> let temp = (bindFunction z x y2 []) in
if List.length(temp) = 2 then (match temp with
hd44::hd55::tl55 -> (match(hd44,hd55) with
(I a, I b) -> mainFunction2 tl ((I (a*b))::tl4) z
|_-> mainFunction2 tl y z
)
|_-> mainFunction2 tl y z
) else if List.length(temp) = 1 then (match temp with
hd44::tl55 -> (match hd44 with
I a -> mainFunction2 tl (I(a * a)::tl4) z
|_-> mainFunction2 tl y z
)
|_-> mainFunction2 tl y z
)
else (match (hd3,tl3) with
(I a, I b) ->mainFunction2 tl ((I (a*b))::tl4) z
| _-> mainFunction2 tl ((S(":error:"))::y) z
)
| I a, N b -> if checkDup b z then (mainFunction2 tl (I((minusValue b z)*a)::tl4)z)
else mainFunction2 tl ((S(":error:"))::y) z
| N a, I b -> if checkDup a z then (mainFunction2 tl (I((minusValue a z)*b)::tl4)z)
else mainFunction2 tl ((S(":error:"))::y) z
| I a, I b ->mainFunction2 tl ((I (a*b))::tl4) z
| _-> mainFunction2 tl ((S(":error:"))::y) z
)
| hd4::tl5 -> mainFunction2 tl (S(":error:")::y) z
|_-> mainFunction2 tl (S(":error:")::y) z
)
| Div ->
(match y with
hd3::tl3::tl4-> (match (hd3,tl3) with
(N x, N y2) -> let temp = (bindFunction z x y2 []) in
if List.length(temp) = 2 then (match minusValue x z, minusValue y2 z with
a, b ->( try mainFunction2 tl ((I (b/a))::tl4) z with Division_by_zero -> mainFunction2 tl ((S(":error:"))::y) z)
) else if List.length(temp) = 1 then (match temp with
hd44::tl55 -> (match hd44 with
I a -> mainFunction2 tl (I(a / a)::tl4) z
|_-> mainFunction2 tl y z
)
|_-> mainFunction2 tl y z
) else (match (hd3,tl3) with
(I a, I b) ->( try mainFunction2 tl ((I (b/a))::tl4) z with Division_by_zero -> mainFunction2 tl ((S(":error:"))::y) z)
| _-> mainFunction2 tl ((S(":error:"))::y) z)
| I a, N b -> if checkDup b z then (try (mainFunction2 tl (I((minusValue b z)/a)::tl4)z) with Division_by_zero -> mainFunction2 tl ((S(":error:"))::y) z)
else mainFunction2 tl ((S(":error:"))::y) z
| N a, I b -> if checkDup a z then (try (mainFunction2 tl (I(b/(minusValue a z))::tl4)z) with Division_by_zero -> mainFunction2 tl ((S(":error:"))::y) z)
else mainFunction2 tl ((S(":error:"))::y) z
| I a, I b ->( try mainFunction2 tl ((I (b/a))::tl4) z with Division_by_zero -> mainFunction2 tl ((S(":error:"))::y) z)
| _-> mainFunction2 tl ((S(":error:"))::y) z
)
| hd4::tl5 -> mainFunction2 tl (S(":error:")::y) z
|_-> mainFunction2 tl (S(":error:")::y) z
)
| Rem ->
(match y with
hd31::tl31::tl41-> (match hd31,tl31 with
I a, I b -> (try mainFunction2 tl ((I (b mod a))::tl41) z with
Division_by_zero -> mainFunction2 tl ((S(":error:"))::y) z)
| I a, N b -> (try mainFunction2 tl ((I ((remFunction z b) mod a))::tl41) z with
Division_by_zero -> mainFunction2 tl ((S(":error:"))::y) z)
| N a, I b -> (try mainFunction2 tl ((I (b mod (remFunction z a)))::tl41) z with
Division_by_zero -> mainFunction2 tl ((S(":error:"))::y) z)
| N a, N b -> if List.length(bindFunction z a b []) = 2 then (match minusValue a z, minusValue b z with
a, b -> (try mainFunction2 tl ((I (b mod a))::tl41) z with
Division_by_zero -> mainFunction2 tl ((S(":error:"))::y) z))
else mainFunction2 tl ((S(":error:"))::y) z
| _-> mainFunction2 tl ((S(":error:"))::y) z
)
| hd4::tl5 -> mainFunction2 tl (S(":error:")::y) z
|_->mainFunction2 tl (S(":error:")::y) z
)
| Neg -> (match y with
hd34::tl34 -> (match hd34 with
N a -> if (checkDup a z) then let temp = (bindFunction2 z a) in
(match temp with
I hd -> mainFunction2 tl (I(hd * -1)::tl34) z
|_-> mainFunction2 tl ((S(":error:"))::y) z)
else mainFunction2 tl ((S(":error:"))::y) z
|I a -> mainFunction2 tl (I(a * -1)::tl34) z
| _-> mainFunction2 tl ((S(":error:"))::y) z
)
|_->mainFunction2 tl (S(":error:")::y) z
)
| Swap -> (match y with
h::h2::t-> mainFunction2 tl (h2::h::t) z
|h3::t2-> mainFunction2 tl (S(":error:")::y) z
|_-> mainFunction2 tl (S(":error:")::y) z
)
| Cat ->
(match y with
hd3::tl3::tl4-> (match (hd3,tl3) with
N x, N y2 -> let temp = (bindFunction z x y2 []) in
if List.length(temp) = 2 then (match temp with
hd::hd2::tl5 -> (match hd, hd2 with
S a, S b -> mainFunction2 tl ((S (a^"" ^b))::tl4) z
|_->mainFunction2 tl ((S(":error:"))::y) z
)
|_->mainFunction2 tl ((S(":error:"))::y) z
) else (match (hd3,tl3) with
S a, S b ->mainFunction2 tl ((S (a^"" ^b))::tl4) z
| _-> mainFunction2 tl ((S(":error:"))::y) z
)
| S a, S b -> mainFunction2 tl (S (b^""^a)::tl4) z
| N a, S b -> (match bindFunction2 z a, b with
S a, b -> mainFunction2 tl (S (b^""^a)::tl4) z
|_->mainFunction2 tl ((S(":error:"))::y) z
)
| S a, N b -> (match a, bindFunction2 z b with
a, S b -> mainFunction2 tl (S(b^""^a)::tl4) z
|_-> mainFunction2 tl ((S(":error:"))::y) z
)
| _-> mainFunction2 tl ((S(":error:"))::y) z
)
| hd4::tl5 -> mainFunction2 tl (S(":error:")::y) z
|_-> mainFunction2 tl (S(":error:")::y) z
)
| And ->
(match y with
hd3::tl3::t-> (match (hd3,tl3) with
|N a, B b -> let temp2 = (bindFunction2 z a) in
(match temp2 with
B a -> if a = ":true:" && b =":true:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":false:" && b =":false:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":true:" && b =":false:" then mainFunction2 tl (B(":false:")::t) z
else if a = ":false:" && b =":true:" then mainFunction2 tl (B(":false:")::t) z
else mainFunction2 tl (S(":error:")::y) z
|_-> mainFunction2 tl (S(":error:")::y) z
)
|B a, N b -> let temp2 = (bindFunction2 z b) in
(match temp2 with
B b -> if a = ":true:" && b =":true:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":false:" && b =":false:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":true:" && b =":false:" then mainFunction2 tl (B(":false:")::t) z
else if a = ":false:" && b =":true:" then mainFunction2 tl (B(":false:")::t) z
else mainFunction2 tl (S(":error:")::y) z
|_-> mainFunction2 tl (S(":error:")::y) z
)
|B a, B b -> if a = ":true:" && b =":true:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":false:" && b =":false:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":true:" && b =":false:" then mainFunction2 tl (B(":false:")::t) z
else if a = ":false:" && b =":true:" then mainFunction2 tl (B(":false:")::t) z
else mainFunction2 tl (S(":error:")::y) z
|(N x, N y2) -> let temp = (bindFunction z x y2 []) in
if List.length(temp) = 2 then (match temp with
hd44::hd55::tl55 -> (match(hd44,hd55) with
(B a, B b) -> if a = ":true:" && b =":true:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":false:" && b =":false:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":true:" && b =":false:" then mainFunction2 tl (B(":false:")::t) z
else if a = ":false:" && b =":true:" then mainFunction2 tl (B(":false:")::t) z
else mainFunction2 tl (S(":error:")::y) z
|_-> mainFunction2 tl (S(":error:")::y) z
)
|_-> mainFunction2 tl y z) else if List.length(temp) = 1 then (match temp with
hd44::tl55 -> (match hd44 with
B a -> mainFunction2 tl (B(":true:")::t) z
|_-> mainFunction2 tl (S(":error:")::t) z
)
|_-> mainFunction2 tl (S(":error:")::t) z
) else (match y with
h::h2::t -> (match h,h2 with
B a, B b -> if a = ":true:" && b =":true:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":false:" && b =":false:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":true:" && b =":false:" then mainFunction2 tl (B(":false:")::t) z
else if a = ":false:" && b =":true:" then mainFunction2 tl (B(":false:")::t) z
else mainFunction2 tl (S(":error:")::y) z
|_-> mainFunction2 tl (S(":error:")::y) z
)
|h3::t2-> mainFunction2 tl (S(":error:")::y) z
|_-> mainFunction2 tl (S(":error:")::y) z
)
|_-> mainFunction2 tl (S(":error:")::y) z
)
|_-> mainFunction2 tl (S(":error:")::y) z)
| Or ->
(match y with
hd3::tl3::t-> (match (hd3,tl3) with
B a, B b -> if a = ":true:" && b =":false:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":false:" && b =":true:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":true:" && b =":true:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":false:" && b =":false:" then mainFunction2 tl (B(":false:")::t) z
else if a = ":true:" && (boolFunction z b) = ":true:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":true:" && (boolFunction z b) = ":false:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":false:" && (boolFunction z b) = ":true:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":false:" && (boolFunction z b) = ":false:" then mainFunction2 tl (B(":false:")::t) z
else if b = ":true:" && (boolFunction z a) = ":true:" then mainFunction2 tl (B(":true:")::t) z
else if b = ":true:" && (boolFunction z a) = ":false:" then mainFunction2 tl (B(":true:")::t) z
else if b = ":false:" && (boolFunction z a) = ":true:" then mainFunction2 tl (B(":true:")::t) z
else if b = ":false:" && (boolFunction z a) = ":false:" then mainFunction2 tl (B(":false:")::t) z
else mainFunction2 tl (S(":error:")::y) z
|N a, B b -> let temp2 = (bindFunction2 z a) in
(match temp2 with
B a -> if a = ":true:" && b =":false:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":false:" && b =":true:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":true:" && b =":true:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":false:" && b =":false:" then mainFunction2 tl (B(":false:")::t) z
else if a = ":true:" && (boolFunction z b) = ":true:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":true:" && (boolFunction z b) = ":false:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":false:" && (boolFunction z b) = ":true:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":false:" && (boolFunction z b) = ":false:" then mainFunction2 tl (B(":false:")::t) z
else if b = ":true:" && (boolFunction z a) = ":true:" then mainFunction2 tl (B(":true:")::t) z
else if b = ":true:" && (boolFunction z a) = ":false:" then mainFunction2 tl (B(":true:")::t) z
else if b = ":false:" && (boolFunction z a) = ":true:" then mainFunction2 tl (B(":true:")::t) z
else if b = ":false:" && (boolFunction z a) = ":false:" then mainFunction2 tl (B(":false:")::t) z
else mainFunction2 tl (S(":error:")::y) z
|_-> mainFunction2 tl (S(":error:")::y) z
)
|B a, N b ->
let temp2 = (bindFunction2 z b) in
(match temp2 with
B b -> if a = ":true:" && b =":false:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":false:" && b =":true:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":true:" && b =":true:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":false:" && b =":false:" then mainFunction2 tl (B(":false:")::t) z
else if a = ":true:" && (boolFunction z b) = ":true:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":true:" && (boolFunction z b) = ":false:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":false:" && (boolFunction z b) = ":true:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":false:" && (boolFunction z b) = ":false:" then mainFunction2 tl (B(":false:")::t) z
else if b = ":true:" && (boolFunction z a) = ":true:" then mainFunction2 tl (B(":true:")::t) z
else if b = ":true:" && (boolFunction z a) = ":false:" then mainFunction2 tl (B(":true:")::t) z
else if b = ":false:" && (boolFunction z a) = ":true:" then mainFunction2 tl (B(":true:")::t) z
else if b = ":false:" && (boolFunction z a) = ":false:" then mainFunction2 tl (B(":false:")::t) z
else mainFunction2 tl (S(":error:")::y) z
|_-> mainFunction2 tl (S(":error:")::y) z
)
|N x, N y2 -> let temp = (bindFunction z x y2 []) in
if List.length(temp) = 2 then (match temp with
hd44::hd55::tl55 -> (match(hd44,hd55) with
B a, B b -> if a = ":true:" && b =":false:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":false:" && b =":true:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":true:" && b =":true:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":false:" && b =":false:" then mainFunction2 tl (B(":false:")::t) z
else mainFunction2 tl (S(":error:")::y) z
|_-> mainFunction2 tl (S(":error:")::y) z
)
|_-> mainFunction2 tl y z) else if List.length(temp) = 1 then (match temp with
hd44::tl55 -> (match hd44 with
B a -> if a = ":false:" then mainFunction2 tl (B(":false:")::t) z else mainFunction2 tl (B(":true:")::t) z
|_-> mainFunction2 tl (S(":error:")::t) z
)
|_-> mainFunction2 tl (S(":error:")::t) z
) else (match y with
h::h2::t -> (match h,h2 with
B a, B b -> if a = ":true:" && b =":false:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":false:" && b =":true:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":true:" && b =":true:" then mainFunction2 tl (B(":true:")::t) z
else if a = ":false:" && b =":false:" then mainFunction2 tl (B(":false:")::t) z
else mainFunction2 tl (S(":error:")::y) z
|_-> mainFunction2 tl (S(":error:")::y) z
)
|h3::t2-> mainFunction2 tl (S(":error:")::y) z
|_-> mainFunction2 tl (S(":error:")::y) z
)
|_-> mainFunction2 tl (S(":error:")::y) z
)
|_-> mainFunction2 tl (S(":error:")::y) z)
| Not -> (match y with
h::t -> (match h with
B a -> if a =":true:" then mainFunction2 tl (B(":false:")::t) z
else if a =":false:" then mainFunction2 tl (B (":true:")::t) z
else mainFunction2 tl (S (":error:")::y) z
| N a -> if boolFunction z a = ":true:" then mainFunction2 tl (B(":false:")::t) z
else if boolFunction z a =":false:" then mainFunction2 tl (B (":true:")::t) z
else mainFunction2 tl (S (":error:")::y) z
|_-> mainFunction2 tl (S(":error:")::y) z
)
|_-> mainFunction2 tl (S(":error:")::y) z
)
| Equal -> (match y with
hd::hd2::t -> (match hd, hd2 with
I a, I b -> if a = b then mainFunction2 tl (B (":true:")::t) z else mainFunction2 tl (B(":false:")::t) z
|N a, N b -> if List.length(bindFunction z a b []) = 2 then (match bindFunction z a b [] with
hd::hd2::t -> (match hd, hd2 with
I a, I b -> if a = b then mainFunction2 tl (B (":true:")::t) z else mainFunction2 tl (B(":false:")::t) z
|_->mainFunction2 tl (S(":error:")::y) z
)
|_->mainFunction2 tl (S(":error:")::y) z
)else mainFunction2 tl (B(":false:")::t) z
|N a, I b -> (match (bindFunction2 z a), b with
I a, b -> if a = b then mainFunction2 tl (B (":true:")::t) z
else mainFunction2 tl (B (":false:")::t) z
|_->mainFunction2 tl (S(":error:")::y) z
)
|I a, N b -> (match (bindFunction2 z b), a with
I a, b -> if a = b then mainFunction2 tl (B (":true:")::t) z
else mainFunction2 tl (B (":false:")::t) z
|_->mainFunction2 tl (S(":error:")::y) z
)
|_->mainFunction2 tl (S(":error:")::y) z
)
|_->mainFunction2 tl (S(":error:")::y) z
)
| LessThan -> (match y with
hd::hd2::t -> (match hd,hd2 with
I a, I b -> if a > b then mainFunction2 tl (B (":true:")::t) z else mainFunction2 tl (B (":false:")::t) z
|N a, N b -> if List.length(bindFunction z a b []) = 2 then (match (bindFunction2 z a),(bindFunction2 z b) with
I a, I b -> if a > b then mainFunction2 tl (B (":true:")::t) z
else mainFunction2 tl (B (":false:")::t) z
|_-> mainFunction2 tl (S(":error:")::y) z
) else mainFunction2 tl (S(":error:")::y) z
|N a, I b -> (match (bindFunction2 z a), b with
I a, b -> if a > b then mainFunction2 tl (B (":true:")::t) z
else mainFunction2 tl (B (":false:")::t) z
|_->mainFunction2 tl (S(":error:")::y) z
)
|I a, N b -> (match (bindFunction2 z b), a with
I a, b -> if a < b then mainFunction2 tl (B (":true:")::t) z
else mainFunction2 tl (B (":false:")::t) z
|_->mainFunction2 tl (S(":error:")::y) z
)
|_->mainFunction2 tl (S(":error:")::y) z
)
|_->mainFunction2 tl (S(":error:")::y) z
)
| Bind -> (match y with
hd::hd2::t -> (match hd, hd2 with
I a, N b -> if checkDup b z then mainFunction2 tl (S(":unit:")::t)(overwriteFunction b z hd)
else mainFunction2 tl (S (":unit:")::t) ((b,I(a))::z)
| S a, N b -> if checkDup b z then mainFunction2 tl (S(":unit:")::t)(overwriteFunction b z hd)
else mainFunction2 tl (S (":unit:")::t) ((b,S(a))::z)
| N a, N b -> if checkDup b z then mainFunction2 tl (S(":unit:")::t)(overwriteFunction2 b z a)
else if bindFunction2 z a = S(":error:") then mainFunction2 tl (S(":error:")::y) z
else mainFunction2 tl (S (":unit:")::t) ((b,(bindFunction2 z a))::z)
| P a, N b -> if a=":error:" then mainFunction2 tl (S(":error:")::y) z
else if checkDup b z then mainFunction2 tl (S(":unit:")::t)(overwriteFunction b z hd)
else mainFunction2 tl (S(":unit:")::t) ((b,P(a))::z)
| B a, N b-> if checkDup b z then mainFunction2 tl (S(":unit:")::t)(overwriteFunction b z hd)
else mainFunction2 tl (S (":unit:")::t) ((b,B(a))::z)
|_->mainFunction2 tl (S(":error:")::y) z
)
|_->mainFunction2 tl (S(":error:")::y) z
)
| If -> (match y with
hd::hd2::hd3::t -> (match hd,hd2,hd3 with
hd, hd2, B a -> if a = ":true:" then mainFunction2 tl (hd::t) z
else if a = ":false:" then mainFunction2 tl (hd2::t) z
else mainFunction2 tl (S(":error:")::y) z
| N a, N b, N c -> if boolFunction z c = ":true:" then mainFunction2 tl ((bindFunction2 z a)::t) z
else if (boolFunction z c) = ":false:" then mainFunction2 tl ((bindFunction2 z b)::t) z
else mainFunction2 tl (S(":error:")::y) z
| N a, hd2, N c -> if boolFunction z c = ":true:" then mainFunction2 tl ((bindFunction2 z a)::t) z
else mainFunction2 tl (hd2::t) z
| hd, N a, N c -> if boolFunction z c = ":true:" then mainFunction2 tl ((hd::t)) z
else mainFunction2 tl ((bindFunction2 z a)::t) z
| hd, hd2, N a -> if boolFunction z a = ":true:" then mainFunction2 tl (hd::t) z
else if (boolFunction z a) = ":false:" then mainFunction2 tl (hd2::t) z
else mainFunction2 tl (S(":error:")::y) z
|_-> mainFunction2 tl (S(":error:")::y) z
)
|_-> mainFunction2 tl (S(":error:")::y) z
)
| Let -> (match mainFunction2 tl y z with
(Some const,x1)-> mainFunction2 x1 (const::y) z
| (None, x1)-> mainFunction2 x1 y z
)
| End -> (
match y with
[]-> (None,tl)
| hd1::tl1-> (Some hd1,tl)
)
|_-> mainFunction2 tl y z
)
in
(* -------------------------------------above is the mainFunction2 ---------------------------------------------*)
(* -------------------------------------above is the mainFunction2 ---------------------------------------------*)
(* -------------------------------------above is the mainFunction2 ---------------------------------------------*)
(* -------------------------------------above is the mainFunction2 ---------------------------------------------*)
(* -------------------------------------above is the mainFunction2 ---------------------------------------------*)
(* -------------------------------------above is the mainFunction2 ---------------------------------------------*)
(* -------------------------------------above is the mainFunction2 ---------------------------------------------*)
let rec mainFunction (x:dataType list) (y:const list) (z:(string * const) list) : const list =
match x with
[] -> y
| hd::tl -> (match hd with
Pushi i-> mainFunction tl (i::y) z
| Pushb b-> mainFunction tl (b::y) z
| Pushn n -> mainFunction tl (n::y) z
| Pushs s-> mainFunction tl (s::y) z
| Push p-> (match p with
P a -> mainFunction tl (P(a)::y) z
|_-> mainFunction tl (S(":error:")::y) z
)
| Pop -> (match y with
| [] -> mainFunction tl (S(":error:")::y) z
| hd2::tl222 -> mainFunction tl tl222 z
)
| Add ->
(match y with
hd3::tl3::tl4-> (match (hd3,tl3) with
(N x, N y2) -> let temp = (bindFunction z x y2 []) in
if List.length(temp) = 2 then (match temp with
hd44::hd55::tl55 -> (match(hd44,hd55) with
(I a, I b) -> mainFunction tl ((I (a+b))::tl4) z
|_-> mainFunction tl y z
)
|_-> mainFunction tl y z
) else if List.length(temp) = 1 then (match temp with
hd44::tl55 -> (match hd44 with
I a -> mainFunction tl (I(a + a)::tl4) z
|_-> mainFunction tl y z
)
|_-> mainFunction tl y z
)
else (match (hd3,tl3) with
(I a, I b) ->mainFunction tl ((I (a+b))::tl4) z
| _-> mainFunction tl ((S(":error:"))::y) z
)
| I a, N b -> if checkDup b z then (mainFunction tl (I(combineValue b z a)::tl4)z)
else mainFunction tl ((S(":error:"))::y) z
| N a, I b -> if checkDup a z then (mainFunction tl (I(combineValue a z b)::tl4)z)
else mainFunction tl ((S(":error:")::y))z
| I a, I b ->mainFunction tl ((I (a+b))::tl4) z
| _-> mainFunction tl ((S(":error:"))::y) z
)
| hd4::tl5 -> mainFunction tl (S(":error:")::y) z
|_-> mainFunction tl (S(":error:")::y) z
)
| Sub ->
(match y with
hd3::tl3::tl4-> (match (hd3,tl3) with
(N x, N y2) -> let temp = (bindFunction z x y2 []) in
if List.length(temp) = 2 then (match (minusValue x z), (minusValue y2 z) with
a, b -> mainFunction tl(I(b-a)::tl4) z
) else if List.length(temp) = 1 then (match temp with
hd44::tl55 -> (match hd44 with
I a -> mainFunction tl (I(a - a)::tl4) z
|_-> mainFunction tl y z
)
|_-> mainFunction tl y z
)
else (match (hd3,tl3) with
(I a, I b) ->mainFunction tl ((I (b-a))::tl4) z
| _-> mainFunction tl ((S(":error:"))::y) z)
| I a, N b -> if checkDup b z && minusValue b z != 0 then (mainFunction tl (I((minusValue b z)-a)::tl4)z)
else mainFunction tl ((S(":error:"))::y) z
| N a, I b -> if checkDup a z && minusValue a z != 0 then (mainFunction tl (I(b-(minusValue a z))::tl4)z)
else mainFunction tl ((S(":error:"))::y) z
| I a, I b ->mainFunction tl ((I (b-a))::tl4) z
| _-> mainFunction tl ((S(":error:"))::y) z
)
| hd4::tl5 -> mainFunction tl (S(":error:")::y) z
|_-> mainFunction tl (S(":error:")::y) z
)
| Mul -> (match y with
hd3::tl3::tl4-> (match (hd3,tl3) with
(N x, N y2) -> let temp = (bindFunction z x y2 []) in
if List.length(temp) = 2 then (match temp with
hd44::hd55::tl55 -> (match(hd44,hd55) with
(I a, I b) -> mainFunction tl ((I (a*b))::tl4) z
|_-> mainFunction tl y z
)
|_-> mainFunction tl y z
) else if List.length(temp) = 1 then (match temp with
hd44::tl55 -> (match hd44 with
I a -> mainFunction tl (I(a * a)::tl4) z
|_-> mainFunction tl y z
)
|_-> mainFunction tl y z
)
else (match (hd3,tl3) with
(I a, I b) ->mainFunction tl ((I (a*b))::tl4) z
| _-> mainFunction tl ((S(":error:"))::y) z
)
| I a, N b -> if checkDup b z then (mainFunction tl (I((minusValue b z)*a)::tl4)z)
else mainFunction tl ((S(":error:"))::y) z
| N a, I b -> if checkDup a z then (mainFunction tl (I((minusValue a z)*b)::tl4)z)
else mainFunction tl ((S(":error:"))::y) z
| I a, I b ->mainFunction tl ((I (a*b))::tl4) z
| _-> mainFunction tl ((S(":error:"))::y) z
)
| hd4::tl5 -> mainFunction tl (S(":error:")::y) z
|_-> mainFunction tl (S(":error:")::y) z
)
| Div ->
(match y with
hd3::tl3::tl4-> (match (hd3,tl3) with
(N x, N y2) -> let temp = (bindFunction z x y2 []) in
if List.length(temp) = 2 then (match minusValue x z, minusValue y2 z with
a, b ->( try mainFunction tl ((I (b/a))::tl4) z with Division_by_zero -> mainFunction tl ((S(":error:"))::y) z)
) else if List.length(temp) = 1 then (match temp with
hd44::tl55 -> (match hd44 with
I a -> mainFunction tl (I(a / a)::tl4) z
|_-> mainFunction tl y z
)
|_-> mainFunction tl y z
) else (match (hd3,tl3) with
(I a, I b) ->( try mainFunction tl ((I (b/a))::tl4) z with Division_by_zero -> mainFunction tl ((S(":error:"))::y) z)
| _-> mainFunction tl ((S(":error:"))::y) z)
| I a, N b -> if checkDup b z then (try (mainFunction tl (I((minusValue b z)/a)::tl4)z) with Division_by_zero -> mainFunction tl ((S(":error:"))::y) z)
else mainFunction tl ((S(":error:"))::y) z
| N a, I b -> if checkDup a z then (try (mainFunction tl (I(b/(minusValue a z))::tl4)z) with Division_by_zero -> mainFunction tl ((S(":error:"))::y) z)
else mainFunction tl ((S(":error:"))::y) z
| I a, I b ->( try mainFunction tl ((I (b/a))::tl4) z with Division_by_zero -> mainFunction tl ((S(":error:"))::y) z)
| _-> mainFunction tl ((S(":error:"))::y) z
)
| hd4::tl5 -> mainFunction tl (S(":error:")::y) z
|_-> mainFunction tl (S(":error:")::y) z
)
| Rem ->
(match y with
hd31::tl31::tl41-> (match hd31,tl31 with
I a, I b -> (try mainFunction tl ((I (b mod a))::tl41) z with
Division_by_zero -> mainFunction tl ((S(":error:"))::y) z)
| I a, N b -> (try mainFunction tl ((I ((remFunction z b) mod a))::tl41) z with
Division_by_zero -> mainFunction tl ((S(":error:"))::y) z)
| N a, I b -> (try mainFunction tl ((I (b mod (remFunction z a)))::tl41) z with
Division_by_zero -> mainFunction tl ((S(":error:"))::y) z)
| N a, N b -> if List.length(bindFunction z a b []) = 2 then (match minusValue a z, minusValue b z with
a, b -> (try mainFunction tl ((I (b mod a))::tl41) z with
Division_by_zero -> mainFunction tl ((S(":error:"))::y) z))
else mainFunction tl ((S(":error:"))::y) z
| _-> mainFunction tl ((S(":error:"))::y) z
)
| hd4::tl5 -> mainFunction tl (S(":error:")::y) z
|_->mainFunction tl (S(":error:")::y) z
)
| Neg -> (match y with
hd34::tl34 -> (match hd34 with
N a -> if (checkDup a z) then let temp = (bindFunction2 z a) in
(match temp with
I hd -> mainFunction tl (I(hd * -1)::tl34) z
|_-> mainFunction tl ((S(":error:"))::y) z)
else mainFunction tl ((S(":error:"))::y) z
|I a -> mainFunction tl (I(a * -1)::tl34) z
| _-> mainFunction tl ((S(":error:"))::y) z
)
|_->mainFunction tl (S(":error:")::y) z
)
| Swap -> (match y with
h::h2::t-> mainFunction tl (h2::h::t) z
|h3::t2-> mainFunction tl (S(":error:")::y) z
|_-> mainFunction tl (S(":error:")::y) z
)
| Cat ->
(match y with
hd3::tl3::tl4-> (match (hd3,tl3) with
N x, N y2 -> let temp = (bindFunction z x y2 []) in
if List.length(temp) = 2 then (match temp with
hd::hd2::tl5 -> (match hd, hd2 with
S a, S b -> mainFunction tl ((S (a^"" ^b))::tl4) z
|_->mainFunction tl ((S(":error:"))::y) z
)
|_->mainFunction tl ((S(":error:"))::y) z
) else (match (hd3,tl3) with
S a, S b ->mainFunction tl ((S (a^"" ^b))::tl4) z
| _-> mainFunction tl ((S(":error:"))::y) z
)
| S a, S b -> mainFunction tl (S (b^""^a)::tl4) z
| N a, S b -> (match bindFunction2 z a, b with
S a, b -> mainFunction tl (S (b^""^a)::tl4) z
|_->mainFunction tl ((S(":error:"))::y) z
)
| S a, N b -> (match a, bindFunction2 z b with
a, S b -> mainFunction tl (S(b^""^a)::tl4) z
|_-> mainFunction tl ((S(":error:"))::y) z
)
| _-> mainFunction tl ((S(":error:"))::y) z
)
| hd4::tl5 -> mainFunction tl (S(":error:")::y) z
|_-> mainFunction tl (S(":error:")::y) z
)
| And ->
(match y with
hd3::tl3::t-> (match (hd3,tl3) with
|N a, B b -> let temp2 = (bindFunction2 z a) in
(match temp2 with
B a -> if a = ":true:" && b =":true:" then mainFunction tl (B(":true:")::t) z
else if a = ":false:" && b =":false:" then mainFunction tl (B(":true:")::t) z
else if a = ":true:" && b =":false:" then mainFunction tl (B(":false:")::t) z
else if a = ":false:" && b =":true:" then mainFunction tl (B(":false:")::t) z
else mainFunction tl (S(":error:")::y) z
|_-> mainFunction tl (S(":error:")::y) z
)
|B a, N b -> let temp2 = (bindFunction2 z b) in
(match temp2 with
B b -> if a = ":true:" && b =":true:" then mainFunction tl (B(":true:")::t) z
else if a = ":false:" && b =":false:" then mainFunction tl (B(":true:")::t) z
else if a = ":true:" && b =":false:" then mainFunction tl (B(":false:")::t) z
else if a = ":false:" && b =":true:" then mainFunction tl (B(":false:")::t) z
else mainFunction tl (S(":error:")::y) z
|_-> mainFunction tl (S(":error:")::y) z
)
|B a, B b -> if a = ":true:" && b =":true:" then mainFunction tl (B(":true:")::t) z
else if a = ":false:" && b =":false:" then mainFunction tl (B(":true:")::t) z
else if a = ":true:" && b =":false:" then mainFunction tl (B(":false:")::t) z
else if a = ":false:" && b =":true:" then mainFunction tl (B(":false:")::t) z
else mainFunction tl (S(":error:")::y) z
|(N x, N y2) -> let temp = (bindFunction z x y2 []) in
if List.length(temp) = 2 then (match temp with
hd44::hd55::tl55 -> (match(hd44,hd55) with
(B a, B b) -> if a = ":true:" && b =":true:" then mainFunction tl (B(":true:")::t) z