elna/lib/Language/Elna/SymbolTable.hs

46 lines
1.0 KiB
Haskell
Raw Normal View History

2024-07-26 12:22:07 +02:00
module Language.Elna.SymbolTable
( Info(..)
, ParameterInfo(..)
, SymbolTable(..)
, Type(..)
, booleanType
, intType
) where
import Data.HashMap.Strict (HashMap)
import Data.Text (Text)
import Data.Vector (Vector)
import Data.Word (Word32)
import Language.Elna.Location (Identifier(..), showArrayType)
data Type
= PrimitiveType Text
| ArrayType Word32 Type
deriving Eq
instance Show Type
where
show (PrimitiveType typeName) = show typeName
show (ArrayType elementCount typeName) = showArrayType elementCount typeName
intType :: Type
intType = PrimitiveType "int"
booleanType :: Type
booleanType = PrimitiveType "boolean"
newtype SymbolTable = SymbolTable (HashMap Identifier Info)
deriving (Eq, Show)
data ParameterInfo = ParameterInfo
{ name :: Identifier
, type' :: Type
, isReferenceParameter :: Bool
} deriving (Eq, Show)
data Info
= TypeInfo Type
| VariableInfo Type Bool
| ProcedureInfo SymbolTable (Vector ParameterInfo)
deriving (Eq, Show)