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/AST.hs | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'lib/Language/Elna/Frontend/AST.hs') diff --git a/lib/Language/Elna/Frontend/AST.hs b/lib/Language/Elna/Frontend/AST.hs index b9ed539..68ac581 100644 --- a/lib/Language/Elna/Frontend/AST.hs +++ b/lib/Language/Elna/Frontend/AST.hs @@ -6,8 +6,8 @@ module Language.Elna.Frontend.AST , Statement(..) , TypeExpression(..) , VariableDeclaration(..) - {-, VariableAccess(..) - , Condition(..)-} + --, VariableAccess(..) + , Condition(..) , Expression(..) , Literal(..) ) where @@ -67,8 +67,8 @@ instance Show TypeExpression data Statement = EmptyStatement - {-| AssignmentStatement VariableAccess Expression | IfStatement Condition Statement (Maybe Statement) + {-| AssignmentStatement VariableAccess Expression | WhileStatement Condition Statement -} | CompoundStatement [Statement] | CallStatement Identifier [Expression] @@ -77,13 +77,13 @@ data Statement instance Show Statement where show EmptyStatement = ";" - {-show (AssignmentStatement lhs rhs) = - concat [show lhs, " := ", show rhs, ";"] show (IfStatement condition if' else') = concat [ "if (", show condition, ") " , show if' , maybe "" ((<> " else ") . show) else' ] + {-show (AssignmentStatement lhs rhs) = + concat [show lhs, " := ", show rhs, ";"] show (WhileStatement expression statement) = concat ["while (", show expression, ") ", show statement, ";"]-} show (CompoundStatement statements) = @@ -143,22 +143,21 @@ instance Show VariableAccess show (VariableAccess variableName) = show variableName show (ArrayAccess arrayAccess elementIndex) = concat [show arrayAccess, "[", show elementIndex, "]"] - +-} data Condition = EqualCondition Expression Expression - | NonEqualCondition Expression Expression - | LessCondition Expression Expression - | GreaterCondition Expression Expression - | LessOrEqualCondition Expression Expression - | GreaterOrEqualCondition Expression Expression + -- | NonEqualCondition Expression Expression + -- | LessCondition Expression Expression + -- | GreaterCondition Expression Expression + -- | LessOrEqualCondition Expression Expression + -- | GreaterOrEqualCondition Expression Expression deriving Eq instance Show Condition where show (EqualCondition lhs rhs) = concat [show lhs, " = ", show rhs] - show (NonEqualCondition lhs rhs) = concat [show lhs, " # ", show rhs] - show (LessCondition lhs rhs) = concat [show lhs, " < ", show rhs] - show (GreaterCondition lhs rhs) = concat [show lhs, " > ", show rhs] - show (LessOrEqualCondition lhs rhs) = concat [show lhs, " <= ", show rhs] - show (GreaterOrEqualCondition lhs rhs) = concat [show lhs, " >= ", show rhs] --} + -- show (NonEqualCondition lhs rhs) = concat [show lhs, " # ", show rhs] + -- show (LessCondition lhs rhs) = concat [show lhs, " < ", show rhs] + -- show (GreaterCondition lhs rhs) = concat [show lhs, " > ", show rhs] + -- show (LessOrEqualCondition lhs rhs) = concat [show lhs, " <= ", show rhs] + -- show (GreaterOrEqualCondition lhs rhs) = concat [show lhs, " >= ", show rhs] -- cgit v1.2.3