summaryrefslogtreecommitdiff
path: root/lib/Language/Elna/Frontend/AST.hs
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2024-10-04 18:26:10 +0200
committerEugen Wissner <belka@caraus.de>2024-10-04 18:26:10 +0200
commit35742aa52587400950cf25170c2247f98f498d4d (patch)
tree78d0fd208e2e08d30c18ada33c52bc76a91267d6 /lib/Language/Elna/Frontend/AST.hs
parentfdf56ce9d0de459dc5bd65537847ded7b02ad5c2 (diff)
downloadelna-35742aa52587400950cf25170c2247f98f498d4d.tar.gz
Add printc and exit builtin functions
Diffstat (limited to 'lib/Language/Elna/Frontend/AST.hs')
-rw-r--r--lib/Language/Elna/Frontend/AST.hs31
1 files changed, 13 insertions, 18 deletions
diff --git a/lib/Language/Elna/Frontend/AST.hs b/lib/Language/Elna/Frontend/AST.hs
index 738ddcc..4c1c20b 100644
--- a/lib/Language/Elna/Frontend/AST.hs
+++ b/lib/Language/Elna/Frontend/AST.hs
@@ -12,10 +12,12 @@ module Language.Elna.Frontend.AST
, Literal(..)
) where
+import Data.Char (chr)
import Data.Int (Int32)
import Data.List (intercalate)
-import Data.Word ({-Word16, -}Word32)
+import Data.Word (Word8, Word32)
import Language.Elna.Location (Identifier(..), showArrayType)
+import Numeric (showHex)
newtype Program = Program [Declaration]
deriving Eq
@@ -67,8 +69,8 @@ data Statement
= EmptyStatement
{-| AssignmentStatement VariableAccess Expression
| IfStatement Condition Statement (Maybe Statement)
- | WhileStatement Condition Statement
- | CompoundStatement [Statement]-}
+ | WhileStatement Condition Statement -}
+ | CompoundStatement [Statement]
| CallStatement Identifier [Expression]
deriving Eq
@@ -83,9 +85,9 @@ instance Show Statement
, maybe "" ((<> " else ") . show) else'
]
show (WhileStatement expression statement) =
- concat ["while (", show expression, ") ", show 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) <> ")"
@@ -93,22 +95,18 @@ data VariableDeclaration =
VariableDeclaration Identifier TypeExpression
deriving Eq
-newtype Literal
+data Literal
= IntegerLiteral Int32
- {- | HexadecimalLiteral Int32
- | CharacterLiteral Word16
- | BooleanLiteral Bool -}
+ | HexadecimalLiteral Int32
+ | CharacterLiteral Word8
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" -}
instance Show VariableDeclaration
where
@@ -120,8 +118,8 @@ data Expression
| SumExpression Expression Expression
| SubtractionExpression Expression Expression
| NegationExpression Expression
-{- | VariableExpression VariableAccess
| ProductExpression Expression Expression
+{- | VariableExpression VariableAccess
| DivisionExpression Expression Expression -}
deriving Eq
@@ -131,13 +129,10 @@ instance Show Expression
show (SumExpression lhs rhs) = concat [show lhs, " + ", show rhs]
show (SubtractionExpression lhs rhs) = concat [show lhs, " - ", show rhs]
show (NegationExpression negation) = '-' : show negation
- {- show (VariableExpression variable) = show variable
show (ProductExpression lhs rhs) = concat [show lhs, " * ", show rhs]
+ {- show (VariableExpression variable) = show variable
show (DivisionExpression lhs rhs) = concat [show lhs, " / ", show rhs] -}
{-
-import Data.Char (chr)
-import Numeric (showHex)
-
data VariableAccess
= VariableAccess Identifier
| ArrayAccess VariableAccess Expression