🎃 Function application

This commit is contained in:
2024-09-26 15:57:23 +02:00
parent ff778af26f
commit 007b33f87d
3 changed files with 19 additions and 1 deletions

1
a3/a3-handout/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
dist-newstyle

View File

@ -75,6 +75,17 @@ pAtom =
lString "(" *> pExp <* lString ")"
]
pFExp :: Parser Exp
pFExp = pAtom >>= chain
where
chain x =
choice
[ do
y <- pAtom
chain $ Apply x y,
pure x
]
pLExp :: Parser Exp
pLExp =
choice
@ -82,7 +93,7 @@ pLExp =
<$> (lKeyword "if" *> pExp)
<*> (lKeyword "then" *> pExp)
<*> (lKeyword "else" *> pExp),
pAtom
pFExp
]
pExp1 :: Parser Exp

View File

@ -64,5 +64,11 @@ tests =
"Lexing edge cases"
[ parserTest "2 " $ CstInt 2,
parserTest " 2" $ CstInt 2
],
testGroup
"FExp"
[ parserTest "x y" $ Apply (Var "x") (Var "y"),
parserTest "x y z" $ Apply (Apply (Var "x") (Var "y")) (Var "z"),
parserTest "x (y z)" $ Apply (Var "x") (Apply (Var "y") (Var "z"))
]
]