]> ruin.nu Git - proglang.git/blobdiff - Printsyntax.hs
minor change
[proglang.git] / Printsyntax.hs
index d1b4c4962d5b0a37e4d40bfec23c249040213763..287fbaefe878444e73a106d2d33887fed4c3856a 100644 (file)
@@ -93,9 +93,9 @@ instance Print Type where
    TBool  -> prPrec i 0 (concatD [doc (showString "bool")])
 
 
-instance Print Stms where
+instance Print Program where
   prt i e = case e of
-   Program stms -> prPrec i 0 (concatD [prt 0 stms])
+   Program funcstms -> prPrec i 0 (concatD [prt 0 funcstms])
 
 
 instance Print Stm where
@@ -107,6 +107,7 @@ instance Print Stm where
    SWhile exp stm -> prPrec i 0 (concatD [doc (showString "while") , doc (showString "(") , prt 0 exp , doc (showString ")") , prt 0 stm])
    SIf exp stm0 stm -> prPrec i 0 (concatD [doc (showString "if") , doc (showString "(") , prt 0 exp , doc (showString ")") , prt 0 stm0 , doc (showString "else") , prt 0 stm])
    SPrint exp -> prPrec i 0 (concatD [doc (showString "print") , prt 0 exp , doc (showString ";")])
+   SReturn exp -> prPrec i 0 (concatD [doc (showString "return") , prt 0 exp , doc (showString ";")])
    SNoop  -> prPrec i 0 (concatD [])
 
   prtList es = case es of
@@ -123,9 +124,40 @@ instance Print Exp where
    ENot exp -> prPrec i 3 (concatD [doc (showString "!") , prt 3 exp])
    EReadI  -> prPrec i 3 (concatD [doc (showString "readInt")])
    EReadB  -> prPrec i 3 (concatD [doc (showString "readBool")])
+   EFunc id exps -> prPrec i 3 (concatD [prt 0 id , doc (showString "(") , prt 0 exps , doc (showString ")")])
    BiOpExp exp0 op exp -> prPrec i 0 (concatD [prt 0 exp0 , prt 0 op , prt 0 exp])
    EPost id op -> prPrec i 0 (concatD [prt 0 id , prt 1 op])
 
+  prtList es = case es of
+   [] -> (concatD [])
+   [x] -> (concatD [prt 0 x])
+   x:xs -> (concatD [prt 0 x , doc (showString ",") , prt 0 xs])
+
+instance Print Decl where
+  prt i e = case e of
+   Decl type' id -> prPrec i 0 (concatD [prt 0 type' , prt 0 id])
+
+  prtList es = case es of
+   [] -> (concatD [])
+   [x] -> (concatD [prt 0 x])
+   x:xs -> (concatD [prt 0 x , doc (showString ",") , prt 0 xs])
+
+instance Print Func where
+  prt i e = case e of
+   Func type' id decls stms -> prPrec i 0 (concatD [prt 0 type' , prt 0 id , doc (showString "(") , prt 0 decls , doc (showString ")") , doc (showString "{") , prt 0 stms , doc (showString "}")])
+
+  prtList es = case es of
+   [] -> (concatD [])
+   x:xs -> (concatD [prt 0 x , prt 0 xs])
+
+instance Print FuncStm where
+  prt i e = case e of
+   S stm -> prPrec i 0 (concatD [prt 0 stm])
+   F func -> prPrec i 0 (concatD [prt 0 func])
+
+  prtList es = case es of
+   [] -> (concatD [])
+   x:xs -> (concatD [prt 0 x , prt 0 xs])
 
 instance Print Op where
   prt i e = case e of