-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTM.hs
More file actions
40 lines (34 loc) · 1.34 KB
/
TM.hs
File metadata and controls
40 lines (34 loc) · 1.34 KB
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
{-|
Module : TM
Description : Runs an example Turing Machine which results in "dotTM.txt"
Maintainer : Jade Kessinger
-}
module TM where
import TMAST
import TMSimulate
import TMDotVisualization
import System.IO
import Control.Monad
import Data.Map (Map)
import qualified Data.Map as Map
machine = Machine {
config = Config Tape {left = ["0", "1", "0", "1", "1"],
right = [],
tapeHead = "_"} "0",
states = Map.fromList [
("0", Map.fromList [
("0", Transition {write = "0", move = Lt, goto = "Halt"}),
("1", Transition {write = "1", move = Rt, goto = "Halt"}),
("_", Transition {write = "_", move = Lt, goto = "1"})]),
("1", Map.fromList [
("0", Transition {write = "1", move = Lt, goto = "1"}),
("1", Transition {write = "0", move = Lt, goto = "1"}),
("_", Transition {write = "_", move = Rt, goto = "2"})]),
("2", Map.fromList [
("0", Transition {write = "0", move = Rt, goto = "2"}),
("1", Transition {write = "1", move = Rt, goto = "2"}),
("_", Transition {write = "_", move = Rt, goto = "Halt"})])]}
resultConfig = simulate machine
resultString = stringFormat resultConfig
dotString = formatAsDotProgram machine
makeDotFile = writeFile "dotTM.txt" dotString