projects
/
kaleidoscope-hs-old.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Update AST to match Kaleidoscope more closely
[kaleidoscope-hs-old.git]
/
AST.hs
diff --git
a/AST.hs
b/AST.hs
index 2bea0028cf47bb61f94c982f011ca24b72a612ac..1965ae6ba8378bc8277b2b46fe031ea04a64a5d5 100644
(file)
--- a/
AST.hs
+++ b/
AST.hs
@@
-4,6
+4,15
@@
import Data.Char
import Text.Read
import Text.ParserCombinators.ReadP hiding ((+++), choice)
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
data AST = Function String [String] Expr
| Eval Expr
deriving Show
@@
-25,9
+34,7
@@
instance Read AST where
params <- between (char '(') (char ')') $
sepBy (munch1 isAlpha) skipSpaces
skipSpaces
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
return (Function name params body)
instance Read Expr where