summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2014-02-05 13:25:54 +1100
committerJed Barber <jjbarber@y7mail.com>2014-02-05 13:25:54 +1100
commitcac23eb0080ee1abcf0e21004290fd79039d71a8 (patch)
tree9ff19ba24ba8bf7fc9b725468c690127e364bdb2
parent8ef39061d5e5967fb14c3452c1f1e43b9b79b4c5 (diff)
Completed most of Fractran parser
-rw-r--r--Fractran/Parser.hs36
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 ")
+