From cac23eb0080ee1abcf0e21004290fd79039d71a8 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Wed, 5 Feb 2014 13:25:54 +1100 Subject: Completed most of Fractran parser --- Fractran/Parser.hs | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'Fractran') 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 ") + -- cgit