Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- doc_type :: Type -> Doc
- doc_type TVoid = text "void"
- doc_type TInt = text "int"
- doc_type TFloat = text "float"
- doc_type TChar = text "char"
- doc_type (TPtr tp) = (doc_type tp) <> text "*"
- doc_type (TStruct str) = text "struct" <+> text str
- exp_doc :: Exp -> Doc
- exp_doc (EIdent str) = text str
- exp_doc (ELit either) = if isLeft either
- then text (show (head (lefts [either])))
- else text (rights [either])
- exp_doc (EBinOp str exp1 exp2) = exp_doc exp1 <+> text str <+> exp_doc exp2
- exp_doc (EUnOpPre str exp) = text str <> exp_doc exp
- exp_doc (EUnOpPost str exp) = exp_doc exp <> text str
- exp_doc (EFunCall exp exps) = exp_doc exp <> text "("
- <> exp_list_concat_doc exps
- <> text ")"
- case_doc :: Case -> Doc
- case_doc CDefault = text "default:""
- case_doc (CInt int) = text "case" <+> text (show int) <> text ":"
- case_doc (CChar c) = text "case" <+> text c <> text ":"
- stmt_doc :: Stmt -> Doc
- stmt_doc SBreak = text "break;"
- stmt_doc SContinue = text "continue;"
- stmt_doc (SLoc tp str maybe_exp) = doc_type tp <+> text str <+> doc
- where doc = if isNothing maybe_exp
- then text ";"
- else text " = "
- <> exp_doc (fromJust maybe_exp)
- <> text ";"
- stmt_doc (SExp exp) = exp_doc exp <> text ";"
- stmt_doc (SReturn exp) = text "return" <+> exp_doc exp <> text ";"
- stmt_doc (SBlock stmts) = text "{" <> nest 2 (statements stmts) <!> text "}"
- stmt_doc (SIf exp stmt m_stmt) = text "if (" <> exp_doc exp <> text ")"
- <+> stmt_doc stmt <> text "" <> doc
- where doc = if isNothing m_stmt
- then text ""
- else line
- <> text "else "
- <> stmt_doc(fromJust m_stmt)
- stmt_doc (SSwitch Exp [Either Case Stmt]) =
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement