]> ruin.nu Git - proglang.git/commitdiff
moved modified Testsyntax to Typechecker to keep the original one
authorMichael Andreen <harv@ruin.nu>
Sun, 26 Feb 2006 21:26:14 +0000 (21:26 +0000)
committerMichael Andreen <harv@ruin.nu>
Sun, 26 Feb 2006 21:26:14 +0000 (21:26 +0000)
Docsyntax.tex
Makefile
Parsyntax.y
Printsyntax.hs
Skelsyntax.hs
Testsyntax.hs
Typechecker.hs [new file with mode: 0644]

index a4040dc8da604ba2614e495033c45b9c03029ef7..76d4a279cb7e9486db34d88dbffe3dddd165d14f 100644 (file)
@@ -83,8 +83,8 @@ All other symbols are terminals.\\
 \end{tabular}\\
 
 \begin{tabular}{lll}
-{\nonterminal{Exp}} & {\arrow}  &{\nonterminal{Exp1}} {\nonterminal{BOp}} {\nonterminal{Exp1}}  \\
- & {\delimit}  &{\nonterminal{Ident}} {\terminal{{$=$}}} {\nonterminal{Exp}}  \\
+{\nonterminal{Exp}} & {\arrow}  &{\nonterminal{Ident}} {\terminal{{$=$}}} {\nonterminal{Exp}}  \\
+ & {\delimit}  &{\nonterminal{Exp1}} {\nonterminal{BOp}} {\nonterminal{Exp1}}  \\
  & {\delimit}  &{\nonterminal{Exp1}}  \\
 \end{tabular}\\
 
@@ -107,11 +107,7 @@ All other symbols are terminals.\\
  & {\delimit}  &{\nonterminal{Bool}}  \\
  & {\delimit}  &{\terminal{readInt}}  \\
  & {\delimit}  &{\terminal{readBool}}  \\
- & {\delimit}  &{\nonterminal{Exp4}}  \\
-\end{tabular}\\
-
-\begin{tabular}{lll}
-{\nonterminal{Exp4}} & {\arrow}  &{\terminal{(}} {\nonterminal{Exp}} {\terminal{)}}  \\
+ & {\delimit}  &{\terminal{(}} {\nonterminal{Exp}} {\terminal{)}}  \\
 \end{tabular}\\
 
 \begin{tabular}{lll}
index 883c65fc997e911fa25d0a2a366ddc02f3c85490..fe345b456c3c7f00c512d080884fbaf66a810a24 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,8 @@ all:
        happy -gca -idebug Parsyntax.y
        alex -g Lexsyntax.x
        latex Docsyntax.tex; dvips Docsyntax.dvi -o Docsyntax.ps
-       ghc -fglasgow-exts --make Testsyntax.hs -o Testsyntax
+       ghc --make Testsyntax.hs -o Testsyntax
+       ghc -fglasgow-exts --make Typechecker.hs -o Typechecker
 clean:
        -rm -f *.log *.aux *.hi *.o *.dvi
        -rm -f Docsyntax.ps
index 8bf7c6812d4ca3074be5f2e493c57b5359353263..f75fff6d2eebaa3458074b030d5c7b70b0de7f1d 100644 (file)
@@ -70,8 +70,8 @@ Stm : Type Ident '=' Exp ';' { SDecl $1 $2 $4 }
 
 
 Exp :: { Exp }
-Exp : Exp1 BOp Exp1 { BExp $1 $2 $3 } 
-  | Ident '=' Exp { EAss $1 $3 }
+Exp : Ident '=' Exp { EAss $1 $3 } 
+  | Exp1 BOp Exp1 { BExp $1 $2 $3 }
   | Exp1 { $1 }
 
 
@@ -94,11 +94,7 @@ Exp3 : Ident '++' { postIncr_ $1 }
   | Bool { EBool $1 }
   | 'readInt' { EReadI }
   | 'readBool' { EReadB }
-  | Exp4 { $1 }
-
-
-Exp4 :: { Exp }
-Exp4 : '(' Exp ')' { $2 } 
+  | '(' Exp ')' { $2 }
 
 
 ListStm :: { [Stm] }
index 1d1068749e5bc7d85c4411c7eb9efdf905125d07..0e549511ce4275a12b895072d1a216b7f8bf45e8 100644 (file)
@@ -103,9 +103,9 @@ instance Print Stm where
 
 instance Print Exp where
   prt i e = case e of
+   EAss id exp -> prPrec i 0 (concatD [prt 0 id , doc (showString "=") , prt 0 exp])
    BExp exp0 bop exp -> prPrec i 0 (concatD [prt 1 exp0 , prt 0 bop , prt 1 exp])
    EVar id -> prPrec i 3 (concatD [prt 0 id])
