From a32fcdf9da3dbb4f5b0d5503249720aff686416e Mon Sep 17 00:00:00 2001 From: Nikolaj Gade Date: Thu, 26 Sep 2024 17:01:06 +0200 Subject: [PATCH] :printer: Half a printing function part 2 (does not work) --- a3/a3-handout/src/APL/Parser.hs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/a3/a3-handout/src/APL/Parser.hs b/a3/a3-handout/src/APL/Parser.hs index cbfd1b9..4b53203 100644 --- a/a3/a3-handout/src/APL/Parser.hs +++ b/a3/a3-handout/src/APL/Parser.hs @@ -101,26 +101,33 @@ pLExp = <$> (lKeyword "if" *> pExp) <*> (lKeyword "then" *> pExp) <*> (lKeyword "else" *> pExp), - Print - <$> (lKeyword "print" *> pStringLit) - <*> pExp, pFExp ] -pPExp :: Parser Exp -pPExp = pLExp >>= chain +pExp3 :: Parser Exp +pExp3 = + choice + [ + Print + <$> (lKeyword "print" *> pStringLit) + <*> pExp, + pLExp + ] + +pExp2 :: Parser Exp +pExp2 = pExp3 >>= chain where chain x = choice [ do lString "**" - y <- pPExp + y <- pExp2 chain $ Pow x y, pure x ] pExp1 :: Parser Exp -pExp1 = pPExp >>= chain +pExp1 = pExp2 >>= chain where chain x = choice