From 0850f0a8d66af028e32a79063cdad328b70db909 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Fri, 11 Oct 2024 16:14:01 +0200 Subject: Implement if statements with equality --- lib/Language/Elna/Frontend/Parser.hs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'lib/Language/Elna/Frontend/Parser.hs') diff --git a/lib/Language/Elna/Frontend/Parser.hs b/lib/Language/Elna/Frontend/Parser.hs index 9d6bb60..9dd3206 100644 --- a/lib/Language/Elna/Frontend/Parser.hs +++ b/lib/Language/Elna/Frontend/Parser.hs @@ -16,8 +16,8 @@ import Language.Elna.Frontend.AST , Statement(..) , TypeExpression(..) , VariableDeclaration(..) - {-, VariableAccess(..) - , Condition(..)-} + --, VariableAccess(..) + , Condition(..) , Expression(..) , Literal(..) ) @@ -97,7 +97,7 @@ variableAccessP = do identifier <- identifierP indices <- many $ bracketsP expressionP pure $ foldr (flip ArrayAccess) (VariableAccess identifier) indices - +-} conditionP :: Parser Condition conditionP = do lhs <- expressionP @@ -105,14 +105,14 @@ conditionP = do conditionCons lhs <$> expressionP where comparisonOperator = - [ symbol "<" >> pure LessCondition - , symbol "<=" >> pure LessOrEqualCondition - , symbol ">" >> pure GreaterCondition - , symbol ">=" >> pure GreaterOrEqualCondition - , symbol "=" >> pure EqualCondition - , symbol "#" >> pure NonEqualCondition + --, symbol "<" >> pure LessCondition + --, symbol "<=" >> pure LessOrEqualCondition + --, symbol ">" >> pure GreaterCondition + --, symbol ">=" >> pure GreaterOrEqualCondition + [ symbol "=" >> pure EqualCondition + --, symbol "#" >> pure NonEqualCondition ] --} + symbol :: Text -> Parser Text symbol = Lexer.symbol space @@ -182,22 +182,22 @@ procedureDeclarationP = procedureCons statementP :: Parser Statement statementP = EmptyStatement <$ semicolonP + <|> ifElseP {-<|> CompoundStatement <$> blockP (many statementP) <|> try assignmentP - <|> try ifElseP <|> try whileP -} - <|> try callP + <|> callP "statement" where callP = CallStatement <$> identifierP <*> parensP (sepBy expressionP commaP) <* semicolonP - {-ifElseP = IfStatement + ifElseP = IfStatement <$> (symbol "if" *> parensP conditionP) <*> statementP <*> optional (symbol "else" *> statementP) - whileP = WhileStatement + {-whileP = WhileStatement <$> (symbol "while" *> parensP conditionP) <*> statementP assignmentP = AssignmentStatement -- cgit v1.2.3