summaryrefslogtreecommitdiff
path: root/Brainfuck/Parser.hs
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2014-04-10 05:25:03 +1000
committerJed Barber <jjbarber@y7mail.com>2014-04-10 05:25:03 +1000
commit281425310c5db21f87981eeb9601a71d1974d98d (patch)
treebef4643d906c93622c311fef2cf758fe94f1f651 /Brainfuck/Parser.hs
parente8695600977769008f285f9958eb043cca1b9b29 (diff)
Rearranging files
Diffstat (limited to 'Brainfuck/Parser.hs')
-rw-r--r--Brainfuck/Parser.hs62
1 files changed, 0 insertions, 62 deletions
diff --git a/Brainfuck/Parser.hs b/Brainfuck/Parser.hs
deleted file mode 100644
index 1ea046a..0000000
--- a/Brainfuck/Parser.hs
+++ /dev/null
@@ -1,62 +0,0 @@
-module Brainfuck.Parser (
- BrainfuckProgram,
- BrainCom(..),
-
- parseBrainfuck
- ) where
-
-import Control.Applicative( some )
-import Text.ParserCombinators.Parsec
-
-
-
-type BrainfuckProgram = [BrainCom]
-
-
-data BrainCom = R | L | Inc | Dec | Out | In | OpenLoop | CloseLoop
- deriving (Show, Eq)
-
-
-
-
-parseBrainfuck :: String -> Either ParseError BrainfuckProgram
-parseBrainfuck = parse brainfuck "error"
-
-
-
-
-brainfuck = do
- many commentChar
- bs <- many fuck
- eof
- return . concat $ bs
-
-
-fuck = (brainCommand >>= return . (:[]))
- <|> loop
- <?> "brainfuck command"
-
-
-loop = do
- char '['
- many commentChar
- bs <- many brainCommand
- char ']'
- many commentChar
- return . concat $ [[OpenLoop],bs,[CloseLoop]]
-
-
-brainCommand = do { b <- brainCom; many commentChar; return b }
-
-
-brainCom = (char '>' >> return R)
- <|> (char '<' >> return L)
- <|> (char '+' >> return Inc)
- <|> (char '-' >> return Dec)
- <|> (char '.' >> return Out)
- <|> (char ',' >> return In)
- <?> "brainfuck command"
-
-
-commentChar = noneOf "><+-.,[]"
-