-
Notifications
You must be signed in to change notification settings - Fork 1
/
AST.hs
33 lines (28 loc) · 1.04 KB
/
AST.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
module AST
( LispVal(Atom, List, DottedList, Number, String, Bool, Character),
unwordsList
) where
------------------------------------------------------------------------
-- AST
------------------------------------------------------------------------
unwordsList :: [LispVal] -> String
unwordsList = unwords . map showVal
data LispVal = Atom String
| List [LispVal]
| DottedList [LispVal] LispVal
| Number Integer
| String String
| Bool Bool
| Character Char
{-| Float Float-}
showVal :: LispVal -> String
showVal (Atom name) = name
showVal (String contents) = "\"" ++ contents ++ "\""
showVal (Bool True) = "#t"
showVal (Bool False) = "#f"
showVal (Number contents) = show contents
showVal (Character contents) = "#\\" ++ [contents]
showVal (List contents) = "(" ++ unwordsList contents ++ ")"
showVal (DottedList head tail) = "(" ++ unwordsList head ++ " . "
++ showVal tail ++ ")"
instance Show LispVal where show = showVal