summaryrefslogtreecommitdiff
path: root/lib/Language/Elna/SymbolTable.hs
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2024-07-29 08:26:47 +0300
committerEugen Wissner <belka@caraus.de>2024-07-29 08:26:47 +0300
commit92990e52f017c3fa0b9ff99f517171051d8c7c18 (patch)
treeb141a70bbd7fb9454c34f042605791e85d0522a5 /lib/Language/Elna/SymbolTable.hs
parentce7652c6189b289ffbc749dc3d1ffb465c758c01 (diff)
downloadelna-92990e52f017c3fa0b9ff99f517171051d8c7c18.tar.gz
Add typeExpression to type converter
Diffstat (limited to 'lib/Language/Elna/SymbolTable.hs')
-rw-r--r--lib/Language/Elna/SymbolTable.hs46
1 files changed, 26 insertions, 20 deletions
diff --git a/lib/Language/Elna/SymbolTable.hs b/lib/Language/Elna/SymbolTable.hs
index a33df44..ba2e41f 100644
--- a/lib/Language/Elna/SymbolTable.hs
+++ b/lib/Language/Elna/SymbolTable.hs
@@ -1,36 +1,42 @@
module Language.Elna.SymbolTable
( Info(..)
, ParameterInfo(..)
- , SymbolTable(..)
- , Type(..)
- , booleanType
- , intType
+ , SymbolTable
+ , enter
+ , lookup
+ , symbolTable
) where
import Data.HashMap.Strict (HashMap)
-import Data.Text (Text)
+import qualified Data.HashMap.Strict as HashMap
import Data.Vector (Vector)
-import Data.Word (Word32)
-import Language.Elna.Location (Identifier(..), showArrayType)
+import Language.Elna.Location (Identifier(..))
+import Language.Elna.Types (Type(..), intType, booleanType)
+import Prelude hiding (lookup)
-data Type
- = PrimitiveType Text
- | ArrayType Word32 Type
- deriving Eq
+newtype SymbolTable = SymbolTable (HashMap Identifier Info)
+ deriving (Eq, Show)
+
+instance Semigroup SymbolTable
+ where
+ (SymbolTable lhs) <> (SymbolTable rhs) = SymbolTable $ rhs <> lhs
-instance Show Type
+instance Monoid SymbolTable
where
- show (PrimitiveType typeName) = show typeName
- show (ArrayType elementCount typeName) = showArrayType elementCount typeName
+ mempty = SymbolTable HashMap.empty
-intType :: Type
-intType = PrimitiveType "int"
+symbolTable :: SymbolTable
+symbolTable = SymbolTable $ HashMap.fromList
+ [ ("boolean", TypeInfo booleanType)
+ , ("int", TypeInfo intType)
+ ]
-booleanType :: Type
-booleanType = PrimitiveType "boolean"
+enter :: Identifier -> Info -> SymbolTable -> SymbolTable
+enter identifier info (SymbolTable table) = SymbolTable
+ $ HashMap.insert identifier info table
-newtype SymbolTable = SymbolTable (HashMap Identifier Info)
- deriving (Eq, Show)
+lookup :: Identifier -> SymbolTable -> Maybe Info
+lookup identifier (SymbolTable table) = HashMap.lookup identifier table
data ParameterInfo = ParameterInfo
{ name :: Identifier