diff options
Removed old homeworks
4 files changed, 0 insertions, 120 deletions
| -rw-r--r-- | homework/81333/brainfsck/src/Lib.hs | 30 | ||||
| -rw-r--r-- | homework/81333/brainfsck/src/Text/Brainfsck/Parser.hs | 56 | ||||
| -rw-r--r-- | homework/81333/brainfsck/src/Text/Brainfsck/Types.hs | 24 | ||||
| -rw-r--r-- | homework/81333/brainfsck/src/Text/Brainfsck/Util.hs | 10 |
diff --git a/homework/81333/brainfsck/src/Lib.hs b/homework/81333/brainfsck/src/Lib.hs deleted file mode 100644 index e4cc95c..0000000 --- a/homework/81333/brainfsck/src/Lib.hs +++ /dev/null @@ -1,30 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} - -module Lib - ( blocks - ) where - -import Data.Attoparsec.ByteString.Char8 -import qualified Data.ByteString.Char8 as B - -import Data.Char -import Text.Brainfsck.Types -import Text.Brainfsck.Util - -blocks :: Blocks -> [BFExpr] -> IO Blocks -blocks b [] = pure b -blocks (Blocks h b r) (BFRight:es) = blocks (Blocks (h + 1) b r) es -blocks (Blocks h b r) (BFLeft:es) = blocks (Blocks (max (h - 1) 0) b r) es -blocks (Blocks h b r) (BFPlus:es) = blocks (Blocks h (inc b h) r) es -blocks (Blocks h b r) (BFMinus:es) = blocks (Blocks h (dec b h) r) es -blocks (Blocks h b r) (BFPut:es) = - blocks (Blocks h b (r <> B.singleton (chr $ b !! h))) es -blocks (Blocks h b r) (BFGet:es) = do - v <- getChar - blocks (Blocks h (load b h $ ord v) r) es -blocks current@(Blocks h b r) (BFLoop expr:es) = do - if b !! h == 0 - then blocks current es - else do - newBlocks <- blocks current expr - blocks newBlocks ((BFLoop expr) : es) diff --git a/homework/81333/brainfsck/src/Text/Brainfsck/Parser.hs b/homework/81333/brainfsck/src/Text/Brainfsck/Parser.hs deleted file mode 100644 index 28c019a..0000000 --- a/homework/81333/brainfsck/src/Text/Brainfsck/Parser.hs +++ /dev/null @@ -1,56 +0,0 @@ -module Text.Brainfsck.Parser - ( parseText - ) where - -import Control.Applicative - -import Data.Attoparsec.ByteString.Char8 -import qualified Data.ByteString.Char8 as B -import Data.Either (fromRight) - -import Text.Brainfsck.Types - -goRight :: Parser BFExpr -goRight = do - char '>' - pure BFRight - -goLeft :: Parser BFExpr -goLeft = do - char '<' - pure BFLeft - -plus :: Parser BFExpr -plus = do - char '+' - pure BFPlus - -minus :: Parser BFExpr -minus = do - char '-' - pure BFMinus - -get :: Parser BFExpr -get = do - char ',' - pure BFGet - -put :: Parser BFExpr -put = do - char '.' - pure BFPut - -bfsymbol :: Parser BFExpr -bfsymbol = goRight <|> goLeft <|> plus <|> minus <|> get <|> put <|> loop - -loop :: Parser BFExpr -loop = do - char '[' - m <- many' bfsymbol - char ']' - pure $ BFLoop m - -parseText :: B.ByteString -> [BFExpr] -parseText s = - fromRight [] $ - parseOnly (many' bfsymbol) $ B.filter ((flip elem) "+-,.<>[]") s diff --git a/homework/81333/brainfsck/src/Text/Brainfsck/Types.hs b/homework/81333/brainfsck/src/Text/Brainfsck/Types.hs deleted file mode 100644 index 5dd26f6..0000000 --- a/homework/81333/brainfsck/src/Text/Brainfsck/Types.hs +++ /dev/null @@ -1,24 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} - -module Text.Brainfsck.Types where - -import qualified Data.ByteString.Char8 as B - -data BFExpr - = BFRight - | BFLeft - | BFPlus - | BFMinus - | BFGet - | BFPut - | BFLoop [BFExpr] - deriving (Show) - -data Blocks = Blocks - { h :: Int - , b :: [Int] - , r :: B.ByteString - } deriving (Show) - -newBlocks :: Blocks -newBlocks = Blocks {h = 0, b = [0,0 ..], r = ""} diff --git a/homework/81333/brainfsck/src/Text/Brainfsck/Util.hs b/homework/81333/brainfsck/src/Text/Brainfsck/Util.hs deleted file mode 100644 index fb2d5ad..0000000 --- a/homework/81333/brainfsck/src/Text/Brainfsck/Util.hs +++ /dev/null @@ -1,10 +0,0 @@ -module Text.Brainfsck.Util where - -inc :: [Int] -> Int -> [Int] -inc b h = take h b <> [b !! h + 1] <> drop (h + 1) b - -dec :: [Int] -> Int -> [Int] -dec b h = take h b <> [b !! h - 1] <> drop (h + 1) b - -load :: [Int] -> Int -> Int -> [Int] -load b h v = take h b <> [v] <> drop (h + 1) b |
