From: Michael Andreen Date: Tue, 28 Feb 2006 10:12:44 +0000 (+0000) Subject: smll stuff X-Git-Url: https://ruin.nu/git/?p=proglang.git;a=commitdiff_plain;h=80dc2356f0ac48fc4e026e549f85ad1a1d01834b smll stuff --- diff --git a/Typecheck.hs b/Typecheck.hs index 691b79b..770c079 100644 --- a/Typecheck.hs +++ b/Typecheck.hs @@ -76,7 +76,7 @@ typeCheckStm (SDecl t i e) = do t2 <- typeCheckExp e if t == t2 || t2 == NoType then do (m:ms) <- get - case insertLookupWithKey (\k a1 a2 -> a1) i t m of + case insertLookupWithKey (\k a1 a2 -> a1) i t m of (Nothing,m') -> put (m':ms) _ -> fail $ "Duplicate variable declaration: "++show i return NoType diff --git a/Typechecker.hs b/Typechecker.hs index 8705476..d9b1e10 100644 --- a/Typechecker.hs +++ b/Typechecker.hs @@ -40,6 +40,7 @@ run v p s = let ts = myLLexer s in case p ts of putStrLn "\nParse Successful!" showTree v (Program s) runStateT (mapM typeCheckStm s) [empty] + print "The program is type-correct!!" return () showTree :: (Show a, Print a) => Int -> a -> IO () diff --git a/examples/TypeCorrect b/examples/TypeCorrect new file mode 100644 index 0000000..85a6b2f --- /dev/null +++ b/examples/TypeCorrect @@ -0,0 +1,26 @@ +int a = readInt; +bool b = readBool; + +if (a < 3) { + print -a; +} +else + print a; + +while (! b){ + int a = a * 42 + readInt; + if ( a == 13) b = false; +} + +while ( a-- > 0) { + print a; +} + +while ( b = readBool){ + int c = readInt; + print c*a; +} + +bool c = readBool; + +if (c) print 42;