annotate agda/regex1.agda @ 36:9558d870e8ae

add cfg and derive
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 28 Nov 2018 21:15:49 +0900
parents 95f2e129cf9e
children a7f09c9a2c7a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
34
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
1 module regex1 where
0
e5aa1cf746cb automaton lecture
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
e5aa1cf746cb automaton lecture
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 open import Level renaming ( suc to succ ; zero to Zero )
34
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
4 open import Data.Fin
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
5 open import Data.Nat hiding ( _≟_ )
36
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
6 open import Data.List hiding ( any )
34
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
7 open import Data.Bool using ( Bool ; true ; false ; _∧_ ; _∨_ )
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
8 open import Relation.Binary.PropositionalEquality as RBF hiding ( [_] )
1
3c6de7cf2a95 nfa worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
9 open import Relation.Nullary using (¬_; Dec; yes; no)
3c6de7cf2a95 nfa worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
10
0
e5aa1cf746cb automaton lecture
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
e5aa1cf746cb automaton lecture
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 data Regex ( Σ : Set ) : Set where
e5aa1cf746cb automaton lecture
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 _* : Regex Σ → Regex Σ
e5aa1cf746cb automaton lecture
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 _&_ : Regex Σ → Regex Σ → Regex Σ
34
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
15 _||_ : Regex Σ → Regex Σ → Regex Σ
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
16 <_> : Σ → Regex Σ
1
3c6de7cf2a95 nfa worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
17
36
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
18 -- postulate a b c d : Set
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
19
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
20 data hoge : Set where
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
21 a : hoge
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
22 b : hoge
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
23 c : hoge
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
24 d : hoge
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
25
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
26 infixr 40 _&_ _||_
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
27
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
28 r1' = (< a > & < b >) & < c >
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
29 r1 = < a > & < b > & < c >
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
30 any = < a > || < b > || < c >
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
31 r2 = ( any * ) & ( < a > & < b > & < c > )
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
32 r3 = ( any * ) & ( < a > & < b > & < c > & < a > & < b > & < c > )
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
33 r4 = ( < a > & < b > & < c > ) || ( < b > & < c > & < d > )
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
34 r5 = ( any * ) & ( < a > & < b > & < c > || < b > & < c > & < d > )
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
35
34
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
36 open import nfa
1
3c6de7cf2a95 nfa worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
37
34
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
38 _‖_ : {Σ : Set} ( x y : List Σ → Bool) → List Σ → Bool
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
39 x ‖ y = λ s → x s ∨ y s
7
f1fbe6603066 εAutomaton using Tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
40
f1fbe6603066 εAutomaton using Tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
41
34
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
42 split : {Σ : Set} → (List Σ → Bool)
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
43 → ( List Σ → Bool) → List Σ → Bool
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
44 split x y [] = x [] ∧ y []
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
45 split x y (h ∷ t) = (x [] ∧ y (h ∷ t)) ∨
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
46 split (λ t1 → x ( ( h ∷ [] ) ++ t1 )) (λ t2 → y t2 ) t
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
47
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
48 _・_ : {Σ : Set} → ( x y : List Σ → Bool) → List Σ → Bool
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
49 x ・ y = λ z → split x y z
7
f1fbe6603066 εAutomaton using Tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
50
34
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
51 {-# TERMINATING #-}
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
52 repeat : {Σ : Set} → (List Σ → Bool) → List Σ → Bool
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
53 repeat x [] = true
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
54 repeat {Σ} x ( h ∷ t ) = split x (repeat {Σ} x) ( h ∷ t )
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
55
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
56 open FiniteSet
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
57
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
58 cmpi : {Σ : Set} → {n : ℕ } (fin : FiniteSet Σ {n}) → (x y : Σ ) → Dec (F←Q fin x ≡ F←Q fin y)
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
59 cmpi fin x y = F←Q fin x ≟ F←Q fin y
4
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
60
34
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
61 regular-language : {Σ : Set} → Regex Σ → {n : ℕ } (fin : FiniteSet Σ {n}) → List Σ → Bool
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
62 regular-language (x *) f = repeat ( regular-language x f )
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
63 regular-language (x & y) f = ( regular-language x f ) ・ ( regular-language y f )
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
64 regular-language (x || y) f = ( regular-language x f ) ‖ ( regular-language y f )
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
65 regular-language < h > f [] = false
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
66 regular-language < h > f (h1 ∷ [] ) with cmpi f h h1
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
67 ... | yes _ = true
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
68 ... | no _ = false
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
69 regular-language < h > f _ = false
1
3c6de7cf2a95 nfa worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
70
34
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
71 finIn2 : FiniteSet In2
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
72 finIn2 = record {
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
73 Q←F = Q←F'
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
74 ; F←Q = F←Q'
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
75 ; finiso→ = finiso→'
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
76 ; finiso← = finiso←'
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
77 } where
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
78 Q←F' : Fin 2 → In2
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
79 Q←F' zero = i0
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
80 Q←F' (suc zero) = i1
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
81 Q←F' (suc (suc ()))
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
82 F←Q' : In2 → Fin 2
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
83 F←Q' i0 = zero
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
84 F←Q' i1 = suc (zero)
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
85 finiso→' : (q : In2) → Q←F' (F←Q' q) ≡ q
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
86 finiso→' i0 = refl
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
87 finiso→' i1 = refl
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
88 finiso←' : (f : Fin 2) → F←Q' (Q←F' f) ≡ f
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
89 finiso←' zero = refl
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
90 finiso←' (suc zero) = refl
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
91 finiso←' (suc (suc ()))
11
8e66865fd9af fix sbconst
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
92
8e66865fd9af fix sbconst
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
93
34
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
94 test-r1 = < i0 > & < i1 >
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
95 test-r2 = regular-language (< i0 > & < i1 >) finIn2 ( i0 ∷ i1 ∷ [] )
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
96 test-r3 = regular-language (< i0 > & < i1 >) finIn2 ( i0 ∷ i0 ∷ [] )
1
3c6de7cf2a95 nfa worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
97
36
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
98 issub : {Σ : Set} {n : ℕ } → Regex Σ → Regex Σ → FiniteSet Σ {n} → Bool
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
99 issub (r *) s f = issub r s f
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
100 issub (r & r₁) s f = issub r s f ∨ issub r₁ s f
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
101 issub (r || r₁) s f = issub r s f ∨ issub r₁ s f
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
102 issub < x > < s > f with cmpi f x s
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
103 issub < x > < s > f | yes p = true
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
104 issub < x > < s > f | no ¬p = false
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
105 issub < x > s f = false
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
106
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
107 record RegexSub {Σ : Set} (R : Regex Σ) {n : ℕ } (fin : FiniteSet Σ {n} ): Set where
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
108 field
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
109 Subterm : Regex Σ
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
110 sub : issub R Subterm fin ≡ true
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
111
35
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
112 regex2nfa : {Σ : Set} → Regex Σ → {n : ℕ } (fin : FiniteSet Σ {n}) → NAutomaton (Regex Σ) Σ
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
113 regex2nfa {Σ} (r *) fin = record { Nδ = Nδ ; Nstart = Nstart ; Nend = Nend } where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
114 nr0 = regex2nfa r fin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
115 Nδ : (Regex Σ) → Σ → (Regex Σ) → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
116 Nδ s0 i s1 = NAutomaton.Nδ nr0 s0 i s1 ∨ ( NAutomaton.Nend nr0 s0 ∧ NAutomaton.Nδ nr0 s0 i s1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
117 Nstart : (Regex Σ) → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
118 Nstart s0 = NAutomaton.Nstart nr0 s0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
119 Nend : (Regex Σ) → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
120 Nend s0 = NAutomaton.Nend nr0 s0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
121 regex2nfa {Σ} (r0 & r1) fin = record { Nδ = Nδ ; Nstart = Nstart ; Nend = Nend } where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
122 nr0 = regex2nfa r0 fin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
123 nr1 = regex2nfa r1 fin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
124 Nδ : (Regex Σ) → Σ → (Regex Σ) → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
125 Nδ s0 i s1 = NAutomaton.Nδ nr0 s0 i s1 ∨ ( NAutomaton.Nend nr0 s0 ∧ NAutomaton.Nδ nr1 s0 i s1 )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
126 Nstart : (Regex Σ) → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
127 Nstart s0 = NAutomaton.Nstart nr0 s0 ∨ ( NAutomaton.Nend nr0 s0 ∧ NAutomaton.Nstart nr1 s0 )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
128 Nend : (Regex Σ) → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
129 Nend s0 = NAutomaton.Nend nr0 s0 ∨ ( NAutomaton.Nend nr0 s0 ∧ NAutomaton.Nend nr1 s0 )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
130 regex2nfa {Σ} (r0 || r1) fin = record { Nδ = Nδ ; Nstart = Nstart ; Nend = Nend } where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
131 nr0 = regex2nfa r0 fin
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
132 nr1 = regex2nfa r1 fin
34
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
133 Nδ : (Regex Σ) → Σ → (Regex Σ) → Bool
35
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
134 Nδ s0 i s1 = NAutomaton.Nδ nr0 s0 i s1 ∨ NAutomaton.Nδ nr1 s0 i s1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
135 Nstart : (Regex Σ) → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
136 Nstart s0 = NAutomaton.Nstart nr0 s0 ∨ NAutomaton.Nstart nr1 s0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
137 Nend : (Regex Σ) → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
138 Nend s0 = NAutomaton.Nend nr0 s0 ∨ NAutomaton.Nend nr1 s0
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
139 regex2nfa {Σ} < x > fin = record { Nδ = Nδ ; Nstart = Nstart ; Nend = Nend } where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
140 Nδ : (Regex Σ) → Σ → (Regex Σ) → Bool
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
141 Nδ r1 s r2 with cmpi fin s x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
142 Nδ r1 s r2 | yes _ = true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
143 Nδ r1 s r2 | no _ = false
34
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
144 Nstart : (Regex Σ) → Bool
35
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
145 Nstart < s > with cmpi fin s x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
146 ... | yes _ = true
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
147 ... | no _ = false
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
148 Nstart _ = false
34
a904b6bc76af add regular language
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 13
diff changeset
149 Nend : (Regex Σ) → Bool
35
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
150 Nend _ = false
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
151
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
152 test-r4 = regex2nfa (< i0 > & < i1 >) finIn2
8
cdf75ae6f0c1 add subset construction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
153
36
9558d870e8ae add cfg and derive
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 35
diff changeset
154 -- testr5 = Naccept test-r4 {!!} ( i0 ∷ i1 ∷ [] )
35
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
155
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
156
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
157
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 34
diff changeset
158