X-Git-Url: https://ruin.nu/git/?p=proglang.git;a=blobdiff_plain;f=Printsyntax.hs;h=ff0128e8d8f68a0398d6b154dc5478968c19a4c6;hp=e84a1d333e8c46d73773924fa4869e035a7d191e;hb=565fbd61dca527c23888e08783d0d91cee458524;hpb=3cee522d1f54b39a1efa654da364c6c939cbcf1f diff --git a/Printsyntax.hs b/Printsyntax.hs index e84a1d3..ff0128e 100644 --- a/Printsyntax.hs +++ b/Printsyntax.hs @@ -87,15 +87,26 @@ 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]) 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 []) + SDecl type' id exp -> prPrec i 0 (concatD [prt 0 type' , prt 0 id , doc (showString "=") , prt 0 exp , doc (showString ";")]) prtList es = case es of [] -> (concatD []) @@ -106,22 +117,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]) + 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]) - EBool bool -> prPrec i 3 (concatD [prt 0 bool]) 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 "<")]) @@ -136,11 +140,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 []) - -