-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test.hs
38 lines (33 loc) · 1.57 KB
/
Test.hs
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
import Data.Automaton.DFA (DFA)
import qualified Data.Automaton.DFA as DFA
import Data.Automaton.IntDFA (IntDFA)
import qualified Data.Automaton.IntDFA as IDFA
import Data.Automaton.TiedDFA (TiedDFA)
import qualified Data.Automaton.TiedDFA as TDFA
import Data.Automaton.NFA (NFA, Input(..))
import qualified Data.Automaton.NFA as NFA
-- Test DFAs that match 1*(0(1*)0(1*))*
dfa :: DFA Int Char
dfa = DFA.trans (2,DFA.Symbol '0',1) . DFA.trans (2,DFA.Symbol '1',2) .
DFA.trans (1,DFA.Symbol '0',2) . DFA.trans (1,DFA.Symbol '1',1) .
DFA.final 1 $ DFA.unit 1
dfa2 :: IntDFA Char
dfa2 = IDFA.trans (2,IDFA.Symbol '0',1) . IDFA.trans (2,IDFA.Symbol '1',2) .
IDFA.trans (1,IDFA.Symbol '0',2) . IDFA.trans (1,IDFA.Symbol '1',1) .
IDFA.final 1 $ IDFA.unit 1
dfa3 :: TiedDFA Char
dfa3 = s1
where s1 = TDFA.trans '0' s2 . TDFA.trans '1' s1 $ TDFA.unit True
s2 = TDFA.trans '0' s1 . TDFA.trans '1' s2 $ TDFA.unit False
-- Test NFA, matches (1*(01*01*)*) U (0*(10*10*)*)
-- Meaning, matches strings (containing only zeros and ones)
-- if the number of ones is even, or the number of zeros is.
nfa :: NFA Int Char
nfa = NFA.trans (1, NFA.Symbol '1', 1) . NFA.trans (1, NFA.Symbol '0', 2) .
NFA.trans (2, NFA.Symbol '1', 2) . NFA.trans (2, NFA.Symbol '0', 1) .
NFA.trans (3, NFA.Symbol '0', 3) . NFA.trans (3, NFA.Symbol '1', 4) .
NFA.trans (4, NFA.Symbol '0', 4) . NFA.trans (4, NFA.Symbol '1', 3) .
NFA.trans (0, NFA.Epsilon, 1) . NFA.trans (0, NFA.Epsilon, 3) .
NFA.final 1 . NFA.final 3 $ NFA.unit 0
main :: IO ()
main = print $ NFA.determinize nfa