findVariable i [] = fail $ "Variable "++show i++" not found in any scope."
findVariable i (m:ms) = if member i m then lookup i m else findVariable i ms
findVariable i [] = fail $ "Variable "++show i++" not found in any scope."
findVariable i (m:ms) = if member i m then lookup i m else findVariable i ms
typeCheckStm :: (MonadState Types m) => Stm -> m ()
typeCheckStm SNoop = return ()
typeCheckStm (SExp e) = do
typeCheckExp e
return ()
typeCheckStm :: (MonadState Types m) => Stm -> m ()
typeCheckStm SNoop = return ()
typeCheckStm (SExp e) = do
typeCheckExp e
return ()
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
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