From c2c923276f7ecde1f71e53309dc5d1cc53cd3ff2 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sun, 29 Sep 2024 19:50:55 +0200 Subject: Implement addition and subtraction --- lib/Language/Elna/Parser.hs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'lib/Language/Elna/Parser.hs') diff --git a/lib/Language/Elna/Parser.hs b/lib/Language/Elna/Parser.hs index 5583601..3c98fff 100644 --- a/lib/Language/Elna/Parser.hs +++ b/lib/Language/Elna/Parser.hs @@ -4,7 +4,7 @@ module Language.Elna.Parser ) where import Control.Monad (void) -import Control.Monad.Combinators.Expr ({-Operator(..), -} makeExprParser) +import Control.Monad.Combinators.Expr (Operator(..), makeExprParser) import Data.Text (Text) import qualified Data.Text as Text import Data.Void (Void) @@ -69,38 +69,38 @@ termP = choice , LiteralExpression <$> literalP -- , VariableExpression <$> variableAccessP ] -{- -variableAccessP :: Parser VariableAccess -variableAccessP = do - identifier <- identifierP - indices <- many $ bracketsP expressionP - pure $ foldr (flip ArrayAccess) (VariableAccess identifier) indices operatorTable :: [[Operator Parser Expression]] operatorTable = - [ unaryOperator + [{- unaryOperator , factorOperator - , termOperator + ,-} termOperator ] where - unaryOperator = + {- unaryOperator = [ prefix "-" NegationExpression , prefix "+" id ] factorOperator = [ binary "*" ProductExpression , binary "/" DivisionExpression - ] + ] -} termOperator = [ binary "+" SumExpression , binary "-" SubtractionExpression ] - prefix name f = Prefix (f <$ symbol name) + -- prefix name f = Prefix (f <$ symbol name) binary name f = InfixL (f <$ symbol name) --} + expressionP :: Parser Expression -expressionP = makeExprParser termP [] -- operatorTable +expressionP = makeExprParser termP operatorTable {- +variableAccessP :: Parser VariableAccess +variableAccessP = do + identifier <- identifierP + indices <- many $ bracketsP expressionP + pure $ foldr (flip ArrayAccess) (VariableAccess identifier) indices + conditionP :: Parser Condition conditionP = do lhs <- expressionP @@ -204,8 +204,8 @@ statementP <$> variableAccessP <* symbol ":=" <*> expressionP - <* semicolonP --} + <* semicolonP -} + variableDeclarationP :: Parser VariableDeclaration variableDeclarationP = VariableDeclaration <$> (symbol "var" *> identifierP) -- cgit v1.2.3