projects
/
kaleidoscope-hs.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Detect and remove __anon_exprs in repl
[kaleidoscope-hs.git]
/
AST.hs
diff --git
a/AST.hs
b/AST.hs
index 7dad3a19e91eab9f12657101bd224b5c81742d07..9ff555a74d10c6d970fc8b7df0a37c1d98fdbffc 100644
(file)
--- a/
AST.hs
+++ b/
AST.hs
@@
-4,18
+4,22
@@
import Data.Char
import Text.Read
import Text.ParserCombinators.ReadP hiding ((+++), choice)
import Text.Read
import Text.ParserCombinators.ReadP hiding ((+++), choice)
-data Expr = Num
Float
+data Expr = Num
Double
| Var String
| BinOp BinOp Expr Expr
| Var String
| BinOp BinOp Expr Expr
+ | Call String [Expr]
deriving Show
data BinOp = Add | Sub | Mul | Cmp Ordering
deriving Show
instance Read Expr where
deriving Show
data BinOp = Add | Sub | Mul | Cmp Ordering
deriving Show
instance Read Expr where
- readPrec = choice [ parseNum
+ readPrec =
parens $
choice [ parseNum
, parseVar
, parseVar
+ , parseCall
, parseBinOp "<" 10 (Cmp LT)
, parseBinOp "<" 10 (Cmp LT)
+ , parseBinOp ">" 10 (Cmp GT)
+ , parseBinOp "==" 10 (Cmp EQ)
, parseBinOp "+" 20 Add
, parseBinOp "-" 20 Sub
, parseBinOp "*" 40 Mul
, parseBinOp "+" 20 Add
, parseBinOp "-" 20 Sub
, parseBinOp "*" 40 Mul
@@
-30,6
+34,12
@@
instance Read Expr where
skipSpaces
b <- readPrec
return (BinOp op a b)
skipSpaces
b <- readPrec
return (BinOp op a b)
+ parseCall = do
+ func <- lift (munch1 isAlpha)
+ params <- lift $ between (char '(') (char ')') $
+ sepBy (readS_to_P reads)
+ (skipSpaces >> char ',' >> skipSpaces)
+ return (Call func params)
data Prototype = Prototype String [String]
deriving Show
data Prototype = Prototype String [String]
deriving Show