Initial commit
[fp.git] / ast.icl
1 implementation module ast
2
3 import StdList
4 import StdOverloaded
5 import Data.Func
6 import Text.PPrint
7
8 instance toString AST where toString a = display $ renderCompact $ pretty a
9 instance toString Function where toString a = display $ renderCompact $ pretty a
10 instance toString Expression where toString a = display $ renderCompact $ pretty a
11 instance toString Value where toString a = display $ renderCompact $ pretty a
12
13 instance Pretty Expression
14 where
15 pretty (Literal v) = pretty v
16 pretty (Variable v) = string v
17 pretty (Apply a b) = parens (pretty a <+> pretty b)
18
19 instance Pretty Function
20 where
21 pretty (Function n args a) = string n <+> fold (<+>) (map string args) <+> string "=" <+> pretty a
22
23 instance Pretty AST
24 where
25 pretty (AST a) = pretty a
26
27 instance Pretty Value
28 where
29 pretty (Int i) = int i
30 pretty (Bool b) = bool b
31 pretty (Char c) = char c