-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpart2.ml
71 lines (55 loc) · 1.77 KB
/
part2.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
open Regexp
open Dfa
open Test
module Part2 : DFA = struct
type 'a state = bool * ('a * bool) regexp
let rec cont_eps (reg : 'a regexp) =
match reg with
| Eps -> true
| Sym l -> false
| Alt(r1,r2) -> (cont_eps r1) || (cont_eps r2)
| Seq(r1,r2) -> (cont_eps r1) && (cont_eps r2)
| Rep(r1) -> true
let init reg =
let rec aux_init = function
| Eps -> Eps
| Sym a -> Sym (a,false)
| Alt(r1,r2) -> Alt(aux_init r1, aux_init r2)
| Seq(r1,r2) -> Seq(aux_init r1,aux_init r2)
| Rep(r1) -> Rep(aux_init r1)
in
(true,aux_init reg)
let final reg_st =
let rec aux = function
| Eps -> false
| Sym (l,b) -> b
| Alt(r1,r2) -> (aux r1) || (aux r2)
| Seq(r1,r2) -> (aux r2 ) || (cont_eps r2 && aux r1)
| Rep(r1) -> (aux r1)
in
((fst reg_st) && (cont_eps (snd reg_st))) || (aux (snd reg_st))
let next reg_st l =
let rec aux_next b = function
| Eps -> (Eps,b)
| Sym (lp,bp) ->
if b && lp == l then
(Sym (lp, true), bp)
else
(Sym (lp, false), bp)
| Alt(r1,r2) -> let (r12,b1) = aux_next b r1 in
let (r22,b2) = aux_next b r2 in
(Alt(r12,r22), b1 || b2)
| Seq(r1,r2) -> let (r12,b1) = aux_next b r1 in
let (r22,b2) = aux_next b1 r2 in
(Seq(r12,r22),b2)
| Rep(r1) -> let (r12,b1) = aux_next (final (b,Rep(r1))) r1 in
(Rep(r12),b1)
in
let (r,b) = aux_next (fst reg_st) (snd reg_st) in
(false, r)
end
(* UTILISATION DU MODULE ET DES FONCTEURS *)
module M2 = Acceptor.Make (Part2)
let accept2 e u = M2.accept e u
(* LANCEMENT DES TESTS -- NE PAS MODIFIER SOUS CETTE LIGNE *)
let () = test2 accept2