Implement if statements with equality

This commit is contained in:
2024-10-11 16:14:01 +02:00
parent 87f183baad
commit 0850f0a8d6
12 changed files with 168 additions and 93 deletions

View File

@@ -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]