6528215422482fbfa3111faece64c3ff80205983
[kaleidoscope-hs-old.git] / AST.hs
1 module AST where
2
3 import Text.Read
4 import Text.ParserCombinators.ReadP hiding ((+++))
5
6 data Expr = Num Float
7           | Add Expr Expr
8   deriving Show
9
10 instance Read Expr where
11   readPrec = parseNum +++ parseAdd
12     where parseNum = Num <$> readPrec
13           parseAdd = step $ do
14             a <- prec 11 readPrec
15             lift $ do
16               skipSpaces
17               char '+'
18               skipSpaces
19             b <- readPrec
20             return (Add a b)