-   EAss id exp -> prPrec i 0 (concatD [prt 0 id , doc (showString "=") , prt 0 exp])
    EInt n -> prPrec i 3 (concatD [prt 0 n])
    ENeg exp -> prPrec i 3 (concatD [doc (showString "-") , prt 3 exp])
    EBool bool -> prPrec i 3 (concatD [prt 0 bool])
index c1af30729a27da27cf5d3a1f820bc0ffaf8ebbf1..8a3605383704b6bf4c3a36e6e4936be53876cfec 100644 (file)
@@ -33,9 +33,9 @@ transStm x = case x of
 
 transExp :: Exp -> Result
 transExp x = case x of
+  EAss id exp  -> failure x
   BExp exp0 bop exp  -> failure x
   EVar id  -> failure x
-  EAss id exp  -> failure x
   EInt n  -> failure x
   ENeg exp  -> failure x
   EBool bool  -> failure x
index fb6986c317591f0b732b6cb8283c8b132cb768e9..45f35b972d017946d22cb22f57d36d3a3b3fb690 100644 (file)
@@ -11,10 +11,6 @@ import Skelsyntax
 import Printsyntax
 import Abssyntax
 
-import Typecheck
-import Control.Monad.State
-import Data.Map as Map hiding (showTree)
-
 
 
 
@@ -29,21 +25,19 @@ type Verbosity = Int
 putStrV :: Verbosity -> String -> IO ()
 putStrV v s = if v > 1 then putStrLn s else return ()
 
-runFile :: Verbosity -> ParseFun Stms -> FilePath -> IO ()
+runFile :: (Print a, Show a) => Verbosity -> ParseFun a -> FilePath -> IO ()
 runFile v p f = putStrLn f >> readFile f >>= run v p
 
-run :: Verbosity -> ParseFun Stms -> String -> IO ()
+run :: (Print a, Show a) => Verbosity -> ParseFun a -> String -> IO ()
 run v p s = let ts = myLLexer s in case p ts of
-       Bad s    -> do
-               putStrLn "\nParse              Failed...\n"
-               putStrV v "Tokens:"
-               putStrV v $ show ts
-               putStrLn s
-       Ok (Program s) -> do
-               putStrLn "\nParse Successful!"
-               showTree v (Program s)
-               runStateT (mapM typeCheckStm s) empty
-               return ()
+           Bad s    -> do putStrLn "\nParse              Failed...\n"
+                          putStrV v "Tokens:"
+                          putStrV v $ show ts
+                          putStrLn s
+           Ok  tree -> do putStrLn "\nParse Successful!"
+                          showTree v tree
+
+
 
 showTree :: (Show a, Print a) => Int -> a -> IO ()
 showTree v tree
diff --git a/Typechecker.hs b/Typechecker.hs
new file mode 100644 (file)
index 0000000..fb6986c
--- /dev/null
@@ -0,0 +1,64 @@
+-- automatically generated by BNF Converter
+module Main where
+
+
+import IO ( stdin, hGetContents )
+import System ( getArgs, getProgName )
+
+import Lexsyntax
+import Parsyntax
+import Skelsyntax
+import Printsyntax
+import Abssyntax
+
+import Typecheck
+import Control.Monad.State
+import Data.Map as Map hiding (showTree)
+
+
+
+
+import ErrM
+
+type ParseFun a = [Token] -> Err a
+
+myLLexer = myLexer
+
+type Verbosity = Int
+
+putStrV :: Verbosity -> String -> IO ()
+putStrV v s = if v > 1 then putStrLn s else return ()
+
+runFile :: Verbosity -> ParseFun Stms -> FilePath -> IO ()
+runFile v p f = putStrLn f >> readFile f >>= run v p
+
+run :: Verbosity -> ParseFun Stms -> String -> IO ()
+run v p s = let ts = myLLexer s in case p ts of
+       Bad s    -> do
+               putStrLn "\nParse              Failed...\n"
+               putStrV v "Tokens:"
+               putStrV v $ show ts
+               putStrLn s
+       Ok (Program s) -> do
+               putStrLn "\nParse Successful!"
+               showTree v (Program s)
+               runStateT (mapM typeCheckStm s) empty
+               return ()
+
+showTree :: (Show a, Print a) => Int -> a -> IO ()
+showTree v tree
+ = do
+      putStrV v $ "\n[Abstract Syntax]\n\n" ++ show tree
+      putStrV v $ "\n[Linearized tree]\n\n" ++ printTree tree
+
+main :: IO ()
+main = do args <- getArgs
+          case args of
+            [] -> hGetContents stdin >>= run 2 pStms
+            "-s":fs -> mapM_ (runFile 0 pStms) fs
+            fs -> mapM_ (runFile 2 pStms) fs
+
+
+
+
+