module Math.Model.Automaton.Stack where
import Data.Delta
import qualified Data.Foldable as Fold
import Data.List
import qualified Data.Map.Strict as Map
import Data.Sigma
import Data.Label
import Control.Monad.State.Lazy
type Delta a = (:->:) a (Maybe Symbol, Symbol) Wd
type Key a = (Label a, (Maybe Symbol, Symbol))
liftDelta:: Ord a => [(a, Wd, Symbol, a, Wd)]-> Delta a
liftDelta xs = let
(as,bs,cs,ds,es) = unzip5 xs
f = fmap Q
g [] = Nothing
g (x:_) = Just x
ps = zip (fmap g bs) cs
ks = zip (f as) ps
rs = zip (f ds) es
in Map.fromList (zip ks rs)
nextDTuple :: Ord a => Delta a -> Key a -> (Label a, Wd)
nextDTuple dt k = if Map.member k dt then dt Map.! k else (QE,[])
data StackA a = Stack {
getDelta::Delta a
,getInitState::Label a
,getFinal::Final a
,getInitSymbol::Symbol} deriving(Show, Eq)
nextState::(Ord a) => Delta a -> Wd -> State (Wd, Label a) (Label a)
nextState _ [] = do
(_, q) <- get
return q