😎 Task 4 and 5

This commit is contained in:
2024-09-28 14:09:12 +02:00
parent a32fcdf9da
commit a9a530444e
2 changed files with 42 additions and 4 deletions

View File

@@ -51,7 +51,7 @@ lVName = lexeme $ try $ do
lStringLit :: Parser String
lStringLit =
lexeme $ read <$> some (satisfy isAlpha) <* notFollowedBy (satisfy isAlphaNum)
lexeme $ some (satisfy (/= '"'))
lInteger :: Parser Integer
lInteger =
@@ -101,6 +101,16 @@ pLExp =
<$> (lKeyword "if" *> pExp)
<*> (lKeyword "then" *> pExp)
<*> (lKeyword "else" *> pExp),
Lambda
<$> (lString "\\" *> lVName)
<*> (lString "->" *> pExp),
TryCatch
<$> (lKeyword "try" *> pExp)
<*> (lKeyword "catch" *> pExp),
Let
<$> (lKeyword "let" *> lVName)
<*> (lString "=" *> pExp)
<*> (lKeyword "in" *> pExp),
pFExp
]
@@ -110,7 +120,10 @@ pExp3 =
[
Print
<$> (lKeyword "print" *> pStringLit)
<*> pExp,
<*> pAtom,
KvGet <$> (lKeyword "get" *> pAtom),
KvPut <$> (lKeyword "put" *> pAtom)
<*> pAtom,
pLExp
]