Skip to content
Snippets Groups Projects
Commit e48aa6b7 authored by Hendrik Rassmann's avatar Hendrik Rassmann
Browse files

merge conflict resolved, I think

parent 51937f9a
Branches
No related tags found
No related merge requests found
...@@ -9,16 +9,7 @@ import ExpTerm ...@@ -9,16 +9,7 @@ import ExpTerm
example_ps = "true false and not" -- 1 2 pop dup "-- %# Int Int\n add %# Int\n pop %# 1\n" example_ps = "true false and not" -- 1 2 pop dup "-- %# Int Int\n add %# Int\n pop %# 1\n"
example_tokens = scanPS example_ps example_tokens = scanPS example_ps
example_exprs = ps2exp <$> example_tokens example_exprs = ps2exp <$> example_tokens
{-
step_through :: Env -> [Expr BaseType] -> IO ()
step_through env [] = putStrLn "done:" >> putStrLn (show env)
step_through env (t:ts) = do
putStrLn "env:"
putStrLn $ show env
putStrLn $ "term:"
putStrLn $ show (t:ts)
step_through (step env t) (ts)
-}
step_through_FNNF :: [ENV] -> [FNNF BaseType] -> IO () step_through_FNNF :: [ENV] -> [FNNF BaseType] -> IO ()
step_through_FNNF envs [] = putStrLn "done:" >> putStrLn (show envs) step_through_FNNF envs [] = putStrLn "done:" >> putStrLn (show envs)
step_through_FNNF envs (t:ts) = sequence_ $ (\env -> do step_through_FNNF envs (t:ts) = sequence_ $ (\env -> do
...@@ -43,13 +34,3 @@ main = do ...@@ -43,13 +34,3 @@ main = do
putStrLn "now in FNNF" putStrLn "now in FNNF"
putStrLn $ show $ expr2fnnf <$> example_exprs putStrLn $ show $ expr2fnnf <$> example_exprs
step_through_FNNF [newENV] $ expr2fnnf <$> example_exprs step_through_FNNF [newENV] $ expr2fnnf <$> example_exprs
{-
old_main = do
tokens <- example_Tokens
let pref = find_prefix tokens
putStrLn $ "works for: " ++ (show $ pref)
putStrLn $ "remaining: " ++ (show $ length tokens - pref)
putStrLn $ "breaks for: " ++ (show $ tokens !! pref)
-}
...@@ -16,6 +16,5 @@ data BaseType -- << store constaints, such as <4, %2 = 0, length of String, etc ...@@ -16,6 +16,5 @@ data BaseType -- << store constaints, such as <4, %2 = 0, length of String, etc
-- | B -- Bottom of Stack -- | B -- Bottom of Stack
| Null | Null
| StringType --(Maybe String) | StringType --(Maybe String)
| Thing -- NoInfo: eating: allways works, but feeding it prop doesn't
| CharType deriving (Show,Eq) | CharType deriving (Show,Eq)
...@@ -11,8 +11,8 @@ data FNNF a = PI [NOPI a] ...@@ -11,8 +11,8 @@ data FNNF a = PI [NOPI a]
data NOPI a = PUSH a data NOPI a = PUSH a
| POP a | POP a
-- | THING | THING
-- | PLOP | PLOP
| SIGMA ([FNNF a]) | SIGMA ([FNNF a])
| CODE (FNNF a) | CODE (FNNF a)
| ZERO String | ZERO String
...@@ -58,8 +58,8 @@ data NNF a = Push a ...@@ -58,8 +58,8 @@ data NNF a = Push a
| NNF_Tag (NNF a) | NNF_Tag (NNF a)
| NNF_Seq [NNF a] | NNF_Seq [NNF a]
| NNF_Alt [NNF a] | NNF_Alt [NNF a]
-- | NNF_Thing | NNF_Thing
-- | NNF_Plop | NNF_Plop
| NNF_Code (NNF a) | NNF_Code (NNF a)
| NNF_Var Int | NNF_Var Int
| NNF_Zero String deriving (Show,Eq, Functor) | NNF_Zero String deriving (Show,Eq, Functor)
...@@ -68,7 +68,7 @@ data Expr a = Node a ...@@ -68,7 +68,7 @@ data Expr a = Node a
| Tag (Expr a) -- == 1 to be interpreted as a comment | Tag (Expr a) -- == 1 to be interpreted as a comment
| Seq [Expr a] | Seq [Expr a]
| Alt [Expr a] | Alt [Expr a]
---- | Thing | Thing
-- | Alt ([(Expr a, Probability)]) -- | Alt ([(Expr a, Probability)])
-- | Star (Expr a) -- == [0.5 0 + .25*a + .125*aa + ...] -- | Star (Expr a) -- == [0.5 0 + .25*a + .125*aa + ...]
| Code (Expr a) | Code (Expr a)
...@@ -127,13 +127,8 @@ expr2nnf expr = pos expr where ...@@ -127,13 +127,8 @@ expr2nnf expr = pos expr where
neg (Node x) = Pop x neg (Node x) = Pop x
neg (Neg x) = pos x neg (Neg x) = pos x
neg (Seq xs) = NNF_Seq $ reverse $ neg <$> xs neg (Seq xs) = NNF_Seq $ reverse $ neg <$> xs
<<<<<<< HEAD
neg (Alt xs) = NNF_Alt $ neg <$> xs -- TODO: this is optimistic, change it later -- error "Think about this hard, but later, neg of OR" neg (Alt xs) = NNF_Alt $ neg <$> xs -- TODO: this is optimistic, change it later -- error "Think about this hard, but later, neg of OR"
neg Thing = NNF_Plop neg Thing = NNF_Plop
=======
neg (Alt _) = error "Think about this hard, but later, neg of OR"
-- neg Thing = NNF_Plop
>>>>>>> refs/remotes/origin/main
neg (Code x) = NNF_Code (neg x) neg (Code x) = NNF_Code (neg x)
neg (Var x) = error "Think about negation of Variables, if this would make sense" neg (Var x) = error "Think about negation of Variables, if this would make sense"
neg (Zero m) = NNF_Zero m neg (Zero m) = NNF_Zero m
...@@ -156,27 +151,8 @@ instance Semigroup (Expr a) where ...@@ -156,27 +151,8 @@ instance Semigroup (Expr a) where
l <> r = error $ "no matching case at <> decleration of Semigroup Expr a" l <> r = error $ "no matching case at <> decleration of Semigroup Expr a"
-- main = putStrLn $ exprTree $ Seq [Neg (Node 3), Alt [Seq [(Node 7),Zero] , Code (Node 1)]] -- main = putStrLn $ exprTree $ Seq [Neg (Node 3), Alt [Seq [(Node 7),Zero] , Code (Node 1)]]
<<<<<<< HEAD
instance Monoid (Expr a) where instance Monoid (Expr a) where
mempty = Seq [] mempty = Seq []
=======
top :: (Expr a) -> (Expr a)
top (Node a) = Node a
--top (Thing) = Thing
top (Neg x) = Neg (top x)
top (Seq []) = Zero "top of stack empty"
top (Seq xs) = top (last xs)
pop :: (Show a) => (Expr a) -> (Expr a)
pop (Node a) = Seq []
pop (Seq []) = Zero "popping from empty Stack"
pop (Seq xs) = case (last xs) of
(Node a) -> Seq (init xs)
-- Thing -> Seq (init xs)
(Neg a) -> error "this only works if pop knows that to pop, not necc for Demo"
pop x = trace ("unknown: " <> (show x)) (error "implement a match for this!")
>>>>>>> refs/remotes/origin/main
instance Semiring (Expr a) where instance Semiring (Expr a) where
l <+> r = Alt [l,r] l <+> r = Alt [l,r]
...@@ -195,7 +171,7 @@ groupSeq (Neg (Node x)) = Seq [Neg (Node x)] ...@@ -195,7 +171,7 @@ groupSeq (Neg (Node x)) = Seq [Neg (Node x)]
instance Stack Expr where instance Stack Expr where
-- (!!!) :: (Show a) => (Expr a) -> Int -> Expr a -- (!!!) :: (Show a) => (Expr a) -> Int -> Expr a
(Node x) !!! 0 = x (Node x) !!! 0 = Node x
(Node _) !!! _ = undefined (Node _) !!! _ = undefined
(Seq xs) !!! i = (xs !! i) !!! 0 (Seq xs) !!! i = (xs !! i) !!! 0
-- x !!! i = trace ("!!! of: " <> (show x)) error "welp" -- x !!! i = trace ("!!! of: " <> (show x)) error "welp"
......
...@@ -46,7 +46,6 @@ stepPI :: ENV -> (FNNF BaseType) -> [ENV] ...@@ -46,7 +46,6 @@ stepPI :: ENV -> (FNNF BaseType) -> [ENV]
stepPI env (TAU x) = stepNOPI env x stepPI env (TAU x) = stepNOPI env x
stepPI env (PI xs) = foldM (stepNOPI) env xs stepPI env (PI xs) = foldM (stepNOPI) env xs
<<<<<<< HEAD
stepNOPI :: ENV -> (NOPI BaseType) -> [ENV] stepNOPI :: ENV -> (NOPI BaseType) -> [ENV]
stepNOPI ENV{s = (TAU (ZERO _)) } _ = [] stepNOPI ENV{s = (TAU (ZERO _)) } _ = []
stepNOPI env (PUSH a) = pure $ env {s = s env <> (TAU (PUSH a))} stepNOPI env (PUSH a) = pure $ env {s = s env <> (TAU (PUSH a))}
...@@ -59,47 +58,7 @@ stepNOPI env (VAR i) = pure $ env {s = (p env) <> (s env !!! i)} ...@@ -59,47 +58,7 @@ stepNOPI env (VAR i) = pure $ env {s = (p env) <> (s env !!! i)}
stepNOPI env (SIGMA []) = [] -- pure $ env {s = (TAU $ ZERO $ "empty SIGMA! state:\n" <> (show env))} -- error info discarded -- Zu optimistisch stepNOPI env (SIGMA []) = [] -- pure $ env {s = (TAU $ ZERO $ "empty SIGMA! state:\n" <> (show env))} -- error info discarded -- Zu optimistisch
stepNOPI env (SIGMA (x:xs)) = (stepPI env x) ++ (stepPI env (TAU $ SIGMA xs)) stepNOPI env (SIGMA (x:xs)) = (stepPI env x) ++ (stepPI env (TAU $ SIGMA xs))
stepNOPI env unknown = error $ "no stepNOPI match for " <> (show unknown) -- pure $ env {s = TAU $ ZERO $ "no match for** " <> (show unknown) <> " **in stepNOPI:\n" <> (show env)} -- Zu optimistisch stepNOPI env unknown = error $ "no stepNOPI match for " <> (show unknown) -- pure $ env {s = TAU $ ZERO $ "no match for** " <> (show unknown) <> " **in stepNOPI:\n" <> (show env)} -- Zu optimistisch
=======
stepNOPI :: ENV -> (NOPI BaseType) -> ENV
stepNOPI env (PUSH a) = env {s = s env <> (TAU (PUSH a))}
--stepNOPI env (PLOP) = env {s = tailFNNF (s env), p = (p env) <> ((TAU . headFNNF) (s env))}
stepNOPI env (POP a)
| s env == PI [] = error "typing with negative types not yet implemented lol"
| lastFNNF (s env) == (PUSH a) = undefined
--stepNOPI env (VAR i) = env {}
--step env (Neg (Node x)) = env {stack = (pop (stack env)), popped = (popped env <> (Node x))} -- NO TEST, FIX
{-
step :: ENV -> (TERM) -> ENV
step env (Node a) = env {stack = stack env <> (Node a)}
step env (Tag x) = if ſ x (stack env) then env else error $ "not matching annotation:\n Anno: " <> (show x) <> "\n stack: " <> (show (stack env))
step env (Seq []) = env
step env (Seq (x:xs)) = step (step env x) (Seq xs)
step env (Neg (Node x)) = env {stack = (pop (stack env)), popped = (popped env <> (Node x))} -- NO TEST, FIX
step env (Neg Thing) = env {stack = (pop (stack env)),popped = (popped env <> (top (stack env)))} -- << HERE poped thing
step env (Var i) = env {stack = (stack env) <> (popped env !!! i)} -- !! scarry
step env x = error $ "next step not known for " <> show x
-}
>>>>>>> refs/remotes/origin/main
--assume NNF
step :: Env -> Term -> Env
step env (Node a) = env {stack = stack env <> (Node a)}
step env (Tag x) = if ſ x (stack env) then env else error $ "not matching annotation:\n Anno: " <> (show x) <> "\n"
step env (Seq []) = env
step env (Seq (x:xs)) = step (step env x) (Seq xs)
step env (Neg (Node x)) = env {stack = (pop (stack env)), popped = (popped env <> (Node x))} -- NO TEST, FIX
--step env (Neg Thing) = env {stack = (pop (stack env)),popped = (popped env <> (top (stack env)))} -- << HERE po>
<<<<<<< HEAD
step env (Var i) = env {stack = (stack env) <> (popped env !!! i)} -- !! scarry
=======
step env (Var i) = env {stack = (stack env) <> (Node (popped env !!! i))} -- !! scarry
>>>>>>> refs/remotes/origin/main
step env x = error $ "next step not known for " <> show x
newEnv :: Env
newEnv = Env (Seq []) (Seq [])
data Int_Expr = Int_Var Int data Int_Expr = Int_Var Int
| Known Int | Known Int
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment