{-# LANGUAGE TupleSections #-}
module TMInterpreter where
import TMType
import ConfigType
import qualified Data.Set as Set
import Helpers
import Data.List (find)
checkCommandTapeToTape :: [([Square], State, [Square])] -> [TapeCommand] -> Bool
checkCommandTapeToTape :: [([Square], State, [Square])] -> [TapeCommand] -> Bool
checkCommandTapeToTape [([Square], State, [Square])]
config [TapeCommand]
command =
case ([TapeCommand]
command, [([Square], State, [Square])]
config) of
([], []) -> Bool
True
(SingleTapeCommand ((Square
r1, State
s1, Square
l1), (Square
r2, State
_, Square
l2)) : [TapeCommand]
t1, ([Square]
r, State
s, [Square]
l) : [([Square], State, [Square])]
t2)
| State
s1 State -> State -> Bool
forall a. Eq a => a -> a -> Bool
== State
s Bool -> Bool -> Bool
&&
(Square
r1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
ES Bool -> Bool -> Bool
&& Square
l1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
RBS Bool -> Bool -> Bool
&& Square
r2 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
/= Square
ES Bool -> Bool -> Bool
&& Square
l2 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
RBS Bool -> Bool -> Bool
&& [Square]
l [Square] -> [Square] -> Bool
forall a. Eq a => a -> a -> Bool
== [Square
RBS] Bool -> Bool -> Bool
||
[Square]
r [Square] -> [Square] -> Bool
forall a. Eq a => a -> a -> Bool
/= [Square
LBS] Bool -> Bool -> Bool
&& Square
r1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== [Square] -> Square
forall a. [a] -> a
last [Square]
r Bool -> Bool -> Bool
&& Square
l1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
RBS Bool -> Bool -> Bool
&& Square
r2 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
ES Bool -> Bool -> Bool
&& Square
l2 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
RBS Bool -> Bool -> Bool
&& [Square]
l [Square] -> [Square] -> Bool
forall a. Eq a => a -> a -> Bool
== [Square
RBS] Bool -> Bool -> Bool
||
[Square] -> Square
forall a. [a] -> a
last [Square]
r Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
r1 Bool -> Bool -> Bool
&& [Square] -> Square
forall a. [a] -> a
head [Square]
l Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
l1 Bool -> Bool -> Bool
||
Square
r1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
ES Bool -> Bool -> Bool
&& Square
r2 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
ES Bool -> Bool -> Bool
&& Square
l1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
RBS Bool -> Bool -> Bool
&& Square
l2 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
l1 Bool -> Bool -> Bool
||
Square
r1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
/= Square
LBS Bool -> Bool -> Bool
&& Square
r1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
/= Square
ES Bool -> Bool -> Bool
&& Square
r1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== [Square] -> Square
forall a. [a] -> a
last [Square]
r Bool -> Bool -> Bool
&& Square
r1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
l2 Bool -> Bool -> Bool
&& Square
l1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
ES Bool -> Bool -> Bool
&& Square
l1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
r2 Bool -> Bool -> Bool
||
Square
l1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
/= Square
LBS Bool -> Bool -> Bool
&& Square
l1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
/= Square
ES Bool -> Bool -> Bool
&& Square
l1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== [Square] -> Square
forall a. [a] -> a
head [Square]
l Bool -> Bool -> Bool
&& Square
l1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
r2 Bool -> Bool -> Bool
&& Square
r1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
ES Bool -> Bool -> Bool
&& Square
r1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
l2) -> [([Square], State, [Square])] -> [TapeCommand] -> Bool
checkCommandTapeToTape [([Square], State, [Square])]
t2 [TapeCommand]
t1
| Bool
otherwise -> Bool
False
([TapeCommand], [([Square], State, [Square])])
_ -> [Char] -> Bool
forall a. HasCallStack => [Char] -> a
error [Char]
"Wrong command type"
applyCommand :: [([Square], State, [Square])] -> [TapeCommand] -> [[([Square], State, [Square])]] -> [([Square], State, [Square])] -> [[([Square], State, [Square])]]
applyCommand :: [([Square], State, [Square])]
-> [TapeCommand]
-> [[([Square], State, [Square])]]
-> [([Square], State, [Square])]
-> [[([Square], State, [Square])]]
applyCommand [([Square], State, [Square])]
config [TapeCommand]
command [[([Square], State, [Square])]]
configs [([Square], State, [Square])]
acc =
case ([TapeCommand]
command, [([Square], State, [Square])]
config) of
([], []) -> [[([Square], State, [Square])]]
configs [[([Square], State, [Square])]]
-> [[([Square], State, [Square])]]
-> [[([Square], State, [Square])]]
forall a. [a] -> [a] -> [a]
++ [[([Square], State, [Square])] -> [([Square], State, [Square])]
forall a. [a] -> [a]
reverse [([Square], State, [Square])]
acc]
(SingleTapeCommand ((Square
r1, State
_, Square
l1), (Square
r2, State
s2, Square
l2)) : [TapeCommand]
t1, ([Square]
r, State
_, [Square]
l) : [([Square], State, [Square])]
t2)
| Square
r1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
ES Bool -> Bool -> Bool
&& Square
r2 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
/= Square
ES Bool -> Bool -> Bool
&& Square
l1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
RBS Bool -> Bool -> Bool
&& Square
l2 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
l1 -> [([Square], State, [Square])]
-> [TapeCommand]
-> [[([Square], State, [Square])]]
-> [([Square], State, [Square])]
-> [[([Square], State, [Square])]]
applyCommand [([Square], State, [Square])]
t2 [TapeCommand]
t1 [[([Square], State, [Square])]]
configs ([([Square], State, [Square])] -> [[([Square], State, [Square])]])
-> [([Square], State, [Square])] -> [[([Square], State, [Square])]]
forall a b. (a -> b) -> a -> b
$ ([Square]
r [Square] -> [Square] -> [Square]
forall a. [a] -> [a] -> [a]
++ [Square
r2], State
s2, [Square]
l) ([Square], State, [Square])
-> [([Square], State, [Square])] -> [([Square], State, [Square])]
forall a. a -> [a] -> [a]
: [([Square], State, [Square])]
acc
| Square
l1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
RBS Bool -> Bool -> Bool
&& Square
r2 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
ES Bool -> Bool -> Bool
&& Square
r1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
/= Square
ES Bool -> Bool -> Bool
&& Square
l2 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
l1 -> [([Square], State, [Square])]
-> [TapeCommand]
-> [[([Square], State, [Square])]]
-> [([Square], State, [Square])]
-> [[([Square], State, [Square])]]
applyCommand [([Square], State, [Square])]
t2 [TapeCommand]
t1 [[([Square], State, [Square])]]
configs ([([Square], State, [Square])] -> [[([Square], State, [Square])]])
-> [([Square], State, [Square])] -> [[([Square], State, [Square])]]
forall a b. (a -> b) -> a -> b
$ ([Square] -> [Square]
forall a. [a] -> [a]
init [Square]
r, State
s2, [Square]
l) ([Square], State, [Square])
-> [([Square], State, [Square])] -> [([Square], State, [Square])]
forall a. a -> [a] -> [a]
: [([Square], State, [Square])]
acc
| Square
r1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
ES Bool -> Bool -> Bool
&& Square
r2 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
ES Bool -> Bool -> Bool
&& Square
l1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
RBS Bool -> Bool -> Bool
&& Square
l2 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
l1 -> [([Square], State, [Square])]
-> [TapeCommand]
-> [[([Square], State, [Square])]]
-> [([Square], State, [Square])]
-> [[([Square], State, [Square])]]
applyCommand [([Square], State, [Square])]
t2 [TapeCommand]
t1 [[([Square], State, [Square])]]
configs ([([Square], State, [Square])] -> [[([Square], State, [Square])]])
-> [([Square], State, [Square])] -> [[([Square], State, [Square])]]
forall a b. (a -> b) -> a -> b
$ ([Square]
r, State
s2, [Square]
l) ([Square], State, [Square])
-> [([Square], State, [Square])] -> [([Square], State, [Square])]
forall a. a -> [a] -> [a]
: [([Square], State, [Square])]
acc
| Square
r1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== [Square] -> Square
forall a. [a] -> a
last [Square]
r Bool -> Bool -> Bool
&& Square
l1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== [Square] -> Square
forall a. [a] -> a
head [Square]
l -> [([Square], State, [Square])]
-> [TapeCommand]
-> [[([Square], State, [Square])]]
-> [([Square], State, [Square])]
-> [[([Square], State, [Square])]]
applyCommand [([Square], State, [Square])]
t2 [TapeCommand]
t1 [[([Square], State, [Square])]]
configs ([([Square], State, [Square])] -> [[([Square], State, [Square])]])
-> [([Square], State, [Square])] -> [[([Square], State, [Square])]]
forall a b. (a -> b) -> a -> b
$ ([Square] -> [Square]
forall a. [a] -> [a]
init [Square]
r [Square] -> [Square] -> [Square]
forall a. [a] -> [a] -> [a]
++ [Square
r2], State
s2, Square
l2 Square -> [Square] -> [Square]
forall a. a -> [a] -> [a]
: [Square] -> [Square]
forall a. [a] -> [a]
tail [Square]
l) ([Square], State, [Square])
-> [([Square], State, [Square])] -> [([Square], State, [Square])]
forall a. a -> [a] -> [a]
: [([Square], State, [Square])]
acc
| Square
r1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
l2 Bool -> Bool -> Bool
&& Square
l1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
r2 Bool -> Bool -> Bool
&& Square
l1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
ES Bool -> Bool -> Bool
&& Square
r1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== [Square] -> Square
forall a. [a] -> a
last [Square]
r -> [([Square], State, [Square])]
-> [TapeCommand]
-> [[([Square], State, [Square])]]
-> [([Square], State, [Square])]
-> [[([Square], State, [Square])]]
applyCommand [([Square], State, [Square])]
t2 [TapeCommand]
t1 [[([Square], State, [Square])]]
configs ([([Square], State, [Square])] -> [[([Square], State, [Square])]])
-> [([Square], State, [Square])] -> [[([Square], State, [Square])]]
forall a b. (a -> b) -> a -> b
$ ([Square] -> [Square]
forall a. [a] -> [a]
init [Square]
r, State
s2, Square
l2 Square -> [Square] -> [Square]
forall a. a -> [a] -> [a]
: [Square]
l) ([Square], State, [Square])
-> [([Square], State, [Square])] -> [([Square], State, [Square])]
forall a. a -> [a] -> [a]
: [([Square], State, [Square])]
acc
| Square
r1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
l2 Bool -> Bool -> Bool
&& Square
l1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
r2 Bool -> Bool -> Bool
&& Square
r1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
ES Bool -> Bool -> Bool
&& Square
l1 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== [Square] -> Square
forall a. [a] -> a
head [Square]
l -> [([Square], State, [Square])]
-> [TapeCommand]
-> [[([Square], State, [Square])]]
-> [([Square], State, [Square])]
-> [[([Square], State, [Square])]]
applyCommand [([Square], State, [Square])]
t2 [TapeCommand]
t1 [[([Square], State, [Square])]]
configs ([([Square], State, [Square])] -> [[([Square], State, [Square])]])
-> [([Square], State, [Square])] -> [[([Square], State, [Square])]]
forall a b. (a -> b) -> a -> b
$ ([Square]
r [Square] -> [Square] -> [Square]
forall a. [a] -> [a] -> [a]
++ [Square
r2], State
s2, [Square] -> [Square]
forall a. [a] -> [a]
tail [Square]
l) ([Square], State, [Square])
-> [([Square], State, [Square])] -> [([Square], State, [Square])]
forall a. a -> [a] -> [a]
: [([Square], State, [Square])]
acc
| Bool
otherwise -> [Char] -> [[([Square], State, [Square])]]
forall a. HasCallStack => [Char] -> a
error ([Char]
"Wrong command " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [TapeCommand] -> [Char]
forall a. Show a => a -> [Char]
show [TapeCommand]
command)
([], [([Square], State, [Square])]
_) -> [[([Square], State, [Square])]]
configs
([TapeCommand], [([Square], State, [Square])])
_ -> [Char] -> [[([Square], State, [Square])]]
forall a. HasCallStack => [Char] -> a
error [Char]
"Can not apply command"
applyCommands :: [[([Square], State, [Square])]] -> [[TapeCommand]] -> [[[([Square], State, [Square])]]]
applyCommands :: [[([Square], State, [Square])]]
-> [[TapeCommand]] -> [[[([Square], State, [Square])]]]
applyCommands [[([Square], State, [Square])]]
configs = ([TapeCommand] -> [[([Square], State, [Square])]])
-> [[TapeCommand]] -> [[[([Square], State, [Square])]]]
forall a b. (a -> b) -> [a] -> [b]
map (\[TapeCommand]
c -> [([Square], State, [Square])]
-> [TapeCommand]
-> [[([Square], State, [Square])]]
-> [([Square], State, [Square])]
-> [[([Square], State, [Square])]]
applyCommand ([[([Square], State, [Square])]] -> [([Square], State, [Square])]
forall a. [a] -> a
last [[([Square], State, [Square])]]
configs) [TapeCommand]
c [[([Square], State, [Square])]]
configs [])
applyCommandss :: [[[([Square], State, [Square])]]] -> [[[TapeCommand]]] -> [[[([Square], State, [Square])]]] -> [[[([Square], State, [Square])]]]
applyCommandss :: [[[([Square], State, [Square])]]]
-> [[[TapeCommand]]]
-> [[[([Square], State, [Square])]]]
-> [[[([Square], State, [Square])]]]
applyCommandss [[[([Square], State, [Square])]]]
configss [[[TapeCommand]]]
commandss [[[([Square], State, [Square])]]]
acc =
case ([[[([Square], State, [Square])]]]
configss, [[[TapeCommand]]]
commandss) of
([], []) -> [[[([Square], State, [Square])]]]
acc
([[([Square], State, [Square])]]
configs : [[[([Square], State, [Square])]]]
t1, [[TapeCommand]]
commands : [[[TapeCommand]]]
t2) -> [[[([Square], State, [Square])]]]
-> [[[TapeCommand]]]
-> [[[([Square], State, [Square])]]]
-> [[[([Square], State, [Square])]]]
applyCommandss [[[([Square], State, [Square])]]]
t1 [[[TapeCommand]]]
t2 ([[[([Square], State, [Square])]]]
-> [[[([Square], State, [Square])]]])
-> [[[([Square], State, [Square])]]]
-> [[[([Square], State, [Square])]]]
forall a b. (a -> b) -> a -> b
$ [[([Square], State, [Square])]]
-> [[TapeCommand]] -> [[[([Square], State, [Square])]]]
applyCommands [[([Square], State, [Square])]]
configs [[TapeCommand]]
commands [[[([Square], State, [Square])]]]
-> [[[([Square], State, [Square])]]]
-> [[[([Square], State, [Square])]]]
forall a. [a] -> [a] -> [a]
++ [[[([Square], State, [Square])]]]
acc
([[[([Square], State, [Square])]]], [[[TapeCommand]]])
_ -> [Char] -> [[[([Square], State, [Square])]]]
forall a. HasCallStack => [Char] -> a
error [Char]
"Commandss and configss don't match"
checkFinalEmptyStates :: [State] -> [([Square], State, [Square])] -> Bool
checkFinalEmptyStates :: [State] -> [([Square], State, [Square])] -> Bool
checkFinalEmptyStates [State]
accessStates [([Square], State, [Square])]
config =
case ([State]
accessStates, [([Square], State, [Square])]
config) of
([], []) -> Bool
True
(State
s1 : [State]
t1, ([Square
l2], State
s2, [Square
r2]) : [([Square], State, [Square])]
t2) | Square
l2 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
LBS Bool -> Bool -> Bool
&& Square
r2 Square -> Square -> Bool
forall a. Eq a => a -> a -> Bool
== Square
RBS Bool -> Bool -> Bool
&& State
s1 State -> State -> Bool
forall a. Eq a => a -> a -> Bool
== State
s2 -> [State] -> [([Square], State, [Square])] -> Bool
checkFinalEmptyStates [State]
t1 [([Square], State, [Square])]
t2
([State], [([Square], State, [Square])])
_ -> Bool
False
startInterpreting :: [State]
-> [[[([Square], State, [Square])]]]
-> [[TapeCommand]]
-> [[([Square], State, [Square])]]
startInterpreting :: [State]
-> [[[([Square], State, [Square])]]]
-> [[TapeCommand]]
-> [[([Square], State, [Square])]]
startInterpreting [State]
accessStates [[[([Square], State, [Square])]]]
configss [[TapeCommand]]
commands =
case ([[([Square], State, [Square])]] -> Bool)
-> [[[([Square], State, [Square])]]]
-> Maybe [[([Square], State, [Square])]]
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find ([State] -> [([Square], State, [Square])] -> Bool
checkFinalEmptyStates [State]
accessStates ([([Square], State, [Square])] -> Bool)
-> ([[([Square], State, [Square])]]
-> [([Square], State, [Square])])
-> [[([Square], State, [Square])]]
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[([Square], State, [Square])]] -> [([Square], State, [Square])]
forall a. [a] -> a
last) [[[([Square], State, [Square])]]]
configss of
Just [[([Square], State, [Square])]]
configs -> [[([Square], State, [Square])]]
configs
Maybe [[([Square], State, [Square])]]
Nothing | [[[TapeCommand]]]
rules [[[TapeCommand]]] -> [[[TapeCommand]]] -> Bool
forall a. Eq a => a -> a -> Bool
/= [[]] -> [State]
-> [[[([Square], State, [Square])]]]
-> [[TapeCommand]]
-> [[([Square], State, [Square])]]
startInterpreting [State]
accessStates ([[[([Square], State, [Square])]]]
-> [[[TapeCommand]]]
-> [[[([Square], State, [Square])]]]
-> [[[([Square], State, [Square])]]]
applyCommandss [[[([Square], State, [Square])]]]
configss [[[TapeCommand]]]
rules []) [[TapeCommand]]
commands
| Bool
otherwise -> [Char] -> [[([Square], State, [Square])]]
forall a. HasCallStack => [Char] -> a
error ([Char] -> [[([Square], State, [Square])]])
-> [Char] -> [[([Square], State, [Square])]]
forall a b. (a -> b) -> a -> b
$ [Char]
"No applicable rule " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [[([Square], State, [Square])]] -> [Char]
forall a. Show a => a -> [Char]
show (([[([Square], State, [Square])]] -> [([Square], State, [Square])])
-> [[[([Square], State, [Square])]]]
-> [[([Square], State, [Square])]]
forall a b. (a -> b) -> [a] -> [b]
map [[([Square], State, [Square])]] -> [([Square], State, [Square])]
forall a. [a] -> a
last [[[([Square], State, [Square])]]]
configss)
where
rules :: [[[TapeCommand]]]
rules = ([[([Square], State, [Square])]] -> [[TapeCommand]])
-> [[[([Square], State, [Square])]]] -> [[[TapeCommand]]]
forall a b. (a -> b) -> [a] -> [b]
map (\[[([Square], State, [Square])]]
c -> ([TapeCommand] -> Bool) -> [[TapeCommand]] -> [[TapeCommand]]
forall a. (a -> Bool) -> [a] -> [a]
filter ([([Square], State, [Square])] -> [TapeCommand] -> Bool
checkCommandTapeToTape ([[([Square], State, [Square])]] -> [([Square], State, [Square])]
forall a. [a] -> a
last [[([Square], State, [Square])]]
c)) [[TapeCommand]]
commands) [[[([Square], State, [Square])]]]
configss
interpretTM :: [String] -> TM -> Configs
interpretTM :: [[Char]] -> TM -> Configs
interpretTM [[Char]]
input (TM
(InputAlphabet Set Square
inputAlphabet,
[TapeAlphabet]
_,
MultiTapeStates
_,
Commands Set [TapeCommand]
commands,
StartStates [State]
startStates,
AccessStates [State]
accessStates)) = do
let inputSquare :: [Square]
inputSquare = [[Char]] -> [Square]
mapValue [[Char]]
input
let isInputCorrect :: Bool
isInputCorrect = Set Square -> Set Square -> Bool
forall a. Ord a => Set a -> Set a -> Bool
Set.isSubsetOf ([Square] -> Set Square
forall a. Ord a => [a] -> Set a
Set.fromList [Square]
inputSquare) Set Square
inputAlphabet
let startConfigss :: [[[([Square], State, [Square])]]]
startConfigss = [[(Square
LBS Square -> [Square] -> [Square]
forall a. a -> [a] -> [a]
: [Square]
inputSquare, [State] -> State
forall a. [a] -> a
head [State]
startStates, [Square
RBS]) ([Square], State, [Square])
-> [([Square], State, [Square])] -> [([Square], State, [Square])]
forall a. a -> [a] -> [a]
:
(State -> ([Square], State, [Square]))
-> [State] -> [([Square], State, [Square])]
forall a b. (a -> b) -> [a] -> [b]
map ([Square
LBS],, [Square
RBS]) ([State] -> [State]
forall a. [a] -> [a]
tail [State]
startStates)]]
if Bool
isInputCorrect then [[([Square], State, [Square])]] -> Configs
Configs ([State]
-> [[[([Square], State, [Square])]]]
-> [[TapeCommand]]
-> [[([Square], State, [Square])]]
startInterpreting [State]
accessStates [[[([Square], State, [Square])]]]
startConfigss (Set [TapeCommand] -> [[TapeCommand]]
forall a. Set a -> [a]
Set.toList Set [TapeCommand]
commands)) else [Char] -> Configs
forall a. HasCallStack => [Char] -> a
error [Char]
"Incorrect input"