{-| Module : Language.Brainfuck.Parse Description : Parser for the BF language Copyright : (c) Alejandro Cabrera, 2014 License : BSD-3 Maintainer : cpp.cabrera@gmail.com Stability : experimental Portability : POSIX -} module Language.Brainfuck.Parse ( parse ) where import Language.Brainfuck.Types (Term(..)) -- |A total function over the BF syntax. parse :: String -> [Term] parse [] = [] parse (x:xs) = case x of '>' -> IncDP : parse xs '<' -> DecDP : parse xs '+' -> IncByte : parse xs '-' -> DecByte : parse xs '.' -> OutByte : parse xs ',' -> InByte : parse xs '[' -> JumpForward : parse xs ']' -> JumpBackward : parse xs _ -> parse xs