typeCheckStm (SWhile e s) = do
TBool <- typeCheckExp e
pushAndPop $ typeCheckStm s
+typeCheckStm (SDeclD t i) = addVariable i t
typeCheckStm (SDecl t i e) = do
t2 <- typeCheckExp e
assert (t == t2) $ "Illegal to assign an expression of type "++show t2++" to variable "++show i++" of type "++show t
+ addVariable i t
+typeCheckStm (SPrint e) = do
+ typeCheckExp e
+ return ()
+
+addVariable :: (MonadState Types m) => Ident -> Type -> m ()
+addVariable i t = do
(m:ms) <- get
case insertLookupWithKey (\k a1 a2 -> a1) i t m of
(Nothing,m') -> put (m':ms)
_ -> fail $ "Duplicate variable declaration: "++show i
-typeCheckStm (SPrint e) = do
- typeCheckExp e
- return ()