From 007b33f87d05722b65450128bb0ac9a78f4ecd1d Mon Sep 17 00:00:00 2001 From: Nikolaj Gade Date: Thu, 26 Sep 2024 15:57:23 +0200 Subject: [PATCH] :jack_o_lantern: Function application --- a3/a3-handout/.gitignore | 1 + a3/a3-handout/src/APL/Parser.hs | 13 ++++++++++++- a3/a3-handout/src/APL/Parser_Tests.hs | 6 ++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 a3/a3-handout/.gitignore diff --git a/a3/a3-handout/.gitignore b/a3/a3-handout/.gitignore new file mode 100644 index 0000000..48a004c --- /dev/null +++ b/a3/a3-handout/.gitignore @@ -0,0 +1 @@ +dist-newstyle diff --git a/a3/a3-handout/src/APL/Parser.hs b/a3/a3-handout/src/APL/Parser.hs index 7652024..cef0e31 100644 --- a/a3/a3-handout/src/APL/Parser.hs +++ b/a3/a3-handout/src/APL/Parser.hs @@ -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 diff --git a/a3/a3-handout/src/APL/Parser_Tests.hs b/a3/a3-handout/src/APL/Parser_Tests.hs index 618761a..1cc9ddd 100644 --- a/a3/a3-handout/src/APL/Parser_Tests.hs +++ b/a3/a3-handout/src/APL/Parser_Tests.hs @@ -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")) ] ]