Website Summary Files Commits Branches @commit @diff @stats
path: root / homework / 81248 / brainfsck / src / Brainfsck
diff options
context:
space:
mode:
Commitaeb0d4f887a0c18c36b59acc7b5df08e62020c50 (patch)
Author
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2020-10-11 21:32:48 +0300
Committer
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2020-10-11 21:33:38 +0300
Filesb6abdc6e1810326b587f2a160f39570f1f568f27 /homework/81248/brainfsck/src/Brainfsck
IPL-aeb0d4f887a0c18c36b59acc7b5df08e62020c50.tar
IPL-aeb0d4f887a0c18c36b59acc7b5df08e62020c50.tar.gz
IPL-aeb0d4f887a0c18c36b59acc7b5df08e62020c50.zip
Parent154b7cd30f21af1554ca26986ff1643e28857727 (diff)
Removed old homeworks
diff --git a/homework/81248/brainfsck/src/Brainfsck/Eval.hs b/homework/81248/brainfsck/src/Brainfsck/Eval.hs
deleted file mode 100644
index 10ffb75..0000000
--- a/homework/81248/brainfsck/src/Brainfsck/Eval.hs
+++ /dev/null
@@ -1,35 +0,0 @@
-{-# OPTIONS -fno-warn-incomplete-patterns #-}
-
-module Brainfsck.Eval
- ( eval
- ) where
-
-import Control.Monad (void, foldM)
-
-import Data.Char (chr, ord)
-
-import Brainfsck.Types
-
-(?) :: (a -> b -> c) -> b -> a -> c
-(?) = flip
-
--- We know we never reach [], because we only call this with infinite tapes.
-operTape :: Expr -> Tape -> IO Tape
-operTape GoRight (Tape ls x (r:rs)) = pure $ Tape (x:ls) r rs
-operTape GoLeft (Tape (l:ls) x rs) = pure $ Tape ls l (x:rs)
-operTape Incr (Tape ls x rs) = pure $ Tape ls (succ x) rs
-operTape Decr (Tape ls x rs) = pure $ Tape ls (pred x) rs
-operTape Out t@(Tape _ x _) = t <$ do putChar $ chr x
-operTape In (Tape ls _ rs) = (Tape ls ? rs) . ord <$> getChar
-operTape l@(Loop xs) t@(Tape _ x _) =
- if x == 0 then pure t
- else do
- tn@(Tape _ x' _) <- evalTape xs t
- if x' /= 0 then operTape l tn
- else pure tn
-
-evalTape :: [Expr] -> Tape -> IO Tape
-evalTape xs t = foldM (flip operTape) t xs
-
-eval :: [Expr] -> IO ()
-eval xs = void $ evalTape xs initialTape
diff --git a/homework/81248/brainfsck/src/Brainfsck/Parse.hs b/homework/81248/brainfsck/src/Brainfsck/Parse.hs
deleted file mode 100644
index 1a9625d..0000000
--- a/homework/81248/brainfsck/src/Brainfsck/Parse.hs
+++ /dev/null
@@ -1,60 +0,0 @@
-module Brainfsck.Parse
- ( parse
- , ps
- ) where
-
-import Prelude hiding (takeWhile)
-
-import Data.Functor (($>))
-import Data.Either (fromRight)
-import Data.Foldable (asum)
-
-import Data.ByteString (ByteString)
-
-import Data.Attoparsec.ByteString.Char8 hiding (parse)
-
-import Brainfsck.Types
-expr :: Parser Expr
-expr = asum
- [ goRight
- , goLeft
- , incr
- , decr
- , out
- , inp
- , loop
- ]
-
-eatComments :: Parser ()
-eatComments = takeWhile (\x -> x `notElem` ("><+-,.[]" :: String)) $> ()
-
-comments :: Parser a -> Parser a
-comments p = eatComments *> p <* eatComments
-
-goRight :: Parser Expr
-goRight = comments $ char '>' $> GoRight
-
-goLeft :: Parser Expr
-goLeft = comments $ char '<' $> GoLeft
-
-incr :: Parser Expr
-incr = comments $ char '+' $> Incr
-
-decr :: Parser Expr
-decr = comments $ char '-' $> Decr
-
-out :: Parser Expr
-out = comments $ char '.' $> Out
-
-inp :: Parser Expr
-inp = comments $ char ',' $> In
-
-loop :: Parser Expr
-loop = comments $ Loop <$>
- (char '[' *> comments (many' expr) <* char ']')
-
-parse :: ByteString -> Either String [Expr]
-parse = parseOnly (many' expr <* endOfInput)
-
-ps :: ByteString -> [Expr]
-ps = fromRight [] . parse
diff --git a/homework/81248/brainfsck/src/Brainfsck/Types.hs b/homework/81248/brainfsck/src/Brainfsck/Types.hs
deleted file mode 100644
index 6195a24..0000000
--- a/homework/81248/brainfsck/src/Brainfsck/Types.hs
+++ /dev/null
@@ -1,28 +0,0 @@
-module Brainfsck.Types
- ( Expr(..)
- , Tape(..)
- , initialTape
- ) where
-
-data Expr
- = GoRight -- increment the data pointer (to point to the next cell to the right).
- | GoLeft -- decrement the data pointer (to point to the next cell to the left).
- | Incr -- increment (increase by one) the byte at the data pointer.
- | Decr -- decrement (decrease by one) the byte at the data pointer.
- | Out -- output the byte at the data pointer.
- | In -- accept one byte of input, storing its value in the byte at the data pointer.
- | Loop [Expr]
- deriving (Show, Eq)
-
--- if the byte at the data pointer is zero, then instead of moving the instruction pointer forward to the next command, jump it forward to the command after the matching ] command.
--- if the byte at the data pointer is nonzero, then instead of moving the instruction pointer forward to the next command, jump it back to the command after the matching [ command.
-
-data Tape = Tape
- { left :: [Int]
- , head :: Int
- , right :: [Int]
- }
- deriving (Show, Eq)
-
-initialTape :: Tape
-initialTape = Tape (repeat 0) 0 $ repeat 0