X-Git-Url: https://ruin.nu/git/?p=proglang.git;a=blobdiff_plain;f=Printsyntax.hs;h=d1b4c4962d5b0a37e4d40bfec23c249040213763;hp=feb0b2332dce7a464f6db733404e1df969d77f70;hb=d553df8dfdffca78342d6fae142ceded9cd64415;hpb=6103c0359b95557566aa9154efa5bcd4d9c996f6 diff --git a/Printsyntax.hs b/Printsyntax.hs index feb0b23..d1b4c49 100644 --- a/Printsyntax.hs +++ b/Printsyntax.hs @@ -87,13 +87,25 @@ instance Print Bool where False -> prPrec i 0 (concatD [doc (showString "false")]) +instance Print Type where + prt i e = case e of + TInt -> prPrec i 0 (concatD [doc (showString "int")]) + TBool -> prPrec i 0 (concatD [doc (showString "bool")]) + + +instance Print Stms where + prt i e = case e of + Program stms -> prPrec i 0 (concatD [prt 0 stms]) + + instance Print Stm where prt i e = case e of - SDecl type' id exp -> prPrec i 0 (concatD [prt 0 type' , prt 0 id , doc (showString "=") , prt 0 exp , doc (showString ";")]) SExp exp -> prPrec i 0 (concatD [prt 0 exp , doc (showString ";")]) SBlock stms -> prPrec i 0 (concatD [doc (showString "{") , prt 0 stms , doc (showString "}")]) - 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]) + SDecl type' id exp -> prPrec i 0 (concatD [prt 0 type' , prt 0 id , doc (showString "=") , prt 0 exp , doc (showString ";")]) + SDeclD type' id -> prPrec i 0 (concatD [prt 0 type' , prt 0 id , doc (showString ";")]) 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 ";")]) SNoop -> prPrec i 0 (concatD []) @@ -106,21 +118,15 @@ instance Print Exp where EAss id exp -> prPrec i 0 (concatD [prt 0 id , doc (showString "=") , prt 0 exp]) EVar id -> prPrec i 3 (concatD [prt 0 id]) 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]) + ENeg exp -> prPrec i 3 (concatD [doc (showString "-") , prt 3 exp]) + 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")]) - ExpT type' exp -> prPrec i 0 (concatD [prt 0 type' , prt 0 exp]) - EDefault -> prPrec i 0 (concatD []) 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]) -instance Print Stms where - prt i e = case e of - Program stms -> prPrec i 0 (concatD [prt 0 stms]) - - instance Print Op where prt i e = case e of Lt -> prPrec i 0 (concatD [doc (showString "<")]) @@ -135,11 +141,4 @@ instance Print Op where Div -> prPrec i 2 (concatD [doc (showString "/")]) -instance Print Type where - prt i e = case e of - TInt -> prPrec i 0 (concatD [doc (showString "int")]) - TBool -> prPrec i 0 (concatD [doc (showString "bool")]) - NoType -> prPrec i 0 (concatD []) - -