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")) ] ]