]> ruin.nu Git - proglang.git/commitdiff
smll stuff
authorMichael Andreen <harv@ruin.nu>
Tue, 28 Feb 2006 10:12:44 +0000 (10:12 +0000)
committerMichael Andreen <harv@ruin.nu>
Tue, 28 Feb 2006 10:12:44 +0000 (10:12 +0000)
Typecheck.hs
Typechecker.hs
examples/TypeCorrect [new file with mode: 0644]

index 691b79b269350f18a31e463fc04d72c106502609..770c079e4bf73259e4a77d36cabc4aaccb310c1e 100644 (file)
@@ -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
index 87054767c896ee26b405b0af976f0b4bd09f5050..d9b1e1047b67d8b355dca3290ac93173b4e0417d 100644 (file)
@@ -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 (file)
index 0000000..85a6b2f
--- /dev/null
@@ -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;