+
+type Types = Map Ident Type
+
+inList :: Eq a => a -> [a] -> Bool
+inList _ [] = False
+inList a (x:xs) = if a == x then True else inList a xs
+
+typeCheckExp :: (MonadState Types m) => Exp -> m Type
+typeCheckExp (BiOpExp e o e') = do
+ t1 <- typeCheckExp e
+ t2 <- typeCheckExp e'
+ if not(t1 == t2) then fail ""
+ else case inList o [Eq,NEq] of
+ True -> return TBool
+ False -> if not(t1 == TInt) then fail ""
+ else case inList o [Plus,Minus,Times,Div] of
+ True -> return TInt
+ False -> return TBool
+typeCheckExp (EVar i) = typeCheckVar i
+typeCheckExp (EAss i e) = do
+ a <- typeCheckVar i
+ b <- typeCheckExp e
+ if a == b then return a else fail "FEL!"
+typeCheckExp (EInt i) = return TInt
+typeCheckExp (EBool b) = return TBool
+typeCheckExp EReadI = return TInt
+typeCheckExp EReadB = return TBool
+typeCheckExp (ExpT t e) = do
+ t2 <- typeCheckExp e
+ if t == t2 then return t else fail "FEL!"
+typeCheckExp EDefault = return NoType
+typeCheckExp (EPost i op) = do
+ TInt <- typeCheckVar i