Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. {- Assignment 2 - Finite Automata (due November 11, noon)
  2.  
  3. Notes:
  4. - You may import Data.List; you may not import any other modules
  5.  
  6. ***Write the names and CDF accounts for each of your group members below.***
  7. <Name>, <CDF>
  8. <Name>, <CDF>
  9. -}
  10. module Dfa (State, Symbol, Transition, Automaton(..),
  11. allStrings, tableToDelta, extend, possibleOutcomes,
  12. accept, language,
  13. removeUseless, isFiniteLanguage, language') where
  14.  
  15. import Data.List
  16.  
  17. -- Basic data types
  18. type State = Integer
  19. type Symbol = Char
  20. type Transition = (State, Symbol, State)
  21.  
  22. -- Automaton Data Type
  23. -- Automaton states alphabet transitions initial final
  24. data Automaton = Automaton [State] [Symbol] [Transition] State [State]
  25. -- Some helper functions for you to access the different automaton components
  26. states :: Automaton -> [State]
  27. states (Automaton s _ _ _ _) = s
  28. alphabet :: Automaton -> [Symbol]
  29. alphabet (Automaton _ a _ _ _) = a
  30. transitions :: Automaton -> [Transition]
  31. transitions (Automaton _ _ ts _ _) = ts
  32. initial :: Automaton -> State
  33. initial (Automaton _ _ _ i _) = i
  34. final :: Automaton -> [State]
  35. final (Automaton _ _ _ _ f) = f
  36.  
  37.  
  38. -- Questions 1-4: transitions
  39. tableToDelta :: [Transition] -> State -> Symbol -> [State]
  40. tableToDelta ((tr_s,tr_a,tr_next_s):xs) s a =
  41. if length xs > 0 then
  42. if (s == tr_s) && (a == tr_a) then
  43. (head [tr_next_s]):(tableToDelta xs s a)
  44. else
  45. tableToDelta xs s a
  46. else
  47. if (s == tr_s) && (a == tr_a) then
  48. [(head [tr_next_s])]
  49. else
  50. []
  51.  
  52. extend :: (State -> Symbol -> [State]) -> (State -> String -> [State])
  53. extend f a (x_a:xs_a) =
  54. let f1 = f a x_a in
  55. if length xs_a > 0 then
  56. extend f (head f1) xs_a
  57. else
  58. f1
  59.  
  60. --allStrings :: [Symbol] -> [[String]]
  61. allStrings = undefined
  62.  
  63.  
  64.  
  65. allStrings_private_n1 a =
  66. if length (tail a) > 0 then
  67. [head a] : allStrings_private_n1 (tail a)
  68. else
  69. [[head a]]
  70.  
  71. allStrings_private_n2 a =
  72. if length (tail a) > 0 then
  73. ((head a) : (head (allStrings_private_n1 a))) : allStrings_private_n2 (head $ tail $ allStrings_private_n1 a)
  74. else
  75. [head a : (head $ allStrings_private_n1 a)]
  76.  
  77.  
  78. possibleOutcomes :: Automaton -> State -> [[(String, [State])]]
  79. possibleOutcomes = undefined
  80.  
  81.  
  82. -- Questions 5-6: acceptance
  83. accept :: Automaton -> String -> Bool
  84. accept = undefined
  85.  
  86. language :: Automaton -> [String]
  87. language = undefined
  88.  
  89.  
  90. -- Questions 7-9: finiteness
  91. removeUseless :: Automaton -> Automaton
  92. removeUseless = undefined
  93.  
  94. isFiniteLanguage :: Automaton -> Bool
  95. isFiniteLanguage = undefined
  96.  
  97. language' :: Automaton -> [String]
  98. language' = undefined
  99.  
  100.  
  101. -- Question 10: epsilon transitions
  102. epsilonClosure :: Automaton -> [State] -> [State]
  103. epsilonClosure = undefined
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement