summaryrefslogtreecommitdiff
path: root/lib/Language/Elna/AST.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Language/Elna/AST.hs')
-rw-r--r--lib/Language/Elna/AST.hs70
1 files changed, 35 insertions, 35 deletions
diff --git a/lib/Language/Elna/AST.hs b/lib/Language/Elna/AST.hs
index 8f66bdc..087c2fd 100644
--- a/lib/Language/Elna/AST.hs
+++ b/lib/Language/Elna/AST.hs
@@ -7,11 +7,12 @@ module Language.Elna.AST
, TypeExpression(..)
, VariableDeclaration(..)
{-, VariableAccess(..)
- , Condition(..)
+ , Condition(..)-}
, Expression(..)
- , Literal(..)-}
+ , Literal(..)
) where
+import Data.Int (Int32)
import Data.List (intercalate)
import Data.Word ({-Word16, -}Word32)
import Language.Elna.Location (Identifier(..), showArrayType)
@@ -67,8 +68,8 @@ data Statement
{-| AssignmentStatement VariableAccess Expression
| IfStatement Condition Statement (Maybe Statement)
| WhileStatement Condition Statement
- | CompoundStatement [Statement]
- | CallStatement Identifier [Expression]-}
+ | CompoundStatement [Statement]-}
+ | CallStatement Identifier [Expression]
deriving Eq
instance Show Statement
@@ -84,70 +85,69 @@ instance Show Statement
show (WhileStatement expression statement) =
concat ["while (", show expression, ") ", show statement, ";"]
show (CompoundStatement statements) =
- concat ["{\n", unlines (show <$> statements), " }"]
+ concat ["{\n", unlines (show <$> statements), " }"]-}
show (CallStatement name parameters) = show name <> "("
- <> intercalate ", " (show <$> parameters) <> ")"-}
+ <> intercalate ", " (show <$> parameters) <> ")"
data VariableDeclaration =
VariableDeclaration Identifier TypeExpression
deriving Eq
-instance Show VariableDeclaration
- where
- show (VariableDeclaration identifier typeExpression) =
- concat ["var ", show identifier, ": " <> show typeExpression, ";"]
-{-
-import Data.Int (Int32)
-import Data.Char (chr)
-import Numeric (showHex)
-
-data Literal
+newtype Literal
= IntegerLiteral Int32
- | HexadecimalLiteral Int32
+ {- | HexadecimalLiteral Int32
| CharacterLiteral Word16
- | BooleanLiteral Bool
+ | BooleanLiteral Bool -}
deriving Eq
instance Show Literal
where
show (IntegerLiteral integer) = show integer
- show (HexadecimalLiteral integer) = '0' : 'x' : showHex integer ""
+ {- show (HexadecimalLiteral integer) = '0' : 'x' : showHex integer ""
show (CharacterLiteral character) =
'\'' : chr (fromEnum character) : ['\'']
show (BooleanLiteral boolean)
| boolean = "true"
- | otherwise = "false"
+ | otherwise = "false" -}
-data VariableAccess
- = VariableAccess Identifier
- | ArrayAccess VariableAccess Expression
- deriving Eq
-
-instance Show VariableAccess
+instance Show VariableDeclaration
where
- show (VariableAccess variableName) = show variableName
- show (ArrayAccess arrayAccess elementIndex) =
- concat [show arrayAccess, "[", show elementIndex, "]"]
+ show (VariableDeclaration identifier typeExpression) =
+ concat ["var ", show identifier, ": " <> show typeExpression, ";"]
-data Expression
- = VariableExpression VariableAccess
- | LiteralExpression Literal
+newtype Expression
+ = LiteralExpression Literal
+{- | VariableExpression VariableAccess
| NegationExpression Expression
| SumExpression Expression Expression
| SubtractionExpression Expression Expression
| ProductExpression Expression Expression
- | DivisionExpression Expression Expression
+ | DivisionExpression Expression Expression -}
deriving Eq
instance Show Expression
where
- show (VariableExpression variable) = show variable
show (LiteralExpression literal) = show literal
+ {- show (VariableExpression variable) = show variable
show (NegationExpression negation) = '-' : show negation
show (SumExpression lhs rhs) = concat [show lhs, " + ", show rhs]
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 (DivisionExpression lhs rhs) = concat [show lhs, " / ", show rhs] -}
+{-
+import Data.Char (chr)
+import Numeric (showHex)
+
+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 Condition
= EqualCondition Expression Expression