diff options
Diffstat (limited to 'lib/Language/Elna/AST.hs')
| -rw-r--r-- | lib/Language/Elna/AST.hs | 56 |
1 files changed, 36 insertions, 20 deletions
diff --git a/lib/Language/Elna/AST.hs b/lib/Language/Elna/AST.hs index 189fcb5..ac86e63 100644 --- a/lib/Language/Elna/AST.hs +++ b/lib/Language/Elna/AST.hs @@ -1,5 +1,7 @@ module Language.Elna.AST - ( Declaration(..) + ( VariableAccess(..) + , Condition(..) + , Declaration(..) , Expression(..) , Identifier(..) , Literal(..) @@ -44,21 +46,25 @@ instance Show Literal | boolean = "true" | otherwise = "false" +data VariableAccess + = VariableAccess Identifier + | ArrayAccess VariableAccess Expression + deriving Eq + +instance Show VariableAccess + where + show (VariableAccess variableName) = show variableName + show (ArrayAccess arrayAccess elementIndex) = + concat [show arrayAccess, "[", show elementIndex, "]"] + data Expression - = VariableExpression Identifier + = VariableExpression VariableAccess | LiteralExpression Literal | NegationExpression Expression | SumExpression Expression Expression | SubtractionExpression Expression Expression | ProductExpression Expression Expression | DivisionExpression Expression Expression - | EqualExpression Expression Expression - | NonEqualExpression Expression Expression - | LessExpression Expression Expression - | GreaterExpression Expression Expression - | LessOrEqualExpression Expression Expression - | GreaterOrEqualExpression Expression Expression - | ArrayExpression Expression Expression deriving Eq instance Show Expression @@ -70,20 +76,30 @@ instance Show Expression show (SubtractionExpression lhs rhs) = concat [show lhs, " - ", show rhs] show (ProductExpression lhs rhs) = concat [show lhs, " * ", show rhs] show (DivisionExpression lhs rhs) = concat [show lhs, " / ", show rhs] - show (EqualExpression lhs rhs) = concat [show lhs, " = ", show rhs] - show (NonEqualExpression lhs rhs) = concat [show lhs, " # ", show rhs] - show (LessExpression lhs rhs) = concat [show lhs, " < ", show rhs] - show (GreaterExpression lhs rhs) = concat [show lhs, " > ", show rhs] - show (LessOrEqualExpression lhs rhs) = concat [show lhs, " <= ", show rhs] - show (GreaterOrEqualExpression lhs rhs) = concat [show lhs, " >= ", show rhs] - show (ArrayExpression arrayExpression indexExpression) = - concat [show arrayExpression, "[", show indexExpression, "]"] + +data Condition + = EqualCondition 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] data Statement = EmptyStatement - | AssignmentStatement Expression Expression - | IfStatement Expression Statement (Maybe Statement) - | WhileStatement Expression Statement + | AssignmentStatement VariableAccess Expression + | IfStatement Condition Statement (Maybe Statement) + | WhileStatement Condition Statement | CompoundStatement [Statement] | CallStatement Identifier [Expression] deriving Eq |
