module AST where import Text.Read import Text.ParserCombinators.ReadP hiding ((+++)) data Expr = Num Float | Add Expr Expr deriving Show instance Read Expr where readPrec = parseNum +++ parseAdd where parseNum = Num <$> readPrec parseAdd = step $ do a <- prec 11 readPrec lift $ do skipSpaces char '+' skipSpaces b <- readPrec return (Add a b)