diff options
Diffstat (limited to 'Fractran')
-rw-r--r-- | Fractran/Parser.hs | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/Fractran/Parser.hs b/Fractran/Parser.hs index 7cbea11..63564d1 100644 --- a/Fractran/Parser.hs +++ b/Fractran/Parser.hs @@ -9,7 +9,9 @@ import Text.Combinators.Parsec -data FractranProgram = FractranProgram { fractions :: [(Int,Int)] } +data FractranProgram = FractranProgram { fractions :: [(Int,Int)] + , initialValue :: Int } + deriving (Show) @@ -17,3 +19,35 @@ parseFractran :: String -> Either ParseError FractranProgram parseFractran = parse fractran "error" + + +fractran = do + f <- many intPair + v <- initVal + eof + return (FractranProgram f v) + + +intPair = do + whiteSpace + n <- wholeNumber + slash + d <- wholeNumber + return (n,d) + + +slash = char '/' + + +initVal = do + whiteSpace + v <- wholeNumber + whiteSpace + return v + + +wholeNumber = + + +whiteSpace = many (oneOf "\t\n\r ") + |