tools/pas2c.hs
changeset 6274 a3e1eb794249
parent 6273 13262c6e5027
child 6275 f1b4f37dba22
equal deleted inserted replaced
6273:13262c6e5027 6274:a3e1eb794249
    30 
    30 
    31 
    31 
    32 phrase2C :: Phrase -> Doc
    32 phrase2C :: Phrase -> Doc
    33 phrase2C (Phrases p) = braces . nest 4 . vcat . map phrase2C $ p
    33 phrase2C (Phrases p) = braces . nest 4 . vcat . map phrase2C $ p
    34 phrase2C (ProcCall (Identifier name) params) = text name <> parens (hsep . punctuate (char ',') . map expr2C $ params) <> semi
    34 phrase2C (ProcCall (Identifier name) params) = text name <> parens (hsep . punctuate (char ',') . map expr2C $ params) <> semi
    35 phrase2C (IfThenElse (expr) phrase1 mphrase2) = text "if" <> parens (expr2C expr) $$ (braces . nest 4 . phrase2C) phrase1 <+> elsePart
    35 phrase2C (IfThenElse (expr) phrase1 mphrase2) = text "if" <> parens (expr2C expr) $$ (braces . nest 4 . phrase2C) phrase1 $+$ elsePart
    36     where
    36     where
    37     elsePart | isNothing mphrase2 = empty
    37     elsePart | isNothing mphrase2 = empty
    38              | otherwise = text "else" $$ (braces . nest 4 . phrase2C) (fromJust mphrase2)
    38              | otherwise = text "else" $$ (braces . nest 4 . phrase2C) (fromJust mphrase2)
    39 phrase2C (Assignment (Identifier name) expr) = text name <> text " = " <> expr2C expr <> semi
    39 phrase2C (Assignment (Identifier name) expr) = text name <> text " = " <> expr2C expr <> semi
    40 phrase2C (WhileCycle expr phrase) = text "while" <> parens (expr2C expr) $$ nest 4 (phrase2C phrase)
    40 phrase2C (WhileCycle expr phrase) = text "while" <> parens (expr2C expr) $$ nest 4 (phrase2C phrase)