Created
March 22, 2012 17:43
-
-
Save gdeest/2160752 to your computer and use it in GitHub Desktop.
Lambda-Term parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
varTerm = do | |
char <- noneOf ['.', '\\', '(', ')'] | |
return $ Var char | |
appTerm = do | |
app <- char '(' *> lambdaTerm <* char ')' | |
arg <- lambdaTerm | |
return $ App app arg | |
absTerm = do | |
var <- char '\\' *> anyChar <* char '.' | |
fun <- lambdaTerm | |
return $ Abs var fun | |
lambdaTerm = do | |
term <- try varTerm <|> appTerm <|> absTerm | |
return term | |
expression = do | |
term <- lambdaTerm <* char '\n' | |
return term |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment