diff options
author | Jed Barber <jjbarber@y7mail.com> | 2014-03-09 04:03:53 +1100 |
---|---|---|
committer | Jed Barber <jjbarber@y7mail.com> | 2014-03-09 04:03:53 +1100 |
commit | 257a7a01f797560f9271a4ef779956771acc4a7b (patch) | |
tree | c5cd637597cb0c613329deaa7e45e43818865d74 /Unlambda | |
parent | d214e0cfee802e9eba8c925af54490fd782e2d5c (diff) |
Added support for Unlambda version 2
Diffstat (limited to 'Unlambda')
-rw-r--r-- | Unlambda/Parser.hs | 57 |
1 files changed, 47 insertions, 10 deletions
diff --git a/Unlambda/Parser.hs b/Unlambda/Parser.hs index b6afbea..384ec8f 100644 --- a/Unlambda/Parser.hs +++ b/Unlambda/Parser.hs @@ -10,10 +10,17 @@ import Text.ParserCombinators.Parsec -data UnlambdaTerm = S | K | I | V | R | D | C +data UnlambdaTerm = S | K | I | V | R | D | C | E | Bar | Reed | Dot { cha :: Char } + | Compare { cha :: Char } | App { func :: UnlambdaTerm , arg :: UnlambdaTerm } + | Kpartial { constant :: UnlambdaTerm } + | Spartial { func1 :: UnlambdaTerm } + | Sapp { func1 :: UnlambdaTerm + , func2 :: UnlambdaTerm } + | Continuation { arg :: UnlambdaTerm } + | Promise { arg :: UnlambdaTerm } deriving (Eq, Show) @@ -24,6 +31,11 @@ parseUnlambda = parse unlambda "error" +parseUnlambda1 :: String -> Either ParseError UnlambdaTerm +parseUnlambda1 = parse unlambda1 "error" + + + unlambda = do whiteSpace t <- term @@ -31,18 +43,33 @@ unlambda = do return t -term = (try app) - <|> (try s) - <|> (try k) - <|> (try i) - <|> (try v) - <|> (try r) - <|> (try d) - <|> (try c) - <|> (try dot) +unlambda1 = do + whiteSpace + t <- term1 + eof + return t + + +term = (try term1) + <|> (try e) + <|> (try reed) + <|> (try comp) + <|> (try bar) <?> "unlambda term" +term1 = (try app) + <|> (try s) + <|> (try k) + <|> (try i) + <|> (try v) + <|> (try r) + <|> (try d) + <|> (try c) + <|> (try dot) + <?> "unlambda term" + + app = do char '`' whiteSpace @@ -58,6 +85,16 @@ v = char 'v' >> whiteSpace >> return V r = char 'r' >> whiteSpace >> return R d = char 'd' >> whiteSpace >> return D c = char 'c' >> whiteSpace >> return C +e = char 'e' >> whiteSpace >> return E +reed = char '@' >> whiteSpace >> return Reed +bar = char '|' >> whiteSpace >> return Bar + + +comp = do + char '?' + c <- noneOf("") + whiteSpace + return (Compare c) dot = do |