diff options
Diffstat (limited to 'Brainfuck/Parser.hs')
-rw-r--r-- | Brainfuck/Parser.hs | 62 |
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 "><+-.,[]" - |