X-Git-Url: https://ruin.nu/git/?p=proglang.git;a=blobdiff_plain;f=Printsyntax.hs;h=287fbaefe878444e73a106d2d33887fed4c3856a;hp=ff0128e8d8f68a0398d6b154dc5478968c19a4c6;hb=HEAD;hpb=565fbd61dca527c23888e08783d0d91cee458524 diff --git a/Printsyntax.hs b/Printsyntax.hs index ff0128e..287fbae 100644 --- a/Printsyntax.hs +++ b/Printsyntax.hs @@ -93,20 +93,22 @@ 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 prt i e = case e of SExp exp -> prPrec i 0 (concatD [prt 0 exp , doc (showString ";")]) SBlock stms -> prPrec i 0 (concatD [doc (showString "{") , prt 0 stms , doc (showString "}")]) + 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 ";")]) + SReturn exp -> prPrec i 0 (concatD [doc (showString "return") , 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 []) @@ -122,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