import Text.Read
import Text.ParserCombinators.ReadP hiding ((+++), choice)
+newtype Program = Program [AST]
+ deriving Show
+
+instance Read Program where
+ readPrec = fmap Program $ lift $ sepBy1 (readPrec_to_P readPrec 0) $ do
+ skipSpaces
+ char ';'
+ skipSpaces
+
data AST = Function String [String] Expr
| Eval Expr
deriving Show
params <- between (char '(') (char ')') $
sepBy (munch1 isAlpha) skipSpaces
skipSpaces
- body <- between (char '{') (char '}') $
- readS_to_P reads
- skipSpaces
+ body <- readS_to_P reads
return (Function name params body)
instance Read Expr